Quant Memo
Core

Non-Negative Matrix Factorization

Non-negative matrix factorization breaks a table of only-positive numbers into a small set of building-block parts and the amounts of each part used, with the constraint that nothing is ever subtracted — parts only add up.

Prerequisites: PCA (Principal Component Analysis)

PCA is the standard way to compress a big table of numbers into a few underlying components, but its components are allowed to be negative and to cancel each other out, which makes them mathematically efficient and often humanly unreadable — a "component" that's part positive weight on tech stocks, part negative weight on bonds, doesn't correspond to anything a person would naturally point to. Non-negative matrix factorization (NMF) trades some of that mathematical efficiency for components you can actually interpret as ingredients being added together, never subtracted.

The analogy: recipes, not adjustments

Think of a grocery receipt showing quantities of ingredients bought, and imagine trying to explain many different receipts as combinations of a handful of "typical meals" — a taco-night bundle, a pasta-night bundle, a breakfast bundle. Each receipt is some non-negative amount of each bundle: you can buy 2 taco-nights' worth and 0.5 pasta-nights' worth of ingredients, but you can never buy negative-1 breakfasts to "cancel out" other purchases — that's not how groceries work. NMF finds bundles ("parts") and non-negative amounts of each that reconstruct the original data, respecting the fact that in many real datasets — pixel intensities, word counts, trading volumes — negative amounts are physically meaningless.

The maths: factor into two non-negative pieces

Given a data matrix VV with nn rows and mm columns, all entries non-negative, NMF finds two smaller non-negative matrices WW (size n×kn \times k) and HH (size k×mk \times m) such that

VWH,W0, H0V \approx WH, \qquad W \ge 0, \ H \ge 0

In words: each row of VV (say, one document's word counts, or one day's trading volumes across assets) is approximated as a non-negative combination of kk "parts" — the rows of HH are the parts themselves, and the corresponding row of WW says how much of each part that observation uses. Because nothing is allowed to go negative, the only way to build up a data point is by adding parts together, never by adding a part and then subtracting another to cancel it — which is exactly why NMF parts tend to look like recognisable, additive building blocks rather than PCA's abstract combinations.

Worked example 1: two topics, four documents

Suppose word counts for the words {stock, bond, yield, dividend} across four short documents give V=(5004065040030560)V = \begin{pmatrix}5&0&0&4\\0&6&5&0\\4&0&0&3\\0&5&6&0\end{pmatrix}. With k=2k=2 parts, NMF might discover HH close to (1000.8010.850)\begin{pmatrix}1&0&0&0.8\\0&1&0.85&0\end{pmatrix} — one part heavy on "stock/dividend," the other heavy on "bond/yield." Then WW would be close to (50064005)\begin{pmatrix}5&0\\0&6\\4&0\\0&5\end{pmatrix}, meaning documents 1 and 3 are almost entirely made of part 1 ("equity-flavoured"), documents 2 and 4 almost entirely part 2 ("fixed-income-flavoured"). Multiplying WW row 1 by HH: 5×(1,0,0,0.8)=(5,0,0,4)5 \times (1,0,0,0.8) = (5,0,0,4), matching the original row exactly — the reconstruction is exact here because the topics happen to be cleanly separated in this toy example.

Worked example 2: why non-negativity forces different answers than PCA

Take a simpler matrix, V=(422433)V = \begin{pmatrix}4&2\\2&4\\3&3\end{pmatrix}. PCA's first component here would run along the direction (1,1)(1,1), capturing the shared "overall size" of each row and allowing negative loadings on the second component to capture the (2,2)(2,-2) vs (2,2)(-2,2)-style differences. NMF, forbidden from using any negative numbers anywhere, can only express each row as a non-negative sum of two non-negative basis vectors — it can't cancel anything out, so it's forced to represent even the "shared size" and the "difference" as two separate strictly-additive parts, for instance something like part 1 (1,0.5)\approx (1, 0.5) and part 2 (0.5,1)\approx (0.5, 1), with each row a non-negative blend. The two methods can land on genuinely different decompositions of the identical data, because they're solving differently-constrained problems.

Matrix explorer
dashed = before · solid = after
det 1.25trace 2.50λ 1.81, 0.69area scales by 1.25×

The explorer above shows a matrix reshaping a circle into an ellipse along two directions — NMF's WW and HH play an analogous role of finding two "directions" (parts) that reconstruct the data, but constrained to only stretch, never flip through a negative sign.

Function explorer
-224.4
x = 1.00f(x) = 1.000

NMF is typically fit by iteratively rescaling WW and HH toward a better fit — a multiplicative update rule whose stability, like the power-law shape shown here, depends on staying strictly on the positive side of zero throughout.

NMF factors non-negative data into non-negative parts and non-negative amounts of each part, forbidding cancellation — which makes it slower and less mathematically clean than PCA but frequently far more interpretable on data where negative values have no real meaning.

What this means in practice

NMF shows up wherever the data is inherently non-negative and additive: decomposing trading volume across venues into a handful of "typical volume profiles," topic modelling in news or filing text, or separating an order book's shape into recurring liquidity patterns. Unlike PCA, NMF's components generally aren't orthogonal and there's no single unique solution — different initialisations of the iterative fitting procedure can converge to different, equally valid factorizations.

The classic mistake is applying NMF to data that isn't actually non-negative, such as raw returns (which are positive and negative), without first transforming it — feeding NMF signed data either breaks the algorithm's assumptions outright or silently produces meaningless parts. Also, don't assume NMF parts are unique the way PCA components are: rerun with a different random initialisation and expect the parts to look different, even if the reconstruction quality is nearly identical.

Related concepts

Practice in interviews

Further reading

  • Lee & Seung, Learning the Parts of Objects by Non-negative Matrix Factorization (1999)
  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, ch. 14.6
ShareTwitterLinkedIn