Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Nonnegative matrix factorization

`[W,H] = nnmf(A,k)`

[W,H] = nnmf(A,k,* param1*,

`val1`

`param2`

`val2`

[W,H,D] = nnmf(...)

`[W,H] = nnmf(A,k)`

factors the nonnegative *n*-by-*m* matrix `A`

into
nonnegative factors `W`

(*n*-by-`k`

)
and `H`

(`k`

-by-*m*).
The factorization is not exact; `W*H`

is a lower-rank
approximation to `A`

. The factors `W`

and `H`

are
chosen to minimize the root-mean-squared residual `D`

between `A`

and `W*H`

:

D = norm(A-W*H,'fro')/sqrt(N*M)

The factorization uses an iterative method starting with random
initial values for `W`

and `H`

.
Because the root-mean-squared residual `D`

may have
local minima, repeated factorizations may yield different `W`

and `H`

.
Sometimes the algorithm converges to a solution of lower rank than *k*,
which may indicate that the result is not optimal.

`W`

and `H`

are normalized
so that the rows of `H`

have unit length. The columns
of `W`

are ordered by decreasing length.

`[W,H] = nnmf(A,k,`

specifies
optional parameter name/value pairs from the following table.* param1*,

`val1`

`param2`

`val2`

Parameter | Value |
---|---|

`'algorithm'` | Either In general, the |

`'w0'` | An |

`'h0'` | A |

`'options'` | An options structure as created by the `Display` — Level of display. Choices:`'off'` (default) — No display`'final'` — Display final result`'iter'` — Iterative display of intermediate results
`MaxIter` — Maximum number of iterations. Default is`100` . Unlike in optimization settings, reaching`MaxIter` iterations is treated as convergence.`TolFun` — Termination tolerance on change in size of the residual. Default is`1e-4` .`TolX` — Termination tolerance on relative change in the elements of`W` and`H` . Default is`1e-4` .`UseParallel` — Set to`true` to compute in parallel. Default is`false` .`UseSubstreams` — Set to`true` to compute in parallel in a reproducible fashion. Default is`false` . To compute reproducibly, set`Streams` to a type allowing substreams:`'mlfg6331_64'` or`'mrg32k3a'` .`Streams` — A`RandStream` object or cell array of such objects. If you do not specify`Streams` ,`nnmf` uses the default stream or streams. If you choose to specify`Streams` , use a single object except in the case`UseParallel` is`true` `UseSubstreams` is`false`
In that case, use a cell array the same size as the Parallel pool.
To compute in parallel, you need Parallel Computing Toolbox™. |

`'replicates'` | The number of times to repeat the factorization, using
new random starting values for |

`[W,H,D] = nnmf(...)`

also returns `D`

,
the root mean square residual.

[1] Berry, M. W., et al. “Algorithms
and Applications for Approximate Nonnegative Matrix Factorization.” *Computational
Statistics and Data Analysis*. Vol. 52, No. 1, 2007, pp.
155–173.