https://github.com/petabi/petal-decomposition
Matrix decomposition algorithms including PCA (principal component analysis) and ICA (independent component analysis)
https://github.com/petabi/petal-decomposition
decomposition dimensionality-reduction ica matrix pca
Last synced: 2 months ago
JSON representation
Matrix decomposition algorithms including PCA (principal component analysis) and ICA (independent component analysis)
- Host: GitHub
- URL: https://github.com/petabi/petal-decomposition
- Owner: petabi
- License: apache-2.0
- Created: 2020-05-18T23:35:40.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-06T03:03:24.000Z (2 months ago)
- Last Synced: 2025-04-09T20:12:20.420Z (2 months ago)
- Topics: decomposition, dimensionality-reduction, ica, matrix, pca
- Language: Rust
- Homepage:
- Size: 122 KB
- Stars: 21
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# petal-decomposition
petal-decomposition provides matrix decomposition algorithms including PCA
(principal component analysis) and ICA (independent component analysis).[](https://crates.io/crates/petal-decomposition)
[](https://docs.rs/petal-decomposition)
[](https://codecov.io/gh/petabi/petal-decomposition)## Requirements
* BLAS/LAPACK backend (OpenBLAS, Netlib, Intel MKL, or the Accelerate Framework)
## Features
* PCA with exact, full SVD (singular value decomposition)
* PCA with randomized, truncated SVD
* [FastICA](https://www.cs.helsinki.fi/u/ahyvarin/papers/NN00new.pdf)## Crate Features
* Use one of `intel-mkl-static`, `intel-mkl-system`, `netlib-static`, `netlib-system`,
`openblas-static`, and `openblas-system` to select a BLAS/LAPACK
backend.
See [ndarray-linalg's documentation][ndarray-linalg-features] for details.**Note:** On macOS, the Accelerate Framework is used by default, so these
features are not needed.* `serialization` enables serialization/deserialization using [serde](https://crates.io/crates/serde).
## Examples
The following example shows how to apply PCA to an array of three samples, and
obtain singular values as well as how much variance each component explains.```rust
use ndarray::arr2;
use petal_decomposition::Pca;let x = arr2(&[[0_f64, 0_f64], [1_f64, 1_f64], [2_f64, 2_f64]]);
let mut pca = PcaBuilder::new(2).build(); // Keep two dimensions.
pca.fit(&x).unwrap();let s = pca.singular_values(); // [2_f64, 0_f64]
let v = pca.explained_variance_ratio(); // [1_f64, 0_f64]
let y = pca.transform(&x).unwrap(); // [-2_f64.sqrt(), 0_f64, 2_f64.sqrt()]
```## License
Copyright 2020-2024 Petabi, Inc.
Licensed under [Apache License, Version 2.0][apache-license] (the "License");
you may not use this crate except in compliance with the License.Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See [LICENSE](LICENSE) for
the specific language governing permissions and limitations under the License.## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the [Apache-2.0
license][apache-license], shall be licensed as above, without any additional
terms or conditions.[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
[ndarray-linalg-features]: https://github.com/rust-ndarray/ndarray-linalg#backend-features