[−][src]Struct linfa_kernel::Kernel
A generic kernel
Fields
inner: KernelInner<R::Elem>method: KernelMethod<R::Elem>dataset: RImplementations
impl<'a, F: Float> Kernel<ArrayView2<'a, F>>[src]
pub fn new(
dataset: ArrayView2<'a, F>,
method: KernelMethod<F>,
kind: KernelType
) -> Kernel<ArrayView2<'a, F>>[src]
dataset: ArrayView2<'a, F>,
method: KernelMethod<F>,
kind: KernelType
) -> Kernel<ArrayView2<'a, F>>
pub fn dot(&self, rhs: &ArrayView2<'_, F>) -> Array2<F>[src]
Performs the matrix product between the kernel matrix and the input
Parameters
rhs: The matrix on the right-hand side of the multiplication
Returns
A new matrix containing the matrix product between the kernel
and rhs
Panics
If the shapes of kernel and rhs are not compatible for multiplication
pub fn sum(&self) -> Array1<F>[src]
Sums all elements in the same row of the kernel matrix
Returns
A new array with the sum of all the elements in each row
pub fn size(&self) -> usize[src]
Gives the size of the side of the square kernel matrix
pub fn to_upper_triangle(&self) -> Vec<F>[src]
Getter for the data in the upper triangle of the kernel matrix
Returns
A copy of all elements in the upper triangle of the kernel
matrix, stored in a Vec
pub fn diagonal(&self) -> Array1<F>[src]
Getter for the elements in the diagonal of the kernel matrix
Returns
A new array containing the copy of all elements in the diagonal fo the kernel matrix
pub fn column(&self, i: usize) -> Vec<F>[src]
Getter for a column of the kernel matrix
Params
i: the index of the column
Returns
The i-th column of the kernel matrix, stored as a Vec
Panics
If i is out of bounds
pub fn weighted_sum(&self, weights: &[F], sample: ArrayView1<'_, F>) -> F[src]
Sums the inner product of sample and every one of the samples
used to generate the kernel
Parameters
weights: the weight of each inner productsample: the input sample
Returns
The weighted sum of all inner products of sample and every one of the samples
used to generate the kernel
Panics
If the shapes of weights or sample are not compatible with the
shape of the kernel matrix
pub fn is_linear(&self) -> bool[src]
pub fn params() -> KernelParams<F>[src]
Generates the default set of parameters for building a kernel.
Use this to initialize a set of parameters to be customized using KernelParams's methods
Example
use linfa_kernel::Kernel; use linfa::traits::Transformer; use ndarray::Array2; let data = Array2::from_shape_vec((3,2), vec![1., 2., 3., 4., 5., 6.,]).unwrap(); // Build a kernel from `data` with the defaul parameters let params = Kernel::params(); let kernel = params.transform(&data);
Trait Implementations
impl<'a, F: Float> Records for Kernel<ArrayView2<'a, F>>[src]
impl<'a, F: Float> Transformer<&'a ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, Kernel<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>>> for KernelParams<F>[src]
pub fn transform(&self, x: &'a Array2<F>) -> Kernel<ArrayView2<'a, F>>[src]
Builds a kernel from the input data without copying it.
A reference to the input data will be kept by the kernel
through an ArrayView
Parameters
x: matrix of records (##records, ##features) in input
Returns
A kernel build from x according to the parameters on which
this method is called
Panics
If the kernel type is Sparse and the number of neighbors specified is
not between 1 and ##records-1
impl<'a, F: Float> Transformer<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, Kernel<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>>> for KernelParams<F>[src]
pub fn transform(&self, x: ArrayView2<'a, F>) -> Kernel<ArrayView2<'a, F>>[src]
Builds a kernel from a view of the input data.
A reference to the input data will be kept by the kernel
through an ArrayView
Parameters
x: view of a matrix of records (##records, ##features)
A kernel build from x according to the parameters on which
this method is called
Panics
If the kernel type is Sparse and the number of neighbors specified is
not between 1 and ##records-1
Auto Trait Implementations
impl<R> RefUnwindSafe for Kernel<R> where
R: RefUnwindSafe,
<R as Records>::Elem: RefUnwindSafe, [src]
R: RefUnwindSafe,
<R as Records>::Elem: RefUnwindSafe,
impl<R> Send for Kernel<R> where
R: Send, [src]
R: Send,
impl<R> Sync for Kernel<R> where
R: Sync, [src]
R: Sync,
impl<R> Unpin for Kernel<R> where
R: Unpin,
<R as Records>::Elem: Unpin, [src]
R: Unpin,
<R as Records>::Elem: Unpin,
impl<R> UnwindSafe for Kernel<R> where
R: UnwindSafe,
<R as Records>::Elem: RefUnwindSafe + UnwindSafe, [src]
R: UnwindSafe,
<R as Records>::Elem: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,