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§

source§

impl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> KernelBase<K1, K2>

source

pub fn is_linear(&self) -> bool

Whether the kernel is a linear kernel

Returns
  • true: if the kernel is linear
  • false: otherwise
source

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

source

pub fn params_with_nn<N: NearestNeighbour>(nn_algo: N) -> KernelParams<F, N>

Generate parameters with a specific nearest neighbour algorithm

source

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

source

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

source

pub fn size(&self) -> usize

Gives the size of the side of the square kernel matrix

source

pub fn column(&self, i: usize) -> Vec<F>

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

source

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

source

pub fn diagonal(&self) -> Array1<F>

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

source§

impl<'a, F: Float> KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>>

source

pub fn new<N: NearestNeighbour>( dataset: ArrayView2<'a, F>, params: &KernelParams<F, N> ) -> Kernel<F>

source

pub fn view(&'a self) -> KernelView<'a, F>

Gives a KernelView which has a view on the original kernel’s inner matrix

source§

impl<'a, F: Float> KernelBase<ArrayBase<ViewRepr<&'a F>, Dim<[usize; 2]>>, CsMatBase<F, usize, &'a [usize], &'a [usize], &'a [F]>>

source

pub fn to_owned(&self) -> Kernel<F>

Trait Implementations§

source§

impl<K1: Clone + Inner, K2: Clone + Inner> Clone for KernelBase<K1, K2>where K1::Elem: Float + Clone, K2::Elem: Float,

source§

fn clone(&self) -> KernelBase<K1, K2>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K1: Debug + Inner, K2: Debug + Inner> Debug for KernelBase<K1, K2>where K1::Elem: Float + Debug, K2::Elem: Float,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K1: PartialEq + Inner, K2: PartialEq + Inner> PartialEq for KernelBase<K1, K2>where K1::Elem: Float + PartialEq, K2::Elem: Float,

source§

fn eq(&self, other: &KernelBase<K1, K2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F: Float, K1: Inner<Elem = F>, K2: Inner<Elem = F>> Records for KernelBase<K1, K2>

§

type Elem = F

source§

fn nsamples(&self) -> usize

source§

fn nfeatures(&self) -> usize

source§

impl<F: Float, N: NearestNeighbour> Transformer<&ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, KernelBase<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, CsMatBase<F, usize, Vec<usize>, Vec<usize>, Vec<F>>>> for KernelParams<F, N>

source§

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

source§

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>, Vec<usize>, Vec<F>>>> for KernelParams<F, N>

source§

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

source§

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>, Vec<usize>, Vec<F>>>> for KernelParams<F, N>

source§

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

source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V