This package implements four ways to compute a non-negative matrix factorization of a 2D non-negative numpy array.
Given non-negative data
and the number of components
you want the dataset to factorize into, you simply create an NMF instance and use the factorize method to compute the factorization.
$ from nmf import NMF
$ nmf = NMF(data, components)
$ nmf.factorize(method='mur', **method_args)
You can directly access the factors nmf.w
and nmf.h
.
If you want to save the results to a file, you can use the save_factorization
method.
The default folder to save is ./results
and the default file name is constructed using the parameters used in the factorization.
Following the papers:
Accepts following method parameters:
distance_type
-- STRING: 'eu' for Euclidean, 'kl' for Kullback Leiblermin_iter
-- INT: minimum number of iterationsmax_iter
-- INT: maximum number of iterationstol1
-- FLOAT: convergence tolerancetol2
-- FLOAT: convergence tolerancelambda_w
-- FLOAT: regularization parameter for w-Updatelambda_h
-- FLOAT: regularization parameter for h-Updatenndsvd_init
-- Tuple(BOOL, STRING): if BOOL = True, use NNDSVD-type STRINGsave_dir
-- STRING: folder to which to saveFollowing the papers:
Accepts following method parameters:
distance_type
-- STRING: 'eu' for Euclidean, 'kl' for Kullback Leibleruse_fcnnls
-- BOOL: if true, use FCNNLS algorithmlambda_w
-- FLOAT: regularization parameter for w-Updatelambda_h
-- FLOAT: regularization parameter for h-Updatemin_iter
-- INT: minimum number of iterationsmax_iter
-- INT: maximum number of iterationstol1
-- FLOAT: convergence tolerancetol2
-- FLOAT: convergence tolerancenndsvd_init
-- Tuple(BOOL, STRING): if BOOL = True, use NNDSVD-type STRINGsave_dir
-- STRING: folder to which to saveFollowing the papers:
Accepts following method parameters:
rho
-- FLOAT: ADMM dampening parameterdistance_type
-- STRING: 'eu' for Euclidean, 'kl' for Kullback Leiblerreg_w
-- Tuple(FLOAT, STRING): value und type of w-regularizationreg_h
-- Tuple(FLOAT, STRING): value und type of h-regularizationmin_iter
-- INT: minimum number of iterationsmax_iter
-- INT: maximum number of iterationstol1
-- FLOAT: convergence tolerancetol2
-- FLOAT: convergence tolerancenndsvd_init
-- Tuple(BOOL, STRING): if BOOL = True, use NNDSVD-type STRINGsave_dir
-- STRING: folder to which to saveFollowing the papers:
Accepts following method parameters:
distance_type
-- STRING: 'eu' for Euclidean, 'kl' for Kullback Leiblerreg_w
-- Tuple(FLOAT, STRING): value und type of w-regularizationreg_h
-- Tuple(FLOAT, STRING): value und type of h-regularizationmin_iter
-- INT: minimum number of iterationsmax_iter
-- INT: maximum number of iterationsadmm_iter
-- INT: maximum number of internal ADMM iterationstol1
-- FLOAT: convergence tolerancetol2
-- FLOAT: convergence tolerancenndsvd_init
-- Tuple(BOOL, STRING): if BOOL = True, use NNDSVD-type STRINGsave_dir
-- STRING: folder to which to save