Skip to main content

Multivariate Curve Resolution using Nonnegative Matrix Factorization

Project description

McrNmf

McrNmf is a Python package for Multivariate Curve Resolution (MCR) using a range of Nonnegative Matrix Factorization (NMF) algorithms. MCR is widely used in chemometrics, for instance, to decompose mixture spectra into their pure component spectra and associated concentration profiles.

Key Features

  • Multiple solvers – unified interface for three NMF variants: classic Alternating Least Squares (FroALS), Fast Projected Gradient (FroFPGM), and Minimum-Volume formulation (MinVol).
  • Built-in constraints – supports closure, normalization, equality, and per-component unimodality constraints.
  • Robust initialisation – includes Successive Nonnegative Projection (SNPA) algorithm for generating reliable starting estimates of spectra and concentrations
  • Lightweight implementation – written almost entirely in NumPy, with Numba used only to speed up unimodal regression.

For more details, see the documentation.


Installation

With pip:

pip install mcrnmf

Note for macOS Apple Silicon (M4) users: When running the McrNmf package installed via pip, you may encounter runtime numerical warnings (e.g., divide/overflow). To avoid these, please install via conda-forge.

With conda:

conda install -c conda-forge mcrnmf

mcrnmf requires:

  • Python ≥ 3.11.9, < 3.14
  • NumPy ≥ 1.24, < 2.3
  • Numba ≥ 0.61.2

Quick Start

from mcrnmf.datasets import load_rxn_spectra
from mcrnmf import SNPA, MinVol

# load a Raman spectroscopy data (wv × time)
X, wv, t = load_rxn_spectra()

# specify the number of components
rank = 4

# generate initial guess for W and H using SNPA
snpa = SNPA(rank=rank, iter_max=1000)
snpa.fit(X)
Wi = snpa.W  # intial guess for W (pure spectra)
Hi = snpa.H  # intial guess for H (conc. profiles)


mvol = MinVol(rank=rank,
              constraint_kind=1,
              unimodality={"H": True},
              iter_max=2000,
              tol=1e-4)
# fit the Minimum Volume NMF model
mvol.fit(X=X, Wi=Wi, Hi=Hi)
# access the decomposed factors
W = mvol.W
H = mvol.H
# access relative reconstruction error at each iter.
rel_recon_err = mvol.rel_reconstruction_error_ls

More worked examples can be found in the Usage section of the documentation.


Citation

If you use McrNmf in your work, please consider citing the following preprint:

Vasudevan SA, Kohlbrenner R, Ritschel N, Vent-Schmidt T. Beyond Classical MCR-ALS—Minimum Volume NMF and Strategic Sampling for Robust Reaction Monitoring. ChemRxiv. 2025; doi:10.26434/chemrxiv-2025-qs5g4


License

MIT – see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcrnmf-0.1.2.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcrnmf-0.1.2-py3-none-any.whl (3.8 MB view details)

Uploaded Python 3

File details

Details for the file mcrnmf-0.1.2.tar.gz.

File metadata

  • Download URL: mcrnmf-0.1.2.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for mcrnmf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 33dc5bef65d6b400c67547a7e5565088313edcb5c87d039f43619da896408766
MD5 9421b594a086db83528510618433aa76
BLAKE2b-256 afa638a84dfab412b9ed9d9898b8ef28f4709d17575f4f69e42c52d99620ba79

See more details on using hashes here.

File details

Details for the file mcrnmf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mcrnmf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for mcrnmf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2cf360fb76377de7245019aaf980ececf1581dc159ba20ed04c82a1256b1f351
MD5 5ada014f1e23fc0e4d370da6d674e9f2
BLAKE2b-256 7645b3bd2cb74d9d29bbe43085448a8bf1a42f868f7ffdb519291dc0a915a887

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page