[][src]Struct linfa_kernel::Kernel

pub struct Kernel<R: Records> where
    R::Elem: Float
{ pub inner: KernelInner<R::Elem>, pub method: KernelMethod<R::Elem>, pub dataset: R, }

A generic kernel

Fields

inner: KernelInner<R::Elem>method: KernelMethod<R::Elem>dataset: R

Implementations

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]

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 product
  • sample: 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]

Wheter the kernel is a linear kernel

Returns

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

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]

type Elem = F

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]

impl<R> Send for Kernel<R> where
    R: Send
[src]

impl<R> Sync for Kernel<R> where
    R: Sync
[src]

impl<R> Unpin for Kernel<R> where
    R: Unpin,
    <R as Records>::Elem: Unpin
[src]

impl<R> UnwindSafe for Kernel<R> where
    R: UnwindSafe,
    <R as Records>::Elem: RefUnwindSafe + UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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