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

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.


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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcrnmf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f119c760b9fc3a2847fe3005312a0d2c725c13b54da002915254ba5bc13b4c1c
MD5 508bbe1c39ab07ef6d7105ab24af72c1
BLAKE2b-256 46a49e082eef3b378a410023403f8c782385f7d6dafc530e38c9989867284633

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mcrnmf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a87e8372709b98f896d6687b5e9b88a5addf581eeaa927993a748ba6ea0f9fed
MD5 a006b833dac8d087d96707fd3cfbfb36
BLAKE2b-256 92454adab670834919457ad3148cc6472f39418af98b67fdaf2133d7e9056f46

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