Home > Linux > Programming > Libraries

# PyMF 0.1.9

 User Rating:Rated by: NOT RATED0 user(s)
 Developer: License / Price: Last Updated: Category: Christian Thurau | More programs GPL v3 / FREE April 30th, 2011, 17:05 GMT ROOT / Programming / Libraries

 Read user reviews (0)  Refer to a friend  Subscribe

## Python Matrix Factorization Module

PyMF is a Python module for several constrained/unconstrained matrix factorization (and related) methods. The module is early alpha and not very well tested on all platforms. It is known to work well on recent Archlinux and Ubuntu Linux distributions running Python 2.6. In principle, it should also work for Windows/Mac users. If you find any bugs please send an e-mail to cthurau AT googlemail DOT com.

PyMF currently includes the following methods:

- Non-negative matrix factorization (NMF)
- Convex non-negative matrix factorization (CNMF)
- Semi non-negative matrix factorization (SNMF)
- Archetypal analysis (AA)
- Simplex volume maximization (SiVM)
- Convex-hull non-negative matrix factorization (CHNMF)
- Binary matrix factorization (BNMF)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)
- K-means clustering (Kmeans)
- CUR decomposition (CUR)
- Compaxt matrix decomposition (CMD)

Given a dataset, most factorization methods try to minimize the Frobenius norm | data - W*H | by finding a suitable set of basis vectors W and coefficients H. The syntax for calling the various methods is quite similar. Usually, one has to submit a desired number of basis vectors and the maximum number of iterations. For example, applying NMF to a dataset data aiming at 2 basis vectors within 10 iterations works as follows:

>>> import pymf
>>> import numpy as np
>>> data = np.array([[1.0, 0.0, 2.0], [0.0, 1.0, 1.0]])
>>> nmf_mdl = pymf.NMF(data, num_bases=2, niter=10)
>>> nmf_mdl.initialization()
>>> nmf_mdl.factorize()

The basis vectors are now stored in nmf_mdl.W, the coefficients in nmf_mdl.H. To compute coefficients for an existing set of basis vectors simply copy W to nmf_mdl.W, and set compW to False:

>>> data = np.array([[1.5], [1.2]])
>>> W = np.array([[1.0, 0.0], [0.0, 1.0]])
>>> nmf_mdl = pymf.NMF(data, num_bases=2, niter=1, compW=False)
>>> nmf_mdl.initialization()
>>> nmf_mdl.W = W
>>> nmf_mdl.factorize()

By changing pymf.NMF to e.g. pymf.AA or pymf.CNMF Archetypal Analysis or Convex-NMF can be applied. Some methods might allow other parameters, make sure to have a look at the corresponding >>>help(pymf.AA) documentation. For example, CUR, CMD, and SVD are handled slightly differently, as they factorize into three submatrices which requires appropriate arguments for row and column sampling.

Product's homepage

Requirements:

· Python
· NumPy
· CVXOPT
· SciPy

### TAGS:

matrix factorization | Python library | Python | matrix | factorization

Go to top