Skip to main content

OnlineKernelMatrix

Struct OnlineKernelMatrix 

Source
pub struct OnlineKernelMatrix { /* private fields */ }
Expand description

Incrementally updatable kernel matrix.

Supports efficient O(n) updates when adding new samples, avoiding O(n²) recomputation of the entire matrix.

§Example

use tensorlogic_sklears_kernels::{OnlineKernelMatrix, RbfKernel, RbfKernelConfig, Kernel};

let kernel = RbfKernel::new(RbfKernelConfig::new(0.5)).unwrap();
let mut online = OnlineKernelMatrix::new(Box::new(kernel));

// Add samples incrementally
online.add_sample(vec![1.0, 2.0, 3.0]).unwrap();
online.add_sample(vec![4.0, 5.0, 6.0]).unwrap();
online.add_sample(vec![7.0, 8.0, 9.0]).unwrap();

// Get the kernel matrix
let matrix = online.get_matrix();
assert_eq!(matrix.len(), 3);

Implementations§

Source§

impl OnlineKernelMatrix

Source

pub fn new(kernel: Box<dyn Kernel>) -> Self

Create a new online kernel matrix.

Source

pub fn with_config(kernel: Box<dyn Kernel>, config: OnlineConfig) -> Self

Create with custom configuration.

Source

pub fn add_sample(&mut self, sample: Vec<f64>) -> Result<()>

Add a new sample and update the kernel matrix.

Time complexity: O(n) where n is current number of samples.

Source

pub fn add_samples(&mut self, samples: Vec<Vec<f64>>) -> Result<()>

Add multiple samples at once (batch update).

More efficient than adding one by one due to better cache utilization.

Source

pub fn remove_sample(&mut self, index: usize) -> Result<Vec<f64>>

Remove a sample by index and update the matrix.

Time complexity: O(n²) due to matrix restructuring.

Source

pub fn get_matrix(&self) -> &Vec<Vec<f64>>

Get the current kernel matrix.

Source

pub fn get_samples(&self) -> &Vec<Vec<f64>>

Get the current samples.

Source

pub fn get(&self, i: usize, j: usize) -> Option<f64>

Get a specific kernel value.

Source

pub fn len(&self) -> usize

Get the number of samples.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn stats(&self) -> &OnlineStats

Get statistics.

Source

pub fn clear(&mut self)

Reset the matrix.

Source

pub fn kernel(&self) -> &dyn Kernel

Get the underlying kernel.

Source

pub fn config(&self) -> &OnlineConfig

Get the configuration.

Source

pub fn compute_with_sample( &self, query: &[f64], sample_idx: usize, ) -> Result<f64>

Compute kernel value between a query point and stored sample.

Source

pub fn compute_with_all(&self, query: &[f64]) -> Result<Vec<f64>>

Compute kernel values between query and all stored samples.

Source

pub fn to_matrix(&self) -> Vec<Vec<f64>>

Clone the current matrix as a standalone 2D vector.

Auto Trait Implementations§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.