Struct linfa_kernel::KernelBase
source · [−]pub struct KernelBase<K1: Inner, K2: Inner> where
K1::Elem: Float,
K2::Elem: Float, {
pub inner: KernelInner<K1, K2>,
pub method: KernelMethod<K1::Elem>,
}
Expand description
A generic kernel
Fields
inner: KernelInner<K1, K2>
method: KernelMethod<K1::Elem>
The inner product that will be used by the kernel
Implementations
sourceimpl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> KernelBase<K1, K2>
impl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> KernelBase<K1, K2>
sourcepub fn params() -> KernelParams<F, CommonNearestNeighbour>
pub fn params() -> KernelParams<F, CommonNearestNeighbour>
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
sourcepub fn params_with_nn<N: NearestNeighbour>(nn_algo: N) -> KernelParams<F, N>
pub fn params_with_nn<N: NearestNeighbour>(nn_algo: N) -> KernelParams<F, N>
Generate parameters with a specific nearest neighbour algorithm
sourcepub fn dot(&self, rhs: &ArrayView2<'_, F>) -> Array2<F>
pub fn dot(&self, rhs: &ArrayView2<'_, F>) -> Array2<F>
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
sourcepub fn sum(&self) -> Array1<F>
pub fn sum(&self) -> Array1<F>
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
sourcepub fn to_upper_triangle(&self) -> Vec<F>
pub fn to_upper_triangle(&self) -> Vec<F>
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
sourceimpl<'a, F: Float> KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>
impl<'a, F: Float> KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize, Global>, Vec<usize, Global>, Vec<F, Global>, usize>>
pub fn new<N: NearestNeighbour>(
dataset: ArrayView2<'a, F>,
params: &KernelParams<F, N>
) -> Kernel<F>
sourcepub fn view(&'a self) -> KernelView<'a, F>
pub fn view(&'a self) -> KernelView<'a, F>
Gives a KernelView which has a view on the original kernel’s inner matrix
Trait Implementations
sourceimpl<K1: Clone + Inner, K2: Clone + Inner> Clone for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: Clone,
impl<K1: Clone + Inner, K2: Clone + Inner> Clone for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: Clone,
sourcefn clone(&self) -> KernelBase<K1, K2>
fn clone(&self) -> KernelBase<K1, K2>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<K1: Debug + Inner, K2: Debug + Inner> Debug for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: Debug,
impl<K1: Debug + Inner, K2: Debug + Inner> Debug for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: Debug,
sourceimpl<K1: PartialEq + Inner, K2: PartialEq + Inner> PartialEq<KernelBase<K1, K2>> for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: PartialEq,
impl<K1: PartialEq + Inner, K2: PartialEq + Inner> PartialEq<KernelBase<K1, K2>> for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
K1::Elem: PartialEq,
sourcefn eq(&self, other: &KernelBase<K1, K2>) -> bool
fn eq(&self, other: &KernelBase<K1, K2>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &KernelBase<K1, K2>) -> bool
fn ne(&self, other: &KernelBase<K1, K2>) -> bool
This method tests for !=
.
sourceimpl<F: Float, N: NearestNeighbour> 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, N>
impl<F: Float, N: NearestNeighbour> 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, N>
sourcefn transform(&self, x: &Array2<F>) -> Kernel<F>
fn transform(&self, x: &Array2<F>) -> Kernel<F>
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
sourceimpl<'a, F: Float, N: NearestNeighbour> 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, N>
impl<'a, F: Float, N: NearestNeighbour> 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, N>
sourcefn transform(&self, x: &ArrayView2<'a, F>) -> Kernel<F>
fn transform(&self, x: &ArrayView2<'a, F>) -> Kernel<F>
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
sourceimpl<'a, F: Float, N: NearestNeighbour> 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, N>
impl<'a, F: Float, N: NearestNeighbour> 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, N>
sourcefn transform(&self, x: ArrayView2<'a, F>) -> Kernel<F>
fn transform(&self, x: ArrayView2<'a, F>) -> Kernel<F>
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<K1: Inner, K2: Inner> StructuralPartialEq for KernelBase<K1, K2> where
K1::Elem: Float,
K2::Elem: Float,
Auto Trait Implementations
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> Sync for KernelBase<K1, K2> where
K1: Sync,
K2: Sync,
impl<K1, K2> Unpin for KernelBase<K1, K2> where
K1: Unpin,
K2: Unpin,
impl<K1, K2> UnwindSafe for KernelBase<K1, K2> where
K1: UnwindSafe,
K2: UnwindSafe,
<K1 as Inner>::Elem: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more