Skip to main content

Module nmf

Module nmf 

Source
Expand description

Non-negative Matrix Factorization (NMF).

NMF decomposes a non-negative matrix X into two non-negative factors W and H such that X ~ W * H, where:

  • X has shape (n_samples, n_features)
  • W has shape (n_samples, n_components)
  • H has shape (n_components, n_features)

§Algorithm

Two solvers are supported:

  • Multiplicative Update (Lee & Seung, 2001): iteratively update W and H using multiplicative rules that guarantee non-negativity.
  • Coordinate Descent: iteratively solve for each element of W and H using closed-form coordinate-wise updates.

§Initialization

  • Random: initialize W and H with random non-negative values.
  • NNDSVD: Non-Negative Double SVD, initializes W and H from a truncated SVD of X, setting negative entries to zero.

§Examples

use ferrolearn_decomp::NMF;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;

let nmf = NMF::<f64>::new(2);
let x = array![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
let fitted = nmf.fit(&x, &()).unwrap();
let projected = fitted.transform(&x).unwrap();
assert_eq!(projected.ncols(), 2);

Structs§

FittedNMF
A fitted NMF model holding the learned components and reconstruction error.
NMF
Non-negative Matrix Factorization configuration.

Enums§

NMFInit
The initialization strategy for NMF.
NMFSolver
The solver algorithm for NMF.