pub struct CCIPCA { /* private fields */ }Expand description
Candid Covariance-free Incremental PCA (CCIPCA).
Maintains n_components eigenvector estimates that are updated with each
new sample using a covariance-free rank-one update rule. The amnestic
weight controls how quickly old data is forgotten (0.0 = equal weighting).
Dimensionality is determined lazily from the first call to
update, matching the pattern of
IncrementalNormalizer.
Implementations§
Source§impl CCIPCA
impl CCIPCA
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a CCIPCA estimator with n_components components and no forgetting.
use irithyll::preprocessing::CCIPCA;
let pca = CCIPCA::new(3);
assert_eq!(pca.n_components(), 3);
assert_eq!(pca.count(), 0);Sourcepub fn with_amnestic(n_components: usize, amnestic: f64) -> Self
pub fn with_amnestic(n_components: usize, amnestic: f64) -> Self
Create a CCIPCA estimator with a custom amnestic (forgetting) weight.
Higher amnestic values give more weight to recent samples. A value
of 0.0 weights all samples equally.
use irithyll::preprocessing::CCIPCA;
let pca = CCIPCA::with_amnestic(2, 1.5);
assert_eq!(pca.n_components(), 2);Sourcepub fn update(&mut self, features: &[f64])
pub fn update(&mut self, features: &[f64])
Incorporate a new sample and update eigencomponent estimates.
On the first call, the feature dimensionality is established from
features.len(). Subsequent calls must provide the same length.
The algorithm performs:
- Welford mean update.
- Center the sample.
- Rank-one update of each eigenvector with re-orthogonalisation.
- Sort components by descending eigenvalue.
§Panics
Panics if features.len() does not match the established dimensionality.
Sourcepub fn transform(&self, features: &[f64]) -> Vec<f64>
pub fn transform(&self, features: &[f64]) -> Vec<f64>
Project features onto the current principal components.
Centers the input using the running mean and computes the dot product
with each eigenvector. Returns a Vec of length n_components.
§Panics
Panics if features.len() does not match the established dimensionality,
or if no samples have been incorporated yet.
Sourcepub fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
pub fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset all state, preserving n_components and amnestic settings.
After reset, the next update call will re-initialise
the feature dimensionality from the input.
Sourcepub fn n_components(&self) -> usize
pub fn n_components(&self) -> usize
Number of principal components being estimated.
Sourcepub fn n_features(&self) -> Option<usize>
pub fn n_features(&self) -> Option<usize>
Feature dimensionality, or None if not yet initialised.
Sourcepub fn eigenvalues(&self) -> &[f64]
pub fn eigenvalues(&self) -> &[f64]
Current eigenvalue estimates (sorted descending).
Sourcepub fn explained_variance_ratio(&self) -> Vec<f64>
pub fn explained_variance_ratio(&self) -> Vec<f64>
Explained variance ratio for each component.
Each element is the component’s eigenvalue divided by the sum of all
eigenvalues. Returns an empty Vec if no samples have been incorporated.
Trait Implementations§
Source§impl StreamingPreprocessor for CCIPCA
impl StreamingPreprocessor for CCIPCA
Source§fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
fn update_and_transform(&mut self, features: &[f64]) -> Vec<f64>
Source§fn transform(&self, features: &[f64]) -> Vec<f64>
fn transform(&self, features: &[f64]) -> Vec<f64>
Source§fn output_dim(&self) -> Option<usize>
fn output_dim(&self) -> Option<usize>
None if unknown until the first sample.Auto Trait Implementations§
impl Freeze for CCIPCA
impl RefUnwindSafe for CCIPCA
impl Send for CCIPCA
impl Sync for CCIPCA
impl Unpin for CCIPCA
impl UnsafeUnpin for CCIPCA
impl UnwindSafe for CCIPCA
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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