pub struct RandomizedPca<A, R> where
    A: Scalar,
    R: Rng
{ /* private fields */ }
Expand description

Principal component analysis using randomized singular value decomposition.

This uses randomized SVD (singular value decomposition) proposed by Halko et al. [1] to reduce the dimensionality of the input data. The data is centered for each feature before applying randomized SVD.

Examples

use petal_decomposition::RandomizedPcaBuilder;

let x = ndarray::arr2(&[[0_f64, 0_f64], [1_f64, 1_f64], [2_f64, 2_f64]]);
let mut pca = RandomizedPcaBuilder::new(1).build();
let y = pca.fit_transform(&x).unwrap();  // [-2_f64.sqrt(), 0_f64, 2_f64.sqrt()]
assert!((y[(0, 0)].abs() - 2_f64.sqrt()).abs() < 1e-8);
assert!(y[(1, 0)].abs() < 1e-8);
assert!((y[(2, 0)].abs() - 2_f64.sqrt()).abs() < 1e-8);

References

  1. N. Halko, P. G. Martinsson, and J. A. Tropp. Finding Structure with Randomness: Probabilistic Algorithms for Constructing Approximate Matrix Decompositions. SIAM Review, 53(2), 217–288, 2011.

Implementations

Creates a PCA model based on randomized SVD.

The random matrix for randomized SVD is created from a PCG random number generator (the XSL 128/64 (MCG) variant on a 64-bit CPU and the XSH RR 64/32 (LCG) variant on a 32-bit CPU), initialized with a randomly-generated seed.

Creates a PCA model based on randomized SVD, with a PCG random number generator initialized with the given seed.

It uses a PCG random number generator (the XSL 128/64 (MCG) variant on a 64-bit CPU and the XSH RR 64/32 (LCG) variant on a 32-bit CPU). Use with_rng for a different random number generator.

Creates a PCA model with the given number of components and random number generator. The random number generator is used to create a random matrix for randomized SVD.

Returns the principal axes in feature space.

Returns the per-feature empirical mean.

Returns the number of components.

Returns sigular values.

Returns the ratio of explained variance for each component.

Fits the model with input.

Errors

Applies dimensionality reduction to input.

Errors

Fits the model with input and apply the dimensionality reduction on input.

This is equivalent to calling both fit and transform for the same input.

Errors

Transforms data back to its original space.

Errors

Returns DecompositionError::InvalidInput if the number of rows of input is different from that of the training data, or the number of columns of input is different from the number of components.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.