Initialization

Every algorithm starts from an initial pair of factors W and H. A good initialization speeds up convergence and can steer the optimizer toward a better local optimum. nnmf applies one of these methods automatically through its init keyword, but you can also call them directly to obtain (W, H) for use with solve!.

Given X of size p×n and a rank k, each initializer returns W of size p×k and H of size k×n. For algorithms that need only W initialized (such as ProjectedALS), pass zeroh=true to return a zero H.

NMF.randinit — Function
randinit(X, k; normalize=false, zeroh=false, rng=default_rng()) -> (W, H)

Randomly initialize the factors for a rank-k factorization of X. For X of size (p, n), returns W of size (p, k) and H of size (k, n) filled with uniform random values.

If normalize=true, each column of W is scaled to sum to one. If zeroh=true, H is returned as a zero matrix, appropriate for algorithms that need only W initialized (e.g. ProjectedALS). rng supplies the randomness.

Examples

julia> X = rand(10, 7);

julia> W, H = NMF.randinit(X, 3);

julia> size(W), size(H)
((10, 3), (3, 7))
source
NMF.nndsvd — Function
nndsvd(X, k; variant=:std, zeroh=false, initdata=nothing, rng=default_rng()) -> (W, H)

Initialize the rank-k factors of X with Non-Negative Double Singular Value Decomposition (NNDSVD). For X of size (p, n), returns W of size (p, k) and H of size (k, n).

variant selects the flavor: :std (standard, yields a sparse W), :a (NNDSVDa), or :ar (NNDSVDar, recommended for dense NMF). If zeroh=true, H is returned as a zero matrix, appropriate for algorithms that need only W initialized. By default the required SVD is computed with a randomized algorithm seeded by rng; pass a precomputed factorization as initdata (e.g. initdata=svd(X)) to use it instead.

Reference: C. Boutsidis and E. Gallopoulos, "SVD based initialization: A head start for nonnegative matrix factorization," Pattern Recognition, 2008.

Examples

julia> X = rand(10, 7);

julia> W, H = NMF.nndsvd(X, 3; variant=:ar);

julia> size(W), size(H)
((10, 3), (3, 7))
source
NMF.spa — Function
spa(X, k; nnls_alg=(:pivot, :cache)) -> (W, H)

Initialize the rank-k factors of X with the Successive Projection Algorithm (SPA) for separable NMF. For X of size (p, n), returns W of size (p, k) and H of size (k, n). W collects k "anchor" columns of X selected by successive orthogonal projection, and H is obtained by non-negative least squares.

Every column of X must have a nonzero sum, since the columns are normalized to sum to one before anchor selection. nnls_alg is the (alg, variant) pair forwarded to NonNegLeastSquares.nonneg_lsq when solving for H.

Reference: N. Gillis and S. A. Vavasis, "Fast and robust recursive algorithms for separable nonnegative matrix factorization," IEEE Transactions on Pattern Analysis and Machine Intelligence, 36(4):698-714, 2014.

Examples

julia> X = rand(10, 7);

julia> W, H = NMF.spa(X, 3);

julia> size(W), size(H)
((10, 3), (3, 7))
source