Foundations to Frontier
Tests
D. Classical Machine Learning › D9 Dimensionality Reduction and Manifold Learning

Non-negative Matrix Factorization (NMF)

Non-negative matrix factorization approximates a non-negative data matrix V by the product of two non-negative matrices, W (basis or parts) and H (activations or weights). Because nothing can be subtracted, each sample is an additive combination of parts. That yields interpretable components for spectra, images, documents and power signals, where PCA's signed components are hard to read. It is fitted by minimising Frobenius or Kullback–Leibler loss, classically with Lee and Seung's multiplicative updates (which keep entries non-negative and never increase the loss), or with alternating non-negative least squares. The problem is non-convex and its factors are not unique in general; uniqueness needs sparsity or separability. This page covers the model, losses, updates, initialisation (random, NNDSVD), choosing k, uniqueness, and applications. In the exercises you implement NMF and recover mixed spectra; then you compare initialisations and test when the true factors can be identified.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Parts that only add up

Many measurements are naturally positive sums. A spectrum is the sum of each material’s spectrum; a power reading is the sum of what each appliance draws; a document is a mix of topics. NMF factors a table of such data into a few non-negative parts and non-negative amounts of each part per sample. Nothing can cancel out, so the parts come out looking like real, physical pieces.

NMF: finding additive, non-negative parts
NMF components (dashed: true spectra)PCA components
NMF relative error 0.0094 · share of PCA loadings that are negative 30%
With k = 3 and enough updates, NMF's components sit on the three true peaks: each sample is a positive sum of parts, exactly how the data were made. PCA explains the same variance with orthogonal components that dip below zero, mathematically fine but not physical spectra. With k = 2, NMF has to merge peaks; with k = 4–5 it starts splitting them.
Why engineers care

NMF unmixes hyperspectral pixels into material spectra (remote sensing, planetary science), separates an aggregate power signal into appliances or subsystems, extracts topics from maintenance reports, and decomposes audio into sources. Its components are directly interpretable because they live in the same non-negative units as the data.

📝 Quick check (Level 0)
0/3 answered
  1. 1. NMF represents each sample as…
  2. 2. PCA components on non-negative data typically…
  3. 3. NMF needs the data to be…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Updates and losses by hand

Model. V (m × n) ≈ W H, with W (m × k) ≥ 0 and H (k × n) ≥ 0.

Frobenius loss. ‖V − WH‖². For V = [1, 2], W = [1] and H = [1, 1], the residual is [0, 1] and the loss is 1.

Multiplicative update for H (Frobenius): H ← H ⊙ (WᵀV) ⊘ (WᵀWH). For V = [4, 2], W = [2] and H = [1, 1]: WᵀV = [8, 4] and WᵀWH = [4, 4], so H becomes [2, 1]. The fit then reproduces V exactly. Non-negative entries stay non-negative because the update only multiplies by positive ratios.

KL loss. Σ [V log(V/WH) − V + WH]. For V = 2 and WH = 1: 2 ln 2 − 1 = 0.386. It suits count data (Poisson noise).

Scaling ambiguity. (WD)(D⁻¹H) = WH for any positive diagonal D, so normalise W’s columns (for example to unit sum) and move the scale into H.

Compression. A 60 × 200 matrix (12 000 numbers) with k = 3 needs k(m + n) = 780.

The steps in plain English:

  1. Make sure V ≥ 0, and choose k and the loss (Frobenius for Gaussian-like noise, KL for counts).
  2. Initialise W, H ≥ 0 (random, or NNDSVD/NNDSVDa from the SVD).
  3. Alternate the multiplicative (or ANLS) updates for H and W until the loss stops improving.
  4. Normalise the columns of W, then interpret W’s columns as parts and H’s rows as their activations.
📝 Quick check (Level 1)
0/3 answered
  1. 1. One H update for V = [3], W = [1], H = [1]?
  2. 2. Numbers stored by NMF with m = 100, n = 1000, k = 5?
  3. 3. KL loss when WH equals V exactly?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why the updates work, initialisation and uniqueness

Monotone multiplicative updates (Lee and Seung, 2001). Each update minimises a quadratic auxiliary (majorising) function of the loss, so the loss never increases, with no step size to tune. They are slow to converge near the solution, and an entry that hits exactly zero stays there. Faster alternatives: alternating non-negative least squares, HALS / coordinate descent, and projected gradient.

Exercise 1, three peaked spectra mixed with random weights:

  • NMF reached relative error 0.004 and recovered every spectrum with correlation ≥ 0.9998;
  • even after choosing each column’s sign to be mostly positive, 31% of the top-3 SVD factor entries were negative.

Initialisation.

  • NNDSVD builds non-negative factors from the leading singular vectors’ positive or negative parts. It contains many zeros, and multiplicative updates cannot move zeros.
  • NNDSVDa fills those zeros with the data mean.

In exercise 2, NNDSVDa reached error 0.087 after 10 updates against 0.26 for random initialisation. Plain NNDSVD was the slowest by 50 updates.

