NMF.jl
NMF.NMF — Module
NMF.jl provides algorithms and initializations for non-negative matrix factorization: approximating a non-negative matrix X of size p×n by a product W*H, where W is p×k, H is k×n, both are non-negative, and k is a chosen rank.
The high-level entry point is nnmf, which performs initialization and optimization in a single call. For finer control, initialize W and H with NMF.randinit, NMF.nndsvd, or NMF.spa and then run an algorithm in place with NMF.solve!.
Such factorizations are widely used in text mining, image analysis, and recommendation systems, where the non-negativity constraint yields parts-based, interpretable factors.
Installation
using Pkg
Pkg.add("NMF")Quick start
The high-level nnmf function performs initialization and optimization in a single call:
julia> using NMF
julia> X = rand(8, 6);
julia> r = nnmf(X, 3; alg=:multmse, maxiter=50, tol=1.0e-4);
julia> size(r.W), size(r.H)
((8, 3), (3, 6))The returned Result holds the factors r.W and r.H along with metadata about the run (r.niters, r.converged, r.objvalue).
How the package is organized
A factorization proceeds in two stages, each backed by a set of tools:
- Initialization produces starting factors
WandH. See Initialization. - Optimization refines the factors toward a local optimum. See Algorithms.
nnmf selects and runs both stages for you through its init and alg keyword arguments. For finer control you can call an initializer directly and then run an algorithm in place with solve!; see Examples.
Apart from nnmf, the package's names are not exported. Refer to them with the NMF. prefix (for example NMF.solve!, NMF.randinit), which keeps user code explicit about where each name comes from.
See also
NMFMerge augments any least-squares NMF algorithm by merging components.