Reference

Main API functions

class opnmf.model.OPNMF(n_components=10, max_iter=50000, tol=1e-05, init='nndsvd')

orthogonal projective non-negative matrix factorization

Parameters
n_components: int

Number of components.

alpha: int

Constant that multiplies the regularization terms. Set it to zero to have no regularization. Defaults to 1.0.

max_iter: int

Maximum number of iterations before timing out. Defaults to 200.

tol: float, default=1e-4

Tolerance of the stopping condition.

init{‘random’, ‘nndsvd’, ‘nndsvda’, ‘nndsvdar’, ‘custom’}, default=None

Method used to initialize the procedure. Valid options:

  • None: ‘nndsvd’ if n_components < n_features, otherwise ‘random’.

  • ‘random’: non-negative random matrices, scaled with: sqrt(X.mean() / n_components)

  • ‘nndsvd’: Nonnegative Double Singular Value Decomposition (NNDSVD) initialization (better for sparseness)

  • ‘nndsvda’: NNDSVD with zeros filled with the average of X (better when sparsity is not desired)

  • ‘nndsvdar’: NNDSVD with zeros filled with small random values (generally faster, less accurate alternative to NNDSVDa for when sparsity is not desired)

  • ‘custom’: use custom matrix W.

fit(X, init_W=None)

Learn a OPNMF model for the data X.

Parameters
X{array-like, sparse matrix} of shape (n_samples, n_features)

Data matrix to be decomposed

init_Warray-like of shape (n_samples, n_components)

If init=’custom’, it is used as initial guess for the solution.

Returns
self
fit_transform(X, init_W=None)

Learn a OPNMF model for the data X and returns the transformed data.

Parameters
X{array-like, sparse matrix} of shape (n_samples, n_features)

Data matrix to be decomposed

init_Warray-like of shape (n_samples, n_components)

If init=’custom’, it is used as initial guess for the solution.

Returns
Wndarray of shape (n_samples, n_components)

Transformed data

transform(X)

Transform the data X according to the fitted OPNMF model.

Parameters
X{array-like, sparse matrix} of shape (n_samples, n_features)

Data matrix to be transformed by the model.

Returns
Wndarray of shape (n_samples, n_components)

Transformed data.

opnmf.opnmf.opnmf(X, n_components, max_iter=50000, tol=1e-05, init='nndsvd', init_W=None)

Orthogonal projective non-negative matrix factorization.

Parameters
X: array-like of shape (n_samples, n_features)

Data matrix to be decomposed

n_components: int

Number of components.

max_iter: int

Maximum number of iterations before timing out. Defaults to 200.

tol: float, default=1e-4

Tolerance of the stopping condition.

init{‘random’, ‘nndsvd’, ‘nndsvda’, ‘nndsvdar’, ‘custom’}, default=None

Method used to initialize the procedure. Valid options:

  • None: ‘nndsvd’ if n_components < n_features, otherwise ‘random’.

  • ‘random’: non-negative random matrices, scaled with: sqrt(X.mean() / n_components)

  • ‘nndsvd’: Nonnegative Double Singular Value Decomposition (NNDSVD) initialization (better for sparseness)

  • ‘nndsvda’: NNDSVD with zeros filled with the average of X (better when sparsity is not desired)

  • ‘nndsvdar’: NNDSVD with zeros filled with small random values (generally faster, less accurate alternative to NNDSVDa for when sparsity is not desired)

  • ‘custom’: use custom matrix W.

init_W: array (n_samples, n_components)

Fixed initial coefficient matrix.

Returns
Wndarray of shape (n_samples, n_components)

The orthogonal non-negative factorization.

Hndarray of shape (n_components, n_features)

Expansion coefficients.

msefloat

Reconstruction error

opnmf.selection.rank_permute(X, min_components, max_components, step=1, max_iter=50000, tolerance=1e-05, init='nndsvd', init_W=None)

Orthogonal projective non-negative matrix factorization.

Parameters
X: array-like of shape (n_samples, n_features)

Data matrix to be decomposed

min_components: int

Lower bound of the number of components to test.

max_components: int

Upper bound of the number of components to test.

step: int

Spacing between values in the components range.

max_iter: int

Maximum number of iterations before timing out. Defaults to 200.

tol: float, default=1e-4

Tolerance of the stopping condition.

init{‘random’, ‘nndsvd’, ‘nndsvda’, ‘nndsvdar’, ‘custom’}, default=None

Method used to initialize the procedure. Valid options:

  • None: ‘nndsvd’ if n_components < n_features, otherwise ‘random’.

  • ‘random’: non-negative random matrices, scaled with: sqrt(X.mean() / n_components)

  • ‘nndsvd’: Nonnegative Double Singular Value Decomposition (NNDSVD) initialization (better for sparseness)

  • ‘nndsvda’: NNDSVD with zeros filled with the average of X (better when sparsity is not desired)

  • ‘nndsvdar’: NNDSVD with zeros filled with small random values (generally faster, less accurate alternative to NNDSVDa for when sparsity is not desired)

  • ‘custom’: use custom matrix W.

init_W: array (n_samples, n_components)

Fixed initial coefficient matrix.

Returns
good_ranks: array

Array with the number of components that were selected.

tested_ranks: array

Array with the number of components that were tested.

errors: array

Reconstruction error for each number of components tested.

random_errors: array

Reconstruction error for the random permutation, for each number of components tested.

estimators: array

The fitted estimators for each number of components tested.