High-level interface
nnmf runs a full factorization — initialization followed by optimization — and returns a Result. The init and alg keyword arguments choose the initialization method and factorization algorithm; the Initialization and Algorithms pages describe the available choices in detail.
NMF.nnmf — Function
nnmf(X, k; init=:nndsvdar, alg=:greedycd, maxiter=100, tol=…, kwargs...) -> ResultFactorize the non-negative matrix X into a product W*H of two non-negative matrices, where W has k columns and H has k rows, so that W*H approximates X. X is p×n, W is p×k, and H is k×n; k must not exceed min(p, n). The factors are initialized and then optimized, and the Result is returned.
Keyword arguments
init::Symbol=:nndsvdar: initialization method, one of:random,:nndsvd,:nndsvda,:nndsvdar,:spa, or:custom(supplyW0andH0).initdata=nothing: for the:nndsvdvariants, a precomputed SVD ofX(e.g.svd(X)) to use in place of an internally computed randomized SVD.alg::Symbol=:greedycd: factorization algorithm, one of:multmse,:multdiv,:projals,:alspgrad,:cd,:greedycd, or:spa. Selecting:sparequiresinit=:spa.maxiter::Integer=100: maximum number of iterations.tol::Real=cbrt(eps(eltype(X))/100): convergence tolerance on the relative change ofWandH.replicates::Integer=1: number of runs from independent random initializations; the result with the smallest objective value is returned.W0,H0: custom initial factors, required (and used) only wheninit=:custom. They may be overwritten; pass copies to preserve them.update_H::Bool=true: iffalse, holdHfixed and update onlyW.verbose::Bool=false: whether to print per-iteration progress.io::IO=stdout: stream for progress output whenverbose=true.rng::AbstractRNG=default_rng(): random number generator for initialization and any randomized algorithm steps.
Examples
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))NMF.Result — Type
Result{T}The value returned by nnmf and solve!, holding a factorization X ≈ W*H together with metadata about the run.
Fields
W::Matrix{T}: thep×kleft factor.H::Matrix{T}: thek×nright factor.niters::Int: number of iterations performed.converged::Bool: whether the algorithm reached its convergence tolerance.objvalue::T: objective value at the final iteration.
Examples
julia> X = rand(8, 6);
julia> r = nnmf(X, 3);
julia> size(r.W), size(r.H)
((8, 3), (3, 6))