Struct 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§

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<F: Float> KernelBase<ArrayBase<ViewRepr<&F>, Dim<[usize; 2]>>, CsMatBase<F, usize, &[usize], &[usize], &[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 duplicate 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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>

Source§

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> Freeze for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized + Freeze, K1: Freeze, K2: Freeze,

§

impl<K1, K2> RefUnwindSafe for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized + RefUnwindSafe, K1: RefUnwindSafe, K2: RefUnwindSafe,

§

impl<K1, K2> Send for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized, K1: Send, K2: Send,

§

impl<K1, K2> Sync for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized, K1: Sync, K2: Sync,

§

impl<K1, K2> Unpin for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized, K1: Unpin, K2: Unpin,

§

impl<K1, K2> UnwindSafe for KernelBase<K1, K2>
where <K2 as Inner>::Elem: Sized, <K1 as Inner>::Elem: Sized + UnwindSafe, K1: UnwindSafe, K2: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V