Struct linfa_kernel::KernelBase [−][src]
pub struct KernelBase<K1: Inner, K2: Inner> where
K1::Elem: Float,
K2::Elem: Float, { pub inner: KernelInner<K1, K2>, pub method: KernelMethod<K1::Elem>, }
A generic kernel
Fields
inner: KernelInner<K1, K2>method: KernelMethod<K1::Elem>The inner product that will be used by the kernel
Implementations
impl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> KernelBase<K1, K2>[src]
impl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> KernelBase<K1, K2>[src]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 default parameters let params = Kernel::params(); let kernel = params.transform(&data);
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 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 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
impl<'a, F: Float> KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>[src]
impl<'a, F: Float> KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>[src]pub fn new(
dataset: ArrayView2<'a, F>,
method: KernelMethod<F>,
kind: KernelType
) -> Kernel<F>[src]
dataset: ArrayView2<'a, F>,
method: KernelMethod<F>,
kind: KernelType
) -> Kernel<F>
pub fn view(&'a self) -> KernelView<'a, F>[src]
Gives a KernelView which has a view on the original kernel’s inner matrix
impl<'a, F: Float> KernelBase<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, CsMatBase<F, usize, &'a [usize], &'a [usize], &'a [F], usize>>[src]
impl<'a, F: Float> KernelBase<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, CsMatBase<F, usize, &'a [usize], &'a [usize], &'a [F], usize>>[src]Trait Implementations
impl<F: Float> Transformer<&'_ ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]
impl<F: Float> Transformer<&'_ ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]fn transform(&self, x: &Array2<F>) -> Kernel<F>[src]
Builds a kernel from a view of the input data.
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
impl<'a, F: Float> Transformer<&'_ ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]
impl<'a, F: Float> Transformer<&'_ ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]fn transform(&self, x: &ArrayView2<'a, F>) -> Kernel<F>[src]
Builds a kernel from a view of the input data.
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
impl<'a, F: Float> Transformer<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]
impl<'a, F: Float> Transformer<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>> for KernelParams<F>[src]fn transform(&self, x: ArrayView2<'a, F>) -> Kernel<F>[src]
Builds a kernel from a view of the input data.
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<K1, K2> RefUnwindSafe for KernelBase<K1, K2> where
K1: RefUnwindSafe,
K2: RefUnwindSafe,
<K1 as Inner>::Elem: RefUnwindSafe,
impl<K1, K2> RefUnwindSafe for KernelBase<K1, K2> where
K1: RefUnwindSafe,
K2: RefUnwindSafe,
<K1 as Inner>::Elem: RefUnwindSafe, impl<K1, K2> Send for KernelBase<K1, K2> where
K1: Send,
K2: Send,
impl<K1, K2> Send for KernelBase<K1, K2> where
K1: Send,
K2: Send, impl<K1, K2> Sync for KernelBase<K1, K2> where
K1: Sync,
K2: Sync,
impl<K1, K2> Sync for KernelBase<K1, K2> where
K1: Sync,
K2: Sync, impl<K1, K2> UnwindSafe for KernelBase<K1, K2> where
K1: UnwindSafe,
K2: UnwindSafe,
<K1 as Inner>::Elem: UnwindSafe,
impl<K1, K2> UnwindSafe for KernelBase<K1, K2> where
K1: UnwindSafe,
K2: UnwindSafe,
<K1 as Inner>::Elem: UnwindSafe,