Uniqueness. If W H = V, so does (WQ)(Q⁻¹H) whenever both stay non-negative. When parts overlap heavily and activations are dense, many such Q exist, and NMF can fit perfectly yet return the wrong parts. Uniqueness holds under sparsity or separability (each part has an “anchor” feature no other part uses; Donoho and Stodden, 2003). Exercise 2: peaked, sparse factors were recovered at correlation 1.000, while dense, overlapping factors reached only 0.82, despite a fit error of 1.2%.

Choosing k. Plot reconstruction error against k (look for an elbow), check stability of the factors across restarts (consensus clustering), or use cross-validation by masking entries.

from sklearn.decomposition import NMF
model = NMF(n_components=3, init="nndsvda", beta_loss="frobenius", max_iter=500, random_state=0)
W = model.fit_transform(V)      # scikit-learn convention: rows are samples, so W holds the activations
H = model.components_           # and H holds the parts
🐍 Exercise 1: NMF by multiplicative updates
Implement Lee–Seung multiplicative updates for Frobenius and KL losses and a column-matching score; recover three mixed non-negative spectra, check monotone loss and non-negativity, and compare with SVD factor signs.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Lee–Seung multiplicative updates guarantee…
  2. 2. Plain NNDSVD can slow multiplicative updates because…
  3. 3. NMF factors are unique when the true parts are…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Complexity. Exact NMF is NP-hard in general (Vavasis, 2009). Under separability, a polynomial-time algorithm finds the anchors exactly (Arora et al., 2012), and successive projection or XRAY methods are practical versions of it.

Geometry. The columns of V lie in the cone generated by the columns of W. NMF looks for a k-generator cone containing the data. If the data fill only part of the cone, many cones fit equally well, which is the source of non-uniqueness. Separability means the data include the cone’s extreme rays themselves.

Statistical view. Frobenius NMF corresponds to Gaussian noise. KL NMF corresponds to Poisson noise, and is equivalent to probabilistic latent semantic analysis (PLSA) for documents. Itakura–Saito NMF is scale-invariant and suits audio power spectra. All belong to the β-divergence family.

Interview questions.

  • NMF or PCA? NMF for non-negative data where additive parts are meaningful (spectra, counts, images). PCA when signed variation around a mean is natural and orthogonality is useful.
  • How do you get more reliable NMF parts? Use sparsity penalties, several restarts with consensus, a sensible k, NNDSVDa initialisation, and check against domain knowledge, such as known reference spectra.
📝 Quick check (Level 3)
0/3 answered
  1. 1. KL-loss NMF is equivalent to…
  2. 2. Exact NMF in general is…
  3. 3. Separability means each part has…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Initialisation and identifiability

History.

  • P. Paatero and U. Tapper (1994) introduced positive matrix factorization for environmental data.
  • D. Lee and H. S. Seung (1999, 2001) popularised NMF with multiplicative updates and parts-based faces.
  • D. Donoho and V. Stodden (2003) studied uniqueness.
  • C. Boutsidis and E. Gallopoulos (2008) proposed NNDSVD.
  • S. Vavasis (2009) proved NP-hardness; S. Arora et al. (2012) gave provable algorithms under separability.

Exercise 2. 4 factors, 3 datasets. Relative error after 10, 50 and 300 multiplicative updates on the sparse-factor data:

initialisation 10 updates 50 300
random 0.2608 0.0312 0.0077
NNDSVD 0.2011 0.0657 0.0136
NNDSVDa 0.0867 0.0226 0.0075

Factor recovery after 600 updates (mean matched correlation with the true parts, then fit error): sparse, peaked factors 1.000 with fit 0.0051; dense, overlapping factors 0.822 with fit 0.0117.

  • NNDSVDa gave a big head start. Plain NNDSVD’s exact zeros slowed multiplicative updates enough to fall behind random initialisation after 50 updates.
  • A good fit does not mean the true parts. With dense, overlapping factors, NMF fitted the data to about 1% yet recovered the parts only at correlation 0.82: non-uniqueness made visible.
  • Sparse, separable parts were recovered essentially perfectly. That is when NMF’s parts can be trusted as physical.
🐍 Exercise 2 (research): initialisation and identifiability
Compare random, NNDSVD and NNDSVDa initialisations by error after 10, 50 and 300 multiplicative updates; then test how well NMF recovers sparse versus dense ground-truth factors.

NMF in AI, robotics and aerospace

  • Hyperspectral unmixing: decomposing pixels from Earth-observation or planetary imagers into endmember spectra and abundances.
  • Load disaggregation: separating aggregate spacecraft or building power into subsystem contributions.
  • Topic models for maintenance and incident reports (KL-NMF).

References

  1. D. D. Lee, H. S. Seung (1999). “Learning the parts of objects by non-negative matrix factorization.” Nature 401.
  2. D. D. Lee, H. S. Seung (2001). “Algorithms for non-negative matrix factorization.” NeurIPS 13.
  3. C. Boutsidis, E. Gallopoulos (2008). “SVD based initialization: a head start for nonnegative matrix factorization.” Pattern Recognition 41(4).
  4. D. Donoho, V. Stodden (2003). “When does non-negative matrix factorization give a correct decomposition into parts?” NeurIPS 16.
  5. N. Gillis (2020). Nonnegative Matrix Factorization. SIAM.