Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MCR-ALS Lite: Multivariate Curve Resolution - Alternating Least Squares

Lite implementation of MCR-ALS for resolving spectral mixtures into pure component profiles.

πŸ“– Overview

MCR-ALS Lite is the fundamental, lightweight implementation of Multivariate Curve Resolution using Alternating Least Squares. This Lite version provides the core algorithm with essential non-negativity constraints and spectral normalization. It serves as the foundation for more advanced MCR variants that may be added to this repository in the future.

MCR-ALS is a powerful soft-modeling technique for decomposing complex multivariate data into chemically meaningful components. It resolves mixtures by iteratively estimating concentration profiles and pure spectral profiles from experimental data.

The Bilinear Model

MCR-ALS decomposes a data matrix according to the bilinear model:

D = C Γ— S + E

where:

  • D (I Γ— J): Experimental data matrix (e.g., spectra collected over time)
  • C (I Γ— N): Concentration profiles of N components across I samples
  • S (N Γ— J): Pure spectral profiles of N components across J variables
  • E (I Γ— J): Residual matrix (experimental noise and model error)

Key Features of the Lite Version

  • βœ… Flexible initialization with C_init, S_init, both, or neither
  • βœ… Explicit component specification (N parameter)
  • βœ… Optional non-negativity constraints on C and/or S (individually controllable)
  • βœ… Spectral normalization (unit Euclidean norm) to prevent scale ambiguity
  • βœ… Real-time visualization of convergence progress
  • βœ… Lack of Fit (LOF) monitoring at each iteration
  • βœ… Simple, lightweight implementation with minimal dependencies
  • βœ… Foundation for future MCR variants in this repository

Note: This is the Lite version. Future additions to this repository may include MCR-ALS with additional constraints (unimodality, closure, selectivity), MCR-BANDS, weighted MCR-ALS, and other advanced variants.


Applications

MCR-ALS is widely used in:

  • Spectroscopy: UV-Vis, NIR, Raman, FTIR, NMR
  • Chromatography: HPLC-DAD, GC-MS, LC-MS
  • Process monitoring: Reaction kinetics, process analytical technology (PAT)
  • Environmental analysis: Mixture quantification
  • Quality control: Pharmaceutical, food, and chemical industries

πŸ“Š Algorithm

Alternating Least Squares (ALS)

  1. Initialize concentration profiles C and/or spectral profiles S (with N components specified)

  2. Iterate until convergence:

    If C_init provided:

    • Step 1: Fix C, solve for S: min ||D - CΓ—S||Β² (with non-negativity if nonnegS = true)
    • Step 2: Normalize each row of S to unit norm, compensate in C
    • Step 3: Fix S, solve for C: min ||D - CΓ—S||Β² (with non-negativity if nonnegC = true)

    If S_init provided:

    • Step 1: Fix S, solve for C: min ||D - CΓ—S||Β² (with non-negativity if nonnegC = true)

    • Step 2: Fix C, solve for S: min ||D - CΓ—S||Β² (with non-negativity if nonnegS = true)

    • Step 3: Normalize each row of S to unit norm, compensate in C

    • Step 4: Calculate Lack of Fit: LOF = 100 Γ— ||D - CΓ—S||_F / ||D||_F

    • Step 5: Check convergence: if |LOF(i-1) - LOF(i)| < tol, stop

  3. Return optimized C, S, and LOF history

Normalization Strategy

Each spectral component (row of S) is normalized by its Euclidean norm:

% Normalize spectral row i and compensate in C S(i,:) = S(i,:) / norm(S(i,:), 2); C(:,i) = C(:,i) * norm(S(i,:), 2);

This ensures:

  • Unique scaling between C and S
  • Spectral profiles have unit intensity
  • Concentration profiles carry the scaling information

πŸš€ Installation

Prerequisites

  • MATLAB R2016a or later
  • No additional toolboxes required (uses custom fnnls implementation)

Setup

  1. Clone or download the repository
  2. Add the MCR-ALS Lite folder to your MATLAB path:

