Categories &

Functions List

Function Reference: nnmf

statistics: [W, H] = nnmf (A, K)
statistics: [W, H, D] = nnmf (A, K)
statistics: […] = nnmf (…, Name, Value)

Nonnegative matrix factorization.

[W, H] = nnmf (A, K) factors the nonnegative N × M matrix A into nonnegative factors W (N × K) and H (K × M) whose product approximates A, by minimizing the root-mean-square residual between A and W * H. K, the number of factors, is typically smaller than N and M.

[W, H, D] = nnmf (…) also returns the root-mean-square residual D, that is norm (A - W * H, "fro") / sqrt (N * M).

The factorization is not unique: the returned factors are normalized so that the rows of H have unit length, and the columns of W (and the corresponding rows of H) are ordered by decreasing length of the columns of W. Because the objective is not convex, the iteration converges to a local minimum that depends on the starting point; use 'Replicates' to try several random starts and keep the best.

Name/Value pairs:

'Algorithm'
'als' (default) for alternating least squares, or 'mult' for multiplicative updates. Alternating least squares usually converges faster and more reliably; multiplicative updates are more sensitive to the starting point.
'W0'
An N × K initial value for W.
'H0'
A K × M initial value for H.
'Replicates'
The number of times to repeat the factorization from new random starting points, keeping the result with the smallest residual. The default is 1. Ignored for a starting point fixed by both 'W0' and 'H0'.
'Options'
A structure of algorithm options (as returned by statset) whose MaxIter, TolFun, and TolX fields control the iteration.

See also: pca, statset

Source Code: nnmf

Factor a nonnegative matrix into two rank-2 nonnegative factors.

 A = [1, 2, 3; 2, 4, 6; 3, 5, 7; 4, 8, 12];
 [W, H, D] = nnmf (A, 2);
 D
D = 2.6952e-15

W * H approximates A.

 W * H
ans =

    1    2    3
    2    4    6
    3    5    7
    4    8   12