FPGM#

class mcrnmf.nnls.FPGM(constraint_kind=0, iter_max=500, tol=1e-06)[source]#

An implementation of Non-negative Least Squares solver using Fast Projected Gradient Method.

Solves for \(H\) given \(X\) and \(W\) by minimizing the following objective function with other optional constraints on \(H\)

\[||X - WH||_{F}^2\]

where \(||\cdot||_F\) is the Frobenius norm.

Parameters:
constraint_kindinteger-like {0, 1, 2, 3}, default=0

The following constraints are applied based on the integer value specified

  • If 0: Only \(H \geq 0\).

  • If 1: Closure constraint \(H^T e ≤ e\).

  • If 2: Closure constraint \(H e = e\).

  • If 3: Closure constraint \(H^T e = e\).

iter_maxint, default=500

Maximum number of iterations.

tolfloat, default=1e-6

Tolerance for convergence. Must be in the interval \((0, 1)\).

Convergence is reached when:

\[{||H^{i} - H^{i-1}||_{F} \over ||H^{1} - H^{0}||_{F}} \leq \textrm{tol}\]

where \(H^{i}\) is \(H\) after iteration \(i\) and \(H^{0}\) is initial \(H\).

References

[1]

Gillis, N. (2020). Nonnegative matrix factorization. Society for Industrial and Applied Mathematics.

[2]

Lin, Chih-Jen. “Projected gradient methods for nonnegative matrix factorization.” Neural computation 19.10 (2007): 2756-2779.

Examples

>>> from mcrnmf.nnls import FPGM
>>> from mcrnmf import SNPA
>>> from mcrnmf.datasets import load_rxn_spectra
>>>
>>> # load the dataset available in the package
>>> X, wv, time = load_rxn_spectra()
>>> # Get an estimate for W from SNPA
>>> snpa = SNPA(rank=4)
>>> snpa.fit(X=X)
>>> W = snpa.W
>>>
>>> # create an instance of FPGM
>>> fpgm = FPGM(constraint_kind=1, iter_max=400, tol=1e-4)
>>> # solve for H
>>> H, is_converged = fpgm.solve(X=X, W=W, unimodal_H=True)
solve(X, W, H=None, known_H=None, unimodal_H=False)[source]#

Solves for \(H\) given \(X\) and \(W\).

Parameters:
Xndarray of shape (m, n)

Data array.

Wndarray of shape (m, k)

Coefficient array.

Hndarray of shape (k, n) or None, defualt=None

Initial guess for the solution array. If None, an initial guess is generated using least squares solution of \(WH \approx X\).

known_Hndarray of shape (rank, n_samples), default=None

Array containing known values of \(H\).

  • The np.nan elements of the array are treated as unknown.

  • Equality constraint is applied at those indices of \(H\) which do not correspond np.nan entries in known_H.

unimodal_Hbool or list of bool, default=False

Applies unimodality constraint to rows of H.

  • If bool and True applies unimodality constraint to all rows of H

  • If list[bool]:

    • Length of list must be equal to number of columns in W.

    • Applies unimodality constraint only those rows of H which are marked as True. Example: [True, False, True] applies unimodality constraint to rows 1 and 3 of H.

Returns:
Hndarray of shape (k, n)

Solution array.

is_convergedbool

Whether algorithm converged within iter_max iterations.

  • True if convergence was reached based on tol criterion

  • False if maximum iterations were reached without convergence