stnmf.callbacks.consensus

stnmf.callbacks.consensus(self, i, itor, callback_data, sparsities, num_rep=30, max_elem=25000)

Callback function to run consensus analysis

The results are provided in a numpy.ndarray as cophenetic correlation coefficients stored in the key ‘cpcc’ in the dictionary callback_data.

Parameters:
  • sparsities ((n,) array_like) – List of n regularization parameter values to probe

  • num_rep (int, optional) – Number of repetitions for each parameter to check consensus over. Default is 30

  • max_elem (int, optional) – Maximum number of columns to consider from the encodings matrix. Reducing this value is beneficial if the encodings matrix has many columns, i.e. if the STNMF weight factor matrix has many spikes. Higher values may require a lot of memory. Default is 25000

Notes

Selecting max_elem elements is done by sampling without replacement. The indices are selected at initialization and are retained throughout the analysis to always compare the same elements.

Warning

Even with identical random number generator and seed, the implementation of choice-without-replacement differs from MATLAB. The consensus analysis with max_elem < m is thus not compatible with MATLAB!

Note

Implemented for finding the suitable sparsity regularization parameter for subunit recovery with stnmf.STNMF only. No other parameter type or stnmf.mf class is supported.

For more details on the implementation, visit the source code.

Examples

The code below runs the consensus analysis on a given parameter range.

>>> from stnmf import STNMF
>>> from stnmf.callbacks import consensus
>>> results = dict()
>>> STNMF(ste, callback=consensus, callback_data=results,
...       callback_kwargs=dict(sparsities=[0, 0.5, 1.0, 1.5, 2]))
>>> print(results['cpcc'])