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
impl OnlineKernelMatrix
Sourcepub fn with_config(kernel: Box<dyn Kernel>, config: OnlineConfig) -> Self
pub fn with_config(kernel: Box<dyn Kernel>, config: OnlineConfig) -> Self
Create with custom configuration.
Sourcepub fn add_sample(&mut self, sample: Vec<f64>) -> Result<()>
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.
Sourcepub fn add_samples(&mut self, samples: Vec<Vec<f64>>) -> Result<()>
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.
Sourcepub fn remove_sample(&mut self, index: usize) -> Result<Vec<f64>>
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.
Sourcepub fn get_matrix(&self) -> &Vec<Vec<f64>>
pub fn get_matrix(&self) -> &Vec<Vec<f64>>
Get the current kernel matrix.
Sourcepub fn get_samples(&self) -> &Vec<Vec<f64>>
pub fn get_samples(&self) -> &Vec<Vec<f64>>
Get the current samples.
Sourcepub fn stats(&self) -> &OnlineStats
pub fn stats(&self) -> &OnlineStats
Get statistics.
Sourcepub fn config(&self) -> &OnlineConfig
pub fn config(&self) -> &OnlineConfig
Get the configuration.
Sourcepub fn compute_with_sample(
&self,
query: &[f64],
sample_idx: usize,
) -> Result<f64>
pub fn compute_with_sample( &self, query: &[f64], sample_idx: usize, ) -> Result<f64>
Compute kernel value between a query point and stored sample.
Auto Trait Implementations§
impl Freeze for OnlineKernelMatrix
impl !RefUnwindSafe for OnlineKernelMatrix
impl Send for OnlineKernelMatrix
impl Sync for OnlineKernelMatrix
impl Unpin for OnlineKernelMatrix
impl !UnwindSafe for OnlineKernelMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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