pub struct KRLS { /* private fields */ }Expand description
Kernel Recursive Least Squares with ALD sparsification.
Maintains a dictionary of support vectors and learns dual weights in the
kernel space defined by the provided Kernel function.
§Sparsification (ALD)
The Approximate Linear Dependency test measures whether a new sample lies within the span of existing dictionary entries (in RKHS). The test computes:
delta = k(x,x) - k_t^T * P * k_twhere k_t is the vector of kernel evaluations between the new sample and
all dictionary entries, and P is the inverse kernel matrix. If delta < ald_threshold,
the sample is linearly dependent and only the weights are updated.
§Budget
When the dictionary reaches budget entries, no new entries are added.
Subsequent independent samples fall through to weight-only updates.
§Example
use irithyll::learners::krls::{KRLS, RBFKernel};
use irithyll::learner::StreamingLearner;
let mut model = KRLS::new(Box::new(RBFKernel::new(0.5)), 100, 1e-4);
model.train(&[1.0], 1.0_f64.sin());
model.train(&[2.0], 2.0_f64.sin());
let pred = model.predict(&[1.5]);
assert!(pred.is_finite());Implementations§
Source§impl KRLS
impl KRLS
Sourcepub fn new(kernel: Box<dyn Kernel>, budget: usize, ald_threshold: f64) -> Self
pub fn new(kernel: Box<dyn Kernel>, budget: usize, ald_threshold: f64) -> Self
Create a new KRLS learner with no forgetting.
§Arguments
kernel– kernel function (e.g.,RBFKernel,PolynomialKernel)budget– maximum dictionary size (caps memory usage)ald_threshold– ALD sparsification threshold. Typical values: 1e-4 to 1e-2. Smaller = more dictionary entries (closer approximation).
Sourcepub fn with_forgetting(
kernel: Box<dyn Kernel>,
budget: usize,
ald_threshold: f64,
forgetting_factor: f64,
) -> Self
pub fn with_forgetting( kernel: Box<dyn Kernel>, budget: usize, ald_threshold: f64, forgetting_factor: f64, ) -> Self
Create a KRLS learner with exponential forgetting.
forgetting_factor in (0, 1]. Values like 0.99 introduce exponential
discounting of older data for non-stationary environments.
Sourcepub fn ald_threshold(&self) -> f64
pub fn ald_threshold(&self) -> f64
The ALD threshold.
Sourcepub fn forgetting_factor(&self) -> f64
pub fn forgetting_factor(&self) -> f64
The forgetting factor.
Sourcepub fn dictionary(&self) -> &[Vec<f64>]
pub fn dictionary(&self) -> &[Vec<f64>]
Immutable access to the dictionary (support vectors).
Trait Implementations§
Source§impl DiagnosticSource for KRLS
impl DiagnosticSource for KRLS
Source§fn config_diagnostics(&self) -> Option<ConfigDiagnostics>
fn config_diagnostics(&self) -> Option<ConfigDiagnostics>
None if not supported.Source§impl StreamingLearner for KRLS
impl StreamingLearner for KRLS
Source§fn train_one(&mut self, features: &[f64], target: f64, _weight: f64)
fn train_one(&mut self, features: &[f64], target: f64, _weight: f64)
Source§fn predict(&self, features: &[f64]) -> f64
fn predict(&self, features: &[f64]) -> f64
Source§fn n_samples_seen(&self) -> u64
fn n_samples_seen(&self) -> u64
Auto Trait Implementations§
impl Freeze for KRLS
impl !RefUnwindSafe for KRLS
impl Send for KRLS
impl Sync for KRLS
impl Unpin for KRLS
impl UnsafeUnpin for KRLS
impl !UnwindSafe for KRLS
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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