| Crates.io | single_algebra |
| lib.rs | single_algebra |
| version | 0.8.7 |
| created_at | 2024-09-09 14:01:58.516125+00 |
| updated_at | 2025-09-11 11:56:11.079504+00 |
| description | A linear algebra convenience library for the single-rust library. Can be used externally as well. |
| homepage | https://singlerust.com |
| repository | https://github.com/SingleRust/single-algebra |
| max_upload_size | |
| id | 1369326 |
| size | 221,612 |
A high-performance linear algebra library optimized for sparse matrices and dimensionality reduction algorithms. Designed for machine learning, data analysis, and scientific computing applications where efficiency with sparse data is crucial.
f32 and f64 numeric typesAdd this to your Cargo.toml:
[dependencies]
single-algebra = "0.8.6"
use nalgebra_sparse::CsrMatrix;
use single_algebra::dimred::pca::{SparsePCABuilder, SVDMethod};
use single_algebra::dimred::pca::sparse::PowerIterationNormalizer;
// Create or load your sparse matrix (samples × features)
let sparse_matrix: CsrMatrix<f64> = create_your_sparse_matrix();
// Build PCA with customized parameters
let mut pca = SparsePCABuilder::new()
.n_components(50)
.center(true)
.verbose(true)
.svd_method(SVDMethod::Random {
n_oversamples: 10,
n_power_iterations: 7,
normalizer: PowerIterationNormalizer::QR,
})
.build();
// Fit and transform data
let transformed = pca.fit_transform(&sparse_matrix).unwrap();
// Analyze results
let explained_variance_ratio = pca.explained_variance_ratio().unwrap();
let cumulative_variance = pca.cumulative_explained_variance_ratio().unwrap();
let feature_importance = pca.feature_importances().unwrap();
use single_algebra::dimred::pca::{MaskedSparsePCABuilder, SVDMethod};
// Create a feature mask (true = include, false = exclude)
let feature_mask = vec![true, false, true, true, false, true]; // Include features 0, 2, 3, 5
// Build masked PCA
let mut masked_pca = MaskedSparsePCABuilder::new()
.n_components(10)
.mask(feature_mask)
.center(true)
.verbose(true)
.svd_method(SVDMethod::Lanczos)
.build();
// Perform PCA on selected features only
let transformed = masked_pca.fit_transform(&sparse_matrix).unwrap();
use nalgebra_sparse::{CooMatrix, CsrMatrix};
use single_algebra::sparse::MatrixSum;
// Create a sparse matrix
let mut coo = CooMatrix::new(1000, 5000);
// ... populate with data ...
let csr: CsrMatrix<f64> = (&coo).into();
// Efficient column operations
let col_sums: Vec<f64> = csr.sum_col().unwrap();
let col_squared_sums: Vec<f64> = csr.sum_col_squared().unwrap();
use single_algebra::{Normalize, Log1P};
// Apply preprocessing transformations
let normalized_data = your_data.normalize()?;
let log_transformed = your_data.log1p()?;
This library is specifically optimized for:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the BSD 3-Clause License - see the LICENSE.md file for details.
nalgebra-lapack cratefaer crate