spectrochempy.MCRALS

class MCRALS(**kwargs)[source]

Performs MCR-ALS of a dataset knowing the initial C or St matrix.

MCR-ALS (Multivariate Curve Resolution - Alternating Least Squares) resolve”s a set (or several sets) of spectra X of an evolving mixture (or a set of mixtures) into the spectra St of ‘pure’ species and their concentration profiles C. In terms of matrix equation: .. math::X = CS^T + E where \(E\) is the lmatrix of residuals.

Parameters
  • dataset (NDDataset) – The dataset on which to perform the MCR-ALS analysis.

  • guess (NDDataset) – Initial concentration or spectra.

  • **kwargs – Optional parameters, see Other parameters below.

Other Parameters
  • tol (float, optional, default 0.1) – Convergence criterion on the change of residuals (percent change of standard deviation of residuals).

  • maxit (int, optional, default=50) – Maximum number of ALS minimizations.

  • maxdiv (int, optional, default=5) – Maximum number of successive non-converging iterations.

  • nonnegConc (str or array of indexes or None, default "all") – Non negativity constraint on concentrations. If set to 'all' (default) all concentrations profiles are considered non-negative. If an array of indexes is passed, the corresponding profiles are considered non-negative, not the others. For instance [0, 2] indicates that profile #0 and #2 are non-negative while

    profile #1 can be negative. If set to None or [], all profiles can be negative.

  • unimodConc (str or array of indexes, default "all") – Unimodality constraint on concentrations. If set to 'all' (default) all concentrations profiles are considered unimodal. If an array of indexes is passed, the corresponding profiles are considered unimodal, not the others. For instance [0, 2] indicates that profile #0 and #2 are unimodal while

    profile #1 can be multimodal. If set to "None" or [], all profiles can be multimodal.

  • unimodConcMod (str, default “strict”) – When set to "strict", values deviating from unimodality are reset to the value of the previous point. When set to "smooth", both values (deviating point and previous point) are modified to avoid =”steps” in the concentration profile.

  • unimodTol (float, default 1.1) – Tolerance parameter for unimodality. Correction is applied only if: `C[i,j] > C[i-1,j] * unimodTol` on the decreasing branch of profile #j, `C[i,j] < C[i-1,j] * unimodTol` on the increasing branch of profile #j.

  • monoDecConc (None or array of indexes) – Monotonic decrease constraint on concentrations. If set to None (default) or [] no constraint is applied. If an array of indexes is passed, the corresponding profiles are considered do decrease monotonically, not

    the others. For instance [0, 2] indicates that profile #0 and #2 are decreasing while profile #1 can increase.

  • monoDecTol (float, default 1.1) – Tolerance parameter for monotonic decrease. Correction is applied only if: `C[i,j] > C[i-1,j] * unimodTol` along profile #j.

  • monoIncConc (None or array of indexes) – Monotonic increase constraint on concentrations. If set to None (default) or [] no constraint is applied. If an array of indexes is passed, the corresponding profiles are considered to increase monotonically, not

    the others. For instance [0, 2] indicates that profile #0 and #2 are increasing while profile #1 can decrease.

  • monoIncTol (float, default 1.1) – Tolerance parameter for monotonic decrease. Correction is applied only if: `C[i,j] < C[i-1,j] * unimodTol` along profile #j.

  • closureConc (None or array of indexes, default None) – Defines the concentration profiles subjected to closure constraint. If set to None or [], no constraint is applied. If an array of indexes is passed, the corresponding profile will be constrained so that their weighted sum equals the closureTarget.

  • closureTarget (str or array of float, default "default") – The value of the sum of concentrations profiles subjected to closure. If set to default, the total concentration is set to 1.0 for all observations. If an array is passed: the values of concentration for each observation. Hence,`np.ones[X.shape[0]` would be equivalent to “default”.

  • closureMethod (str, "scaling" or "constantSum", default "scaling") – The method used to enforce Closure. “scaling” recompute the concentration profiles using linear algebra: ``` C.data[:, closureConc] = np.dot(C.data[:, closureConc],

    np.diag(np.linalg.lstsq(C.data[:, closureConc], closureTarget.T, rcond=None)[0]))

    ``` “constantSum”` normalize the sum of concentration profiles to closureTarget.

  • hardConc (None or or array of indexes, default None) – Defines hard constraints obn the concentration profiles. If set to None or [], no constraint is applied. If an array of indexes is passed, the corresponding profiles will set by getC (see below).

  • getC (Callable) – An external function that will provide len(hardConc) concentration profiles: ` getC(Ccurr, *argsGetC, **kwargsGetC) -> hardC ` or: ` getC(Ccurr, *argsGetC, **kwargsGetC) -> hardC, newArgsGetC ` or: ` getC(Ccurr, *argsGetCn, **kargsGetC) -> hardC, newArgsGetC, extOutput ` where Ccurr is the current C martrix, *argsGetC are the parameters needed to completely specify the function. hardC is a nadarray or NDDataset of shape (C.y, len(hardConc), newArgsGetC are the updated parameters for the next iteration (can be None), and extOutput can be any relevant output to be kept in extOutput attribute (only the last iteration extOutput is kept)

  • argsGetConc (tuple, optional) – supplementary positional arguments passed to the external function.

  • kwargsGetConc (tuple, optional) – supplementary keyword arguments passed to the external function

  • hardC_to_C_idx (None or list or tuple, default None) – Indicates the correspondence between the indexes of the columns of hardC and of the C matrix. [1, None, 0] indicates that the first profile in hardC (index O) corrsponds to the second profile of C (index 1).

  • nonnegSpec (str, list or tuple or None, default "all") – Indicates non-negative spectral profile. If set to 'all' (default) all spectral profiles are considered non-negative. If an array of indexes is passed, the corresponding profiles are considered non-negative, not the others. For instance [0, 2] indicates that profile #0 and #2 are non-negative while profile #1 can be negative. If set to None or [], all profiles can be negative.

  • normSpec (None or str, default None) – Defines whether the spectral profiles should be normalized. If set to None no normalization is applied.

    when set to “euclid”, spectra are normalized with respect to their total area, when set to “max”, spectra are normalized with respect to the maximum af their value.

    unimodSpecstr or array of indexes, default None

    Unimodality constraint on Spectra. If set to None (default) none of spectral profiles is considered unimodal. If an array of indexes is passed, the corresponding profiles are considered unimodal, not the others. For instance [0, 2] indicates that profile #0 and #2 are unimodal while profile #1 can be multimodal. If set to "None" or [], all profiles can be multimodal.

  • unimodSpecMod (str, default “strict”) – When set to "strict", values deviating from unimodality are reset to the value of the previous point. When set to "smooth", both values (deviating point and previous point) are modified to avoid =”steps” in the concentration profile.

  • unimodSpecTol (float, default 1.1) – Tolerance parameter for unimodality. Correction is applied only if the deviating point is larger/lower than `St[j,i] > St[j, i-1] * unimodSpecTol` on the decreasing branch of profile #j, `St[j,i] < St[j, i-1] * unimodTol` on the increasing branch of profile #j.

See also

PCA

Performs MCR-ALS of a NDDataset knowing the initial C or St matrix.

NNMF

Performs a Non Negative Matrix Factorization of a NDDataset .

EFA

Perform an Evolving Factor Analysis (forward and reverse) of the input NDDataset .

Examples

>>> data = scp.read("matlabdata/als2004dataset.MAT")
>>> X, guess = data[-1], data[3]
>>> mcr = scp.MCRALS(X, guess)
>>> mcr.St, mcr.St
(NDDataset: [float64] unitless (shape: (y:4, x:96)), NDDataset: [float64] unitless (shape: (y:4, x:96)))

Methods

MCRALS.plotmerit(**kwargs)

Plots the input dataset, reconstructed dataset and residuals.

MCRALS.reconstruct()

Transform data back to the original space.

Attributes

MCRALS.C

The final concentration profiles.

MCRALS.Chard

The hard concentration profiles.

MCRALS.St

The final spectra profiles.

MCRALS.Stsoft

The soft spectra profiles.

MCRALS.X

The original dataset.

MCRALS.extOutput

The last output of the external function used to get concentrations.

MCRALS.log

Logs output.

MCRALS.params

The parameters used to perform the MCR als.

C

The final concentration profiles.

Chard

The hard concentration profiles.

St

The final spectra profiles.

Stsoft

The soft spectra profiles.

X

The original dataset.

extOutput

The last output of the external function used to get concentrations.

log

Logs output.

params

The parameters used to perform the MCR als.

Examples using spectrochempy.MCRALS

MCR-ALS optimization example (original example from Jaumot)

MCR-ALS optimization example (original example from Jaumot)