addpath('path/to/Codes/MCR-ALS Lite');

  1. Verify installation:

which MCR_ALS_Lite


πŸ“ Usage

Basic Example - Initialize with Concentration Profiles

% Load your data matrix D (samples Γ— variables) % For example: D could be 50 spectra Γ— 200 wavelengths

% Specify number of components and initialize concentration profiles nComponents = 3; C_init = rand(size(D,1), nComponents); % Random initialization

% Run MCR-ALS Lite (C_init provided, S_init is []) [C, S, lof] = MCR_ALS_Lite(D, nComponents, C_init, [], 100, 1e-6);

% C: Concentration profiles (samples Γ— components) % S: Spectral profiles (components Γ— variables) % lof: Lack of fit per iteration (%)

Basic Example - Initialize with Spectral Profiles

% Load your data matrix D (samples Γ— variables) % For example: D could be 50 spectra Γ— 200 wavelengths

% Specify number of components and initialize spectral profiles nComponents = 3; S_init = rand(nComponents, size(D,2)); % Random initialization

% Run MCR-ALS Lite (C_init is [], S_init provided) [C, S, lof] = MCR_ALS_Lite(D, nComponents, [], S_init, 100, 1e-6);

% C: Concentration profiles (samples Γ— components) % S: Spectral profiles (components Γ— variables) % lof: Lack of fit per iteration (%)

Example - Using Optional Non-Negativity Constraints

% Full non-negativity (default behavior, backward compatible) [C, S, lof] = MCR_ALS_Lite(D, 3, C_init, [], 100, 1e-6, [true true]);

% Only constrain concentrations (C) to be non-negative [C, S, lof] = MCR_ALS_Lite(D, 3, C_init, [], 100, 1e-6, [true false]);

% Only constrain spectra (S) to be non-negative [C, S, lof] = MCR_ALS_Lite(D, 3, C_init, [], 100, 1e-6, [false true]);

% Fully unconstrained (both C and S can be negative) [C, S, lof] = MCR_ALS_Lite(D, 3, C_init, [], 100, 1e-6, [false false]);

% Scalar input (broadcast to both modes) [C, S, lof] = MCR_ALS_Lite(D, 3, C_init, [], 100, 1e-6, true); % same as [true true]

Advanced Initialization

For better results, use informed initialization. These methods can provide either concentration (C) or spectral (S) profiles:

Method Description Output When to Use
PUREST PURity-based Evolving Self-modeling Technique S profiles Pure variable detection
SIMPLISMA/ESI SIMPLe-to-use Interactive Self-modeling / Essential Spectra Identification S profiles Simplex geometry for pure components
Pure windows Known regions where components are isolated C or S Domain knowledge of mixture
Random Random positive values C or S Last resort (quick initialization)

Running the Test Script

% Run the provided test on synthetic data test_MCR_ALS_Lite

This will:

  • Generate synthetic spectral data with 3 known components
  • Apply MCR-ALS Lite to recover concentration and spectral profiles
  • Display convergence plots in real-time
  • Compare recovered vs. true profiles

πŸ“‹ Function Reference

MCR_ALS_Lite

[C, S, lof] = MCR_ALS_Lite(D, N, C_init, S_init, maxIter, tol, nonnegMode)

Inputs:

  • D β€” Data matrix (I Γ— J)
  • N β€” Number of components (positive integer)
  • C_init β€” Initial concentration profiles (I Γ— N) OR [] for random
  • S_init β€” Initial spectral profiles (N Γ— J) OR [] for random
  • maxIter β€” Maximum iterations
  • tol β€” (Optional) Convergence tolerance for LOF change (default: 1e-6)
  • nonnegMode β€” (Optional) 1Γ—2 logical vector [nonnegC, nonnegS]:
    • nonnegC = true β†’ C constrained non-negative
    • nonnegS = true β†’ S constrained non-negative
    • If scalar given, it is broadcast to both modes
    • Default: [true true] (fully non-negative, original behavior)

Note: Provide C_init, S_init, both, or neither (all random if both []). Provided matrices must have N components.

Outputs:

  • C β€” Final concentration profiles (I Γ— N)
  • S β€” Final spectral profiles (N Γ— J), each row normalized to unit norm
  • lof β€” Lack of fit per iteration (%)

Dependencies:

  • fnnls.m β€” Fast Non-Negative Least Squares solver (included)

fnnls

X = fnnls(A, B, tol, maxIter)

Fast non-negative least squares solver for multiple right-hand sides.
Solves min_X ||A*X - B||_F^2 subject to X β‰₯ 0, one column of B at a time.

Inputs:

  • A β€” Design matrix (n Γ— p)
  • B β€” Right-hand sides (n Γ— q)
  • tol β€” Stationarity/zero tolerance (default: 1e-12 * ||A||_F)
  • maxIter β€” Max active-set expansions per RHS (default: 5*p)

Outputs:

  • X β€” Solution matrix (p Γ— q) with non-negative entries

Notes:

  • Based on the Lawson–Hanson active-set NNLS, with Bro–De Jong acceleration (reuse A'*A and A'*B across RHS).
  • Falls back to pseudoinverse when a passive subset is ill-conditioned.

πŸ”¬ References

  1. Tauler, R. (1995) β€” Multivariate curve resolution applied to second order data. Chemometrics and Intelligent Laboratory Systems, 30(1), 133–146.
    DOI: https://doi.org/10.1016/0169-7439(95)00047-X

  2. de Juan, A., & Tauler, R. (2021) β€” Multivariate Curve Resolution: 50 years addressing the mixture analysis problem – A review. Analytica Chimica Acta, 1145, 59–78.
    DOI: https://doi.org/10.1016/j.aca.2020.10.051

  3. Jaumot, J., de Juan, A., & Tauler, R. (2015) β€” MCR-ALS GUI 2.0: New features and applications. Chemometrics and Intelligent Laboratory Systems, 140, 1–12.
    DOI: https://doi.org/10.1016/j.chemolab.2014.10.003

  4. Lawton, W. H., & Sylvestre, E. A. (1971) β€” Self modeling curve resolution. Technometrics, 13(3), 617–633.
    DOI: https://doi.org/10.1080/00401706.1971.10488823

  5. Bro, R., & De Jong, S. (1997) β€” A fast non-negativity-constrained least squares algorithm. Journal of Chemometrics, 11(5), 393–401.
    DOI: https://doi.org/10.1002/%28SICI%291099-128X%28199709/10%2911%3A5%3C393%3A%3AAID-CEM483%3E3.0.CO%3B2-L

  6. Lawson, C. L., & Hanson, R. J. (1974) β€” Solving Least Squares Problems. Prentice–Hall. (SIAM Classics reprint)
    DOI: https://doi.org/10.1137/1.9781611971217

Additional Reading

  • Tauler, R., Smilde, A., & Kowalski, B. (1995) β€” Selectivity, local rank, three-way data analysis and ambiguity in multivariate curve resolution. Journal of Chemometrics, 9(1), 31–58.
    DOI: https://doi.org/10.1002/cem.1180090105

  • Golshan, A., Abdollahi, H., & Maeder, M. (2011) β€” Resolution of rotational ambiguity for three-component systems. Analytical Chemistry, 83(3), 836–841.
    DOI: https://doi.org/10.1021/ac102429q


πŸ“„ License

Released under the MIT License.


πŸ‘€ Authors

  • AdriΓ‘n GΓ³mez-SΓ‘nchez
  • Date: October 30, 2025
  • Reviewed by: Lovelace's Square

πŸ“§ Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

For issues or questions, please open an issue in this repository.


🏷️ Keywords

Multivariate Curve Resolution β€’ MCR-ALS β€’ Alternating Least Squares β€’ Spectral unmixing β€’ Chemometrics β€’ Non-negative least squares β€’ Bilinear decomposition β€’ Mixture analysis β€’ MATLAB