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.1.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.1-py3-none-any.whl (3.8 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcrnmf-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e3a37c374049b5a565dbfa5e5223ddf216f64a76255497a27183e72caa1c24cf
MD5 5a76b62ee0fe02b2fab6c4df63af11d9
BLAKE2b-256 747196558161327d61aeb820b811600f86e9caee233b5aac39f4f91859baeb42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcrnmf-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1146c09de4924f6d7d3f16646c9fc63da28d4cbd28c590b73f4a9b1defaf5aec
MD5 3327dfacadac8e12e825daaf3fe5eb8d
BLAKE2b-256 4085cfc1eab3397b9d5f78d6f38f02ee037b29575943d3d20f74f60db506fdf5

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