Skip to content

omega-sz/nimfa

 
 

Repository files navigation

Nimfa


build: passing build: passing GitHub release BSD license Conda Version

Nimfa is a Python module that implements many algorithms for nonnegative matrix factorization. Nimfa is distributed under the BSD license.

The project was started in 2011 by Marinka Zitnik as a Google Summer of Code project, and since then many volunteers have contributed. See AUTHORS file for a complete list of contributors.

It is currently maintained by a team of volunteers.

[News:] Scikit-fusion, collective latent factor models, matrix factorization for data fusion and learning over heterogeneous data.

[News:] fastGNMF, fast implementation of graph-regularized non-negative matrix factorization using Facebook FAISS.

Important links

Dependencies

Nimfa is a fantastic library for non-negative matrix factorization in Python. I don’t have the expertise to optimize the underlying algorithm, but I’ve identified compatibility issues with NumPy 2.0 that are causing errors.The primary goal of this fork is to adjust syntax to accommodate Python syntax updates and account for deprecated functions in NumPy 2.0. e.g.: np.mat to np.array

All modifications were auto-generated by GitHub Copilot in VS Code.

It works in my conda env with Python 3.11.11 with Numpy 2.1.0 and Scipy 1.15.2. (2025.08.12)

Install

pip install git+https://github.com/omega-sz/nimfa.git

original text below

Nimfa is tested to work under Python 2.7 and Python 3.4. The required dependencies to build the software are NumPy >= 1.7.0, The required dependencies to build the software are NumPy >= 2.0.0, SciPy >= 0.12.0.

For running the examples Matplotlib >= 1.1.1 is required.

Install

This package uses setuptools, which is a common way of installing python modules. To install in your home directory, use:

python setup.py install --user

To install for all users on Unix/Linux:

sudo python setup.py install

For more detailed installation instructions, see the web page http://ai.stanford.edu/~marinka/nimfa.

Alternatively, you may also install this package using conda:

conda install -c conda-forge nimfa

Use

Run alternating least squares nonnegative matrix factorization with projected gradients and Random Vcol initialization algorithm on medulloblastoma gene expression data:

>>> import nimfa
>>> V = nimfa.examples.medulloblastoma.read(normalize=True)
>>> lsnmf = nimfa.Lsnmf(V, seed='random_vcol', rank=50, max_iter=100)
>>> lsnmf_fit = lsnmf()
>>> print('Rss: %5.4f' % lsnmf_fit.fit.rss())
Rss: 0.2668
>>> print('Evar: %5.4f' % lsnmf_fit.fit.evar())
Evar: 0.9997
>>> print('K-L divergence: %5.4f' % lsnmf_fit.distance(metric='kl'))
K-L divergence: 38.8744
>>> print('Sparseness, W: %5.4f, H: %5.4f' % lsnmf_fit.fit.sparseness())
Sparseness, W: 0.7297, H: 0.8796

Cite

@article{Zitnik2012,
  title     = {Nimfa: A Python Library for Nonnegative Matrix Factorization},
  author    = {Zitnik, Marinka and Zupan, Blaz},
  journal   = {Journal of Machine Learning Research},
  volume    = {13},
  pages     = {849-853},
  year      = {2012}
}

Selected publications (Methods)

Selected publications (Applications)

Tutorials

About

Nimfa: Nonnegative matrix factorization in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%