stnmf.mf.SparseSemiNMF

class stnmf.mf.SparseSemiNMF(*args, sparsity=1.7, **kwargs)

Bases: SemiNMF

Sparse semi-non-negative matrix factorization (NMF)

Sparse semi-NMF solving

\(\mathbf{V} \approx \mathbf{W}_+\mathbf{H} \,,\)

where w is non-negative and v and h are not, using accelerated fast HALS algorithms and sparsity constraints.

See also

stnmf.mf.MF

Abstract matrix factorization class

__init__(*args, sparsity=1.7, **kwargs)

Sparse semi-non-negative matrix factorization

Parameters:

sparsity (float, optional) – Regularization weight for sparsity. Default is 1.7

Keyword Arguments:

kwargs – See MF class

See also

stnmf.mf.MF

Abstract matrix factorization class

Methods

__init__(*args[, sparsity])

Sparse semi-non-negative matrix factorization

factorize

init(*args[, lrc_kwargs])

Initialize features w

reseed([seed])

Re-seed the random number generator (RNG)

residual()

Re-compute reconstruction error

update_h()

Update encodings h using Moore–Penrose pseudoinverse

update_w()

Update features w using AF-HALS

Attributes

desc

Readable analysis name

res

Reconstruction error (residual) based on Frobenius norm

h

Encodings

w

Features

desc = 'Sparse semi-NMF'

Readable analysis name

Type:

str

factorize(num_iter=1000, callback=None, callback_data=None, callback_kwargs=None, disp=True, tqdm_args=None)

Factorize by iterative updates

Parameters:
  • num_iter (int, optional) – Number of update iterations. Default is 1000

  • callback (function (**kwargs) -> bool, optional) – Callback function to be called after each iteration. See notes below for details on the provided function arguments. A return value of False will terminate the iteration prematurely. Default is None

  • callback_data (dict, optional) – Dictionary to store callback data. Depending on the callback this dictionary will contain the callback results. Ignored, if callback is None. Default is None

  • callback_kwargs (dict, optional) – Dictionary serving as additional keyword arguments passed to the callback if specified. Ignored, if callback is None. Default is None

  • disp (bool, optional) – Show progress bar. Equivalent to passing disabled=True in tqdm_args. Default is True

  • tqdm_args (dict, optional) – Keyword arguments for tqdm progress bar. Ignored if disp if False. Default is None

Notes

The callback function will be supplied with the following keyword arguments. Additional arguments can be passed through callback_kwargs.

Callback Args:
  • self (stnmf.mf.MF) – Current MF object. Attributes are mutable

  • i (int) – Index of the current (completed) iteration. Initialization is zero

  • itor (tqdm.tqdm) – Iterator used during the factorization. Attributes are mutable

  • callback_data (dict) – Dictionary to store and preserve callback data. Mutable

init(*args, lrc_kwargs=None, **kwargs)

Initialize features w

Parameters:
  • w0 ((n,r) array_like or {'random', 'nnsvdlrc'}, optional) – Initial features w. If array_like, serves as the initial w directly. If ‘random’ or ‘nnsvdlrd’, calls the functions from stnmf.init. Default is ‘nnsvdlrc’

  • lrc_kwargs (dict, optional) – Keyword arguments for low-rank correction. Ignored if w0 is not ‘nnsvdlrc’. Default is None

Raises:

ValueError – If array sizes mismatch.

property res

Reconstruction error (residual) based on Frobenius norm

Type:

float

reseed(seed=None)

Re-seed the random number generator (RNG)

Parameters:

seed (int or None, optional) – Random number generator (RNG) seed. If None, the RNG is initialized without a seed based on OS context. Default is None

Notes

The RNG in this class is only used if initialization is random. Calling this method will overwrite the attribute rng. It is not compatible with using a custom rng.

See also

stnmf.util.create_rng

Create an RNG instance

residual()

Re-compute reconstruction error

See also

res

Reconstruction error (residual)

h

Encodings

Type:

numpy.ndarray

w

Features

Type:

numpy.ndarray

update_h()

Update encodings h using Moore–Penrose pseudoinverse

update_w()

Update features w using AF-HALS