This package implements four ways to compute a non-negative matrix factorization of a 2D non-negative numpy array.
- Multiplicative update rules (MUR)
- Alternating non-negative least squares (ANLS)
- Alternating direction method of multipliers (ADMM)
- Alternating optimization ADMM (AO-ADMM)
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:
- Lee, Seung: Learning the parts of objects by non-negative matrix factorization, 1999
- Lee, Seung: Algorithms for non-negative matrix factorization, 2001
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 save
Following the papers:
- Kim, Park: Non-negative matrix factorization based on alternating non-negativity constrained least squares and active set method
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 save
Following the papers:
- Huang, Sidiropoulos, Liavas: A flexible and efficient algorithmic framework for constrained matrix and tensor factorization, 2015
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 save
Following the papers:
- Huang, Sidiropoulos, Liavas: A flexible and efficient algorithmic framework for constrained matrix and tensor factorization, 2015
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