sklears-decomposition
High-performance matrix decomposition and dimensionality reduction algorithms for Rust, featuring streaming capabilities and SIMD/GPU-accelerated kernels.
Latest release:
0.2.0(July 14, 2026). See the workspace release notes for highlights and upgrade guidance.
Overview
sklears-decomposition provides state-of-the-art decomposition algorithms:
- Classic Methods:
PCA(truncated-SVD based),NMF,FastICA/JADE/InfoMax,FactorAnalysis - Advanced Algorithms:
KernelPCA,DictionaryLearning,MiniBatchDictionaryLearning - Streaming:
IncrementalPCA,OnlineNMF,StreamingPCA,StreamingICA - Specialized: Tensor decomposition (
CPDecomposition,TuckerDecomposition), robust low-rank recovery (LowRankMatrixRecovery,MEstimatorDecomposition),CanonicalCorrelationAnalysis,PartialLeastSquares - Performance: SIMD-accelerated signal processing kernels, an oxicuda-backed
gpufeature (device discovery viasklears_core::gpu), and dedicated memory-efficiency utilities
Note: a handful of names in older drafts of this document (
TruncatedSVD,RandomizedSVD,RandomizedPCA,OutOfCorePCA,TensorPCA,Tucker,PARAFAC,SignalICA,EMD,VMD,MemoryEfficientNMF) do not exist as public types in this crate; the sections below use the real, verified type and method names.RobustPCA,SparsePCA, andProbabilisticPCAalso exist as public names, but only as empty placeholder marker structs with no fields or methods — see Status.
Quick Start
use ;
use ;
use ;
use array;
// Principal Component Analysis
let pca = PCAbuilder
.n_components
.whiten
.build;
// Non-negative Matrix Factorization
let nmf = NMFnew
.init
.solver;
// Independent Component Analysis (FastICA)
let ica = new.n_components;
// Fit and transform
let x = array!;
let fitted = pca.fit?;
let x_transformed = fitted.transform?;
Advanced Features
Kernel PCA
use ;
let kpca = new
.n_components
.kernel;
// Non-linear dimensionality reduction
let fitted = kpca.fit?;
let x_kpca = fitted.transform?;
Streaming Decomposition
use ;
// Incremental PCA for large datasets
let mut ipca = new
.n_components
.batch_size;
for batch in data_stream
// Online NMF
let mut online_nmf = builder
.n_components
.learning_rate
.build;
for batch in data_stream
Dictionary Learning
use ;
// Sparse coding with learned dictionary
let dict_learning = builder
.n_components
.alpha
.transform_algorithm
.build;
// Mini-batch version for large datasets
let mb_dict = new;
Specialized Algorithms
Robust Low-Rank Recovery
use ;
// Separate a low-rank component from sparse corruption (Robust PCA / PCP-style recovery)
let rpca = new
.algorithm
.lambda
.max_iter;
let fitted = rpca.fit?;
let low_rank = fitted.low_rank_component;
let sparse = fitted.sparse_component;
Factor Analysis
use FactorAnalysis;
let fa = new.random_state;
let fitted = fa.fit?;
let noise_variance = fitted.noise_variance;
Tensor Decomposition
use ;
use Array3;
// CP/PARAFAC-style decomposition
let cp = new;
// Tucker decomposition
let tucker = new
.algorithm;
let tensor: = zeros;
let fitted_cp = cp.fit?;
Performance Optimizations
Blind Source Separation (Signal Processing)
use ;
// Blind source separation, returning sources/mixing/unmixing matrices directly
let signal_ica = new.fun;
let bss_result = signal_ica.fit_transform?;
let sources = &bss_result.sources;
Empirical Mode Decomposition
use EmpiricalModeDecomposition;
let emd = default;
let result = emd.decompose?;
Memory-Efficient Operations
The memory_efficiency and hardware_acceleration modules provide SIMD-accelerated
matrix ops, aligned buffers, and (behind the gpu feature) oxicuda-backed device
discovery/acceleration (GpuAcceleration, GpuDecomposition) — see TODO.md for the
current migration status.
Quality Metrics
use PCA;
// Assess decomposition quality
let pca = PCAbuilder.n_components.build;
let fitted = pca.fit?;
let var_ratio = &fitted.explained_variance_ratio; // public field, not a method
let cumsum: = var_ratio.iter.scan.collect;
let x_reduced = fitted.transform?;
// Note: `PCA`/`PcaTrained` does not yet implement `inverse_transform` (see `TODO.md`);
// use the `quality_metrics` module's `QualityAssessment` for reconstruction diagnostics instead.
The quality_metrics module also provides a QualityAssessment type with
reconstruction_quality(), goodness_of_fit(), model_comparison(), and
overall_quality_score() methods for more comprehensive evaluation.
Architecture
Top-level modules actually exported from src/lib.rs:
sklears-decomposition/
├── pca.rs, kernel_pca.rs, incremental_pca.rs # PCA family
├── nmf.rs, online_nmf.rs # NMF family
├── ica.rs, signal_processing/ # ICA, FastICA/JADE/InfoMax, EMD, wavelets, STFT
├── dictionary_learning/ # Dictionary learning, mini-batch, OMP/LARS/K-SVD
├── factor_analysis.rs, cca.rs, pls.rs # Factor analysis, CCA, PLS
├── tensor_decomposition.rs # CP / Tucker decomposition
├── matrix_completion.rs, robust_methods.rs # Low-rank recovery, M-estimator robust methods
├── streaming.rs, time_series.rs # StreamingPCA/ICA, SSA, seasonal decomposition
├── hardware_acceleration.rs, memory_efficiency.rs, distributed.rs # SIMD/GPU/distributed
├── modular_framework.rs, type_safe.rs, fluent_api.rs # Pipeline/composition APIs
├── quality_metrics.rs, validation.rs, visualization.rs # Quality & diagnostics
└── sklearn_compat.rs, format_support.rs, integration.rs # Interop
Status
- Tests: 380 passing crate tests (
cargo nextest run -p sklears-decomposition --all-features, verified 2026-07-14). - Core Algorithms: PCA, NMF, FastICA/JADE/InfoMax, Kernel PCA, Factor Analysis, Dictionary Learning (+ mini-batch), Incremental PCA, Online NMF, CP/Tucker tensor decomposition, CCA, PLS, low-rank matrix recovery (PCP/RPCA-style) are real, tested implementations.
- Known gaps:
RobustPCA,SparsePCA, andProbabilisticPCAinpca.rsare currently empty placeholder marker structs (no fields, no methods) kept only for name compatibility — useLowRankMatrixRecoveryfor robust/sparse-plus-low-rank recovery instead.PcaConfig::svd_solveris aStringfield that is not yet read anywhere in the fit path (no working randomized-SVD path). - Streaming Support: Fully implemented (
IncrementalPCA,OnlineNMF,StreamingPCA,StreamingICA). - GPU Acceleration: oxicuda-backed device discovery/acceleration behind the
gpufeature; seeTODO.mdfor migration details.
Contributing
Priority areas:
- Real implementations behind the
RobustPCA/SparsePCA/ProbabilisticPCAplaceholder names (or removing them) - Wiring
PcaConfig::svd_solverinto the actual fit path - Additional tensor decomposition methods
- Distributed decomposition algorithms
- Performance optimizations
See CONTRIBUTING.md for guidelines.
License
Licensed under the Apache License, Version 2.0.
Citation