spectrochempy.MCRALS

class MCRALS(*args, log_level=30, warm_start=False, argsGetConc, argsGetSpec, closureConc=[], closureMethod='scaling', closureTarget='default', getC_to_C_idx='default', getConc=None, getSpec=None, getSt_to_St_idx='default', hardConc, hardSpec, kwargsGetConc, kwargsGetSpec, max_iter=50, maxdiv=5, monoDecConc, monoDecTol=1.1, monoIncConc, monoIncTol=1.1, nonnegConc='all', nonnegSpec='all', normSpec=None, solverConc='lstsq', solverSpec='lstsq', storeIterations=False, tol=0.1, unimodConc='all', unimodConcMod='strict', unimodConcTol=1.1, unimodSpec=[], unimodSpecMod='strict', unimodSpecTol=1.1)[source]

Multivariate Curve Resolution Alternating Least Squares (MCRALS).

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 \(S^t\) of β€œpure” species and their concentration profiles \(C\).

In terms of matrix equation:

\[X = C.S^t + E\]

where \(E\) is the matrix of residuals.

Parameters:
  • log_level (any of ["INFO", "DEBUG", "WARNING", "ERROR"], optional, default: "WARNING") – The log level at startup. It can be changed later on using the set_log_level method or by changing the log_level attribute.

  • warm_start (bool, optional, default: False) – When fitting repeatedly on the same dataset, but for multiple parameter values (such as to find the value maximizing performance), it may be possible to reuse previous model learned from the previous parameter value, saving time.

    When warm_start is True, the existing fitted model attributes is used to initialize the new model in a subsequent call to fit.

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

  • argsGetSpec (tuple, optional, default: ()) – Supplementary positional arguments passed to the external function.

  • closureConc (any of [β€˜all’] or a list, optional, default: []) – Defines the concentration profiles subjected to closure constraint.

    • []: no constraint is applied.

    • 'all': all profile are constrained so that their weighted sum equals the closureTarget

    • list of indexes: the corresponding profiles are constrained so that their weighted sum equals closureTarget.

  • closureMethod (any value of [ 'scaling' , 'constantSum' ], optional, default: 'scaling') – The method used to enforce closure (Omidikia et al. [2018]).

    • 'scaling' recompute the concentration profiles using least squares:

      \[C \leftarrow C \cdot \textrm{diag} \left( C_L^{-1} c_t \right)\]

      where \(c_t\) is the vector given by closureTarget and \(C_L^{-1}\) is the left inverse of \(C\).

    • 'constantSum' normalize the sum of concentration profiles to closureTarget.

  • closureTarget (any of [β€˜default’] or a numpy array, optional, default: 'default') – The value of the sum of concentrations profiles subjected to closure.

    • 'default': the total concentration is set to 1.0 for all observations.

    • array-like of size n_observations: the values of concentration for each observation. Hence, np.ones(X.shape[0]) would be equivalent to 'default'.

  • getC_to_C_idx (any of [β€˜default’] or a list, optional, default: 'default') – Correspondence of the profiles returned by getConc and C[:,hardConc].

    • 'default': the profiles correspond to those of C[:,hardConc]. This is equivalent to range(len(hardConc))

    • list of indexes or of None. For instance [2, 1, 0] indicates that the third profile returned by getC (index 2) corresponds to the 1st profile of C[:, hardConc], the 2nd returned profile (index 1) corresponds to second profile of C[:, hardConc], etc…

  • getConc (a callable or a unicode string, optional, default: None) – An external function that provide len(hardConc) concentration profiles.

    It should be using one of the following syntax:

    • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC

    • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc

    • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc, extraOutputGetConc

    where:

    • Ccurr is the current C dataset,

    • argsGetConc are the parameters needed to completely specify the function.

    • hardC is a ndarray or NDDataset of shape (n_observations , len(hardConc),

    • newArgsGetConc are the updated parameters for the next iteration (can be None),

    • extraOutputGetConc can be any other relevant output to be kept in extraOutputGetConc attribute, a list of extraOutputGetConc at each MCR ALS iteration.

    Note

    getConc can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.

  • getSpec (a callable or a unicode string, optional, default: None) – An external function that will provide len(hardSpec) concentration profiles.

    It should be using one of the following syntax:

    • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt

    • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec

    • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec, extraOutputGetSpec

    with:

    • Stcurr: the current value of St in the ALS loop,

    • *argsGetSpec and **kwargsGetSpec: the parameters needed to completely specify the function.

    • hardSt: ndarray or NDDataset of shape (n_observations, len(hardSpec),

    • newArgsGetSpec: updated parameters for the next ALS iteration (can be None),

    • extraOutputGetSpec: any other relevant output to be kept in extraOutputGetSpec attribute, a list of extraOutputGetSpec at each iterations.

    Note

    getSpec can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.

  • getSt_to_St_idx (any of [β€˜default’] or a list, optional, default: 'default') – Correspondence between the indexes of the spectra returned by getSpec and St.

    • 'default': the indexes correspond to those of St. This is equivalent to range(len(hardSpec)).

    • list of indexes : corresponding indexes in St, i.e. [2, None, 0] indicates that the first returned profile corresponds to the third St profile (index 2), the 2nd returned profile does not correspond to any profile in St, the 3rd returned profile corresponds to the first St profile (index 0 ).

  • hardConc (list, optional, default: []) – Defines hard constraints on the concentration profiles.

    • []: no constraint is applied.

    • list of indexes: the corresponding profiles will set by getConc.

  • hardSpec (list, optional, default: []) – Defines hard constraints on the spectral profiles.

    • []: no constraint is applied.

    • list of indexes : the corresponding profiles will set by getSpec.

  • kwargsGetConc (dict, optional, default: {}) – Supplementary keyword arguments passed to the external function.

  • kwargsGetSpec (dict, optional, default: {}) – Supplementary keyword arguments passed to the external function.

  • max_iter (int, optional, default: 50) – Maximum number of ALS iteration.

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

  • monoDecConc (list, optional, default: []) – Monotonic decrease constraint on concentrations.

    • []: no constraint is applied.

    • list of indexes: the corresponding profiles are considered to decrease monotonically, not the others. For instance [0, 2] indicates that profile #0 and #2 are decreasing while profile #1 can increase.

  • monoDecTol (float, optional, default: 1.1) – Tolerance parameter for monotonic decrease.

    Correction is applied only if: C[i,j] > C[i-1,j] * unimodTol .

  • monoIncConc (list, optional, default: []) – Monotonic increase constraint on concentrations.

    • []: no constraint is applied.

    • list of indexes: 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, optional, default: 1.1) – Tolerance parameter for monotonic decrease.

    Correction is applied only if C[i,j] < C[i-1,j] * unimodTol along profile #j.

  • nonnegConc (any of [β€˜all’] or a list, optional, default: 'all') – Non-negativity constraint on concentrations.

    • 'all': all concentrations profiles are considered non-negative.

    • list of indexes: 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.

    • []: all profiles can be negative.

  • nonnegSpec (any of [β€˜all’] or a list, optional, default: 'all') – Non-negativity constraint on spectra.

    • 'all': all profiles are considered non-negative.

    • list of indexes : 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.

    • []: all profiles can be negative.

  • normSpec (any value of [ 'None' , 'euclid' , 'max' ], optional, default: None) – Defines whether the spectral profiles should be normalized.

    • None: no normalization is applied.

    • 'euclid': spectra are normalized with respect to their total area,

    • 'max': spectra are normalized with respect to their maximum value.

  • solverConc (any value of [ 'lstsq' , 'nnls' , 'pnnls' ], optional, default: 'lstsq') – Solver used to get C from X and St.

    • 'lstsq': uses ordinary least squares with lstsq

    • 'nnls': non-negative least squares (nnls) are applied sequentially on all profiles

    • 'pnnls': non-negative least squares (nnls) are applied on profiles indicated in nonnegConc and ordinary least squares on other profiles.

  • solverSpec (any value of [ 'lstsq' , 'nnls' , 'pnnls' ], optional, default: 'lstsq') – Solver used to get St from X and C.

    • 'lstsq': uses ordinary least squares with lstsq

    • 'nnls': non-negative least squares (nnls) are applied sequentially on all profiles

    • 'pnnls': non-negative least squares (nnls) are applied on profiles indicated in nonnegConc and ordinary least squares on other profiles.

  • storeIterations (bool, optional, default: False) – Whether to store the C and St generated at each iteration.

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

  • unimodConc (any of [β€˜all’] or a list, optional, default: 'all') – Unimodality constraint on concentrations.

    • 'all': all concentrations profiles are considered unimodal.

    • list of indexes: 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.

    • []: all profiles can be multimodal.

  • unimodConcMod (any value of [ 'strict' , 'smooth' ], optional, default: 'strict') – Method to apply unimodality.

    • 'strict': values deviating from unimodality are reset to the value of the previous point.

    • 'smooth': both values (deviating point and previous point) are modified to avoid steps in the concentration profile.

  • unimodConcTol (float, optional, 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.

  • unimodSpec (any of [β€˜all’] or a list, optional, default: []) – Unimodality constraint on Spectra.

    • []: all profiles can be multimodal.

    • 'all': all profiles are unimodal (equivalent to range(n_components)).

    • array of indexes : 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.

  • unimodSpecMod (any value of [ 'strict' , 'smooth' ], optional, default: 'strict') – Method used to apply unimodality.

    • 'strict': values deviating from unimodality are reset to the value of the previous point.

    • 'smooth': both values (deviating point and previous point) are modified to avoid steps in the concentration profile.

  • unimodSpecTol (float, optional, default: 1.1) – Tolerance parameter for unimodality.

    Correction is applied only if the deviating point St[j, i] is larger than St[j, i-1] * unimodSpecTol on the decreasing branch of profile #j, or lower than St[j, i-1] * unimodTol on the increasing branch of profile #j.

See also

EFA

Perform an Evolving Factor Analysis (forward and reverse).

FastICA

Perform Independent Component Analysis with a fast algorithm.

IRIS

Integral inversion solver for spectroscopic data.

NMF

Non-Negative Matrix Factorization.

PCA

Perform Principal Components Analysis.

SIMPLISMA

SIMPLe to use Interactive Self-modeling Mixture Analysis.

SVD

Perform a Singular Value Decomposition.

Initialize the BaseConfigurable class.

Parameters:
  • log_level (int, optional) – The log level at startup. Default is logging.WARNING.

  • **kwargs (dict) – Additional keyword arguments for configuration.

Attributes Summary

C

The final concentration profiles.

C_constrained

The last constrained concentration profiles, i.e. after applying the hard and soft constraints.

C_constrained_list

The list of constrained concentration profiles at each ALS iteration.

C_ls_list

The list of concentration profiles obtained by least square optimization and scaling at each ALS iteration.

S_soft

Deprecated.

St

The final spectra profiles.

St_constrained_list

The list of constrained spectral profiles at each ALS iteration.

St_ls

The last spectral profiles obtained by least-square optimization, before constraints.

St_ls_list

The list of optimized spectral profiles at each ALS iteration.

St_unconstrained

Deprecated.

X

Return the X input dataset (eventually modified by the model).

Y

The Y input.

argsGetConc

Supplementary positional arguments passed to the external function.

argsGetSpec

Supplementary positional arguments passed to the external function.

closureConc

Defines the concentration profiles subjected to closure constraint.

closureMethod

The method used to enforce closure (Omidikia et al. [2018]).

closureTarget

The value of the sum of concentrations profiles subjected to closure.

components

NDDataset with components in feature space (n_components, n_features).

config

traitlets.config.Config object.

extraOutputGetConc

The extra outputs of the external function used to get concentrations.

extraOutputGetSpec

The extra outputs of the external function used to get spectra.

getC_to_C_idx

Correspondence of the profiles returned by getConc and C[:,hardConc].

getConc

An external function that provide len(hardConc) concentration profiles.

getSpec

An external function that will provide len(hardSpec) concentration profiles.

getSt_to_St_idx

Correspondence between the indexes of the spectra returned by getSpec and St.

hardConc

Defines hard constraints on the concentration profiles.

hardSpec

Defines hard constraints on the spectral profiles.

kwargsGetConc

Supplementary keyword arguments passed to the external function.

kwargsGetSpec

Supplementary keyword arguments passed to the external function.

log

Return log output.

max_iter

Maximum number of ALS iteration.

maxdiv

Maximum number of successive non-converging iterations.

monoDecConc

Monotonic decrease constraint on concentrations.

monoDecTol

Tolerance parameter for monotonic decrease.

monoIncConc

Monotonic increase constraint on concentrations.

monoIncTol

Tolerance parameter for monotonic decrease.

n_components

Number of components that were fitted.

name

Object name

nonnegConc

Non-negativity constraint on concentrations.

nonnegSpec

Non-negativity constraint on spectra.

normSpec

Defines whether the spectral profiles should be normalized.

solverConc

Solver used to get C from X and St.

solverSpec

Solver used to get St from X and C.

storeIterations

Whether to store the C and St generated at each iteration.

tol

Convergence criterion on the change of residuals (percent change of standard deviation of residuals).

unimodConc

Unimodality constraint on concentrations.

unimodConcMod

Method to apply unimodality.

unimodConcTol

Tolerance parameter for unimodality.

unimodSpec

Unimodality constraint on Spectra.

unimodSpecMod

Method used to apply unimodality.

unimodSpecTol

Tolerance parameter for unimodality.

Methods Summary

fit(X,Β Y)

Fit the MCRALS model on an X dataset using initial concentration or spectra.

fit_transform(X,Β Y,Β **kwargs)

Fit the model with X and apply the dimensionality reduction on X.

get_components([n_components])

Return the component's dataset: (selected n_components, n_features).

inverse_transform([X_transform])

Transform data back to its original space.

parameters([replace,Β removed,Β default])

Alias for params method.

params([default])

Return current or default configuration values.

plotmerit([X,Β X_hat])

Plot the input (X), reconstructed (X_hat) and residuals.

reconstruct([X_transform])

Transform data back to its original space.

reduce([X])

Apply dimensionality reduction to X.

reset()

Reset configuration parameters to their default values.

to_dict()

Return config value in a dict form.

transform([X])

Apply dimensionality reduction to X.

Attributes Documentation

C

The final concentration profiles.

C_constrained

The last constrained concentration profiles, i.e. after applying the hard and soft constraints.

C_constrained_list

The list of constrained concentration profiles at each ALS iteration.

Requires MCRALS.storeIterations set to True.

C_ls_list

The list of concentration profiles obtained by least square optimization and scaling at each ALS iteration.

Requires MCRALS.storeIterations set to True.

S_soft

Deprecated. Equivalent to St_ls.

St

The final spectra profiles.

St_constrained_list

The list of constrained spectral profiles at each ALS iteration.

Requires MCRALS.storeIterations set to True.

St_ls

The last spectral profiles obtained by least-square optimization, before constraints.

Spectra obtained after solving \(C_{\textrm{constrained}} \cdot St = X\) for \(St\).

St_ls_list

The list of optimized spectral profiles at each ALS iteration.

Requires MCRALS.storeIterations set to True.

St_unconstrained

Deprecated. Equivalent to St_ls.

X

Return the X input dataset (eventually modified by the model).

Y

The Y input.

argsGetConc

Supplementary positional arguments passed to the external function.

argsGetSpec

Supplementary positional arguments passed to the external function.

closureConc

Defines the concentration profiles subjected to closure constraint.

  • []: no constraint is applied.

  • 'all': all profile are constrained so that their weighted sum equals the closureTarget

  • list of indexes: the corresponding profiles are constrained so that their weighted sum equals closureTarget.

closureMethod

The method used to enforce closure (Omidikia et al. [2018]).

  • 'scaling' recompute the concentration profiles using least squares:

    \[C \leftarrow C \cdot \textrm{diag} \left( C_L^{-1} c_t \right)\]

    where \(c_t\) is the vector given by closureTarget and \(C_L^{-1}\) is the left inverse of \(C\).

  • 'constantSum' normalize the sum of concentration profiles to closureTarget.

closureTarget

The value of the sum of concentrations profiles subjected to closure.

  • 'default': the total concentration is set to 1.0 for all observations.

  • array-like of size n_observations: the values of concentration for each observation. Hence, np.ones(X.shape[0]) would be equivalent to 'default'.

components

NDDataset with components in feature space (n_components, n_features).

See also

get_components

Retrieve only the specified number of components.

config

traitlets.config.Config object.

extraOutputGetConc

The extra outputs of the external function used to get concentrations.

extraOutputGetSpec

The extra outputs of the external function used to get spectra.

getC_to_C_idx

Correspondence of the profiles returned by getConc and C[:,hardConc].

  • 'default': the profiles correspond to those of C[:,hardConc]. This is equivalent to range(len(hardConc))

  • list of indexes or of None. For instance [2, 1, 0] indicates that the third profile returned by getC (index 2) corresponds to the 1st profile of C[:, hardConc], the 2nd returned profile (index 1) corresponds to second profile of C[:, hardConc], etc…

getConc

An external function that provide len(hardConc) concentration profiles.

It should be using one of the following syntax:

  • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC

  • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc

  • getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc, extraOutputGetConc

where:

  • Ccurr is the current C dataset,

  • argsGetConc are the parameters needed to completely specify the function.

  • hardC is a ndarray or NDDataset of shape (n_observations , len(hardConc),

  • newArgsGetConc are the updated parameters for the next iteration (can be None),

  • extraOutputGetConc can be any other relevant output to be kept in extraOutputGetConc attribute, a list of extraOutputGetConc at each MCR ALS iteration.

Note

getConc can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.

getSpec

An external function that will provide len(hardSpec) concentration profiles.

It should be using one of the following syntax:

  • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt

  • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec

  • getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec, extraOutputGetSpec

with:

  • Stcurr: the current value of St in the ALS loop,

  • *argsGetSpec and **kwargsGetSpec: the parameters needed to completely specify the function.

  • hardSt: ndarray or NDDataset of shape (n_observations, len(hardSpec),

  • newArgsGetSpec: updated parameters for the next ALS iteration (can be None),

  • extraOutputGetSpec: any other relevant output to be kept in extraOutputGetSpec attribute, a list of extraOutputGetSpec at each iterations.

Note

getSpec can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.

getSt_to_St_idx

Correspondence between the indexes of the spectra returned by getSpec and St.

  • 'default': the indexes correspond to those of St. This is equivalent to range(len(hardSpec)).

  • list of indexes : corresponding indexes in St, i.e. [2, None, 0] indicates that the first returned profile corresponds to the third St profile (index 2), the 2nd returned profile does not correspond to any profile in St, the 3rd returned profile corresponds to the first St profile (index 0 ).

hardConc

Defines hard constraints on the concentration profiles.

  • []: no constraint is applied.

  • list of indexes: the corresponding profiles will set by getConc.

hardSpec

Defines hard constraints on the spectral profiles.

  • []: no constraint is applied.

  • list of indexes : the corresponding profiles will set by getSpec.

kwargsGetConc

Supplementary keyword arguments passed to the external function.

kwargsGetSpec

Supplementary keyword arguments passed to the external function.

log

Return log output.

max_iter

Maximum number of ALS iteration.

maxdiv

Maximum number of successive non-converging iterations.

monoDecConc

Monotonic decrease constraint on concentrations.

  • []: no constraint is applied.

  • list of indexes: the corresponding profiles are considered to decrease monotonically, not the others. For instance [0, 2] indicates that profile #0 and #2 are decreasing while profile #1 can increase.

monoDecTol

Tolerance parameter for monotonic decrease.

Correction is applied only if: C[i,j] > C[i-1,j] * unimodTol .

monoIncConc

Monotonic increase constraint on concentrations.

  • []: no constraint is applied.

  • list of indexes: 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

Tolerance parameter for monotonic decrease.

Correction is applied only if C[i,j] < C[i-1,j] * unimodTol along profile #j.

n_components

Number of components that were fitted.

name

Object name

nonnegConc

Non-negativity constraint on concentrations.

  • 'all': all concentrations profiles are considered non-negative.

  • list of indexes: 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.

  • []: all profiles can be negative.

nonnegSpec

Non-negativity constraint on spectra.

  • 'all': all profiles are considered non-negative.

  • list of indexes : 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.

  • []: all profiles can be negative.

normSpec

Defines whether the spectral profiles should be normalized.

  • None: no normalization is applied.

  • 'euclid': spectra are normalized with respect to their total area,

  • 'max': spectra are normalized with respect to their maximum value.

solverConc

Solver used to get C from X and St.

  • 'lstsq': uses ordinary least squares with lstsq

  • 'nnls': non-negative least squares (nnls) are applied sequentially on all profiles

  • 'pnnls': non-negative least squares (nnls) are applied on profiles indicated in nonnegConc and ordinary least squares on other profiles.

solverSpec

Solver used to get St from X and C.

  • 'lstsq': uses ordinary least squares with lstsq

  • 'nnls': non-negative least squares (nnls) are applied sequentially on all profiles

  • 'pnnls': non-negative least squares (nnls) are applied on profiles indicated in nonnegConc and ordinary least squares on other profiles.

storeIterations

Whether to store the C and St generated at each iteration.

tol

Convergence criterion on the change of residuals (percent change of standard deviation of residuals).

unimodConc

Unimodality constraint on concentrations.

  • 'all': all concentrations profiles are considered unimodal.

  • list of indexes: 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.

  • []: all profiles can be multimodal.

unimodConcMod

Method to apply unimodality.

  • 'strict': values deviating from unimodality are reset to the value of the previous point.

  • 'smooth': both values (deviating point and previous point) are modified to avoid steps in the concentration profile.

unimodConcTol

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.

unimodSpec

Unimodality constraint on Spectra.

  • []: all profiles can be multimodal.

  • 'all': all profiles are unimodal (equivalent to range(n_components)).

  • array of indexes : 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.

unimodSpecMod

Method used to apply unimodality.

  • 'strict': values deviating from unimodality are reset to the value of the previous point.

  • 'smooth': both values (deviating point and previous point) are modified to avoid steps in the concentration profile.

unimodSpecTol

Tolerance parameter for unimodality.

Correction is applied only if the deviating point St[j, i] is larger than St[j, i-1] * unimodSpecTol on the decreasing branch of profile #j, or lower than St[j, i-1] * unimodTol on the increasing branch of profile #j.

Methods Documentation

fit(X, Y)[source]

Fit the MCRALS model on an X dataset using initial concentration or spectra.

Parameters:
Returns:

self – The fitted instance itself.

See also

fit_transform

Fit the model with an input dataset X and apply the dimensionality reduction on X.

fit_reduce

Alias of fit_transform (Deprecated).

fit_transform(X, Y, **kwargs)[source]

Fit the model with X and apply the dimensionality reduction on X.

Parameters:
Returns:

NDDataset – Dataset with shape (n_observations, n_components).

Other Parameters:

n_components (int, optional) – The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the fit process.

get_components(n_components=None)

Return the component’s dataset: (selected n_components, n_features).

Parameters:

n_components (int, optional, default: None) – The number of components to keep in the output dataset. If None, all calculated components are returned.

Returns:

NDDataset – Dataset with shape (n_components, n_features)

inverse_transform(X_transform=None, **kwargs)[source]

Transform data back to its original space.

In other words, return an input X_original whose reduce/transform would be X.

Parameters:
  • X_transform (array-like of shape (n_observations, n_components), optional) – Reduced X data, where n_observations is the number of observations and n_components is the number of components. If X_transform is not provided, a transform of X provided in fit is performed first.

  • Y_transform (NDDataset or array-like of shape (n_observations, n_components), optional) – New data, where n_targets is the number of variables to predict. If Y_transform is not provided, a transform of Y provided in fit is performed first.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns:

NDDataset – Dataset with shape (n_observations, n_features).

Other Parameters:

n_components (int, optional) – The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the fit process.

parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]

Alias for params method.

Deprecated since version 0.8.0: Use params instead.

params(default=False)[source]

Return current or default configuration values.

Parameters:

default (bool, optional, default: False) – If default is True, the default parameters are returned, else the current values.

Returns:

dict – Current or default configuration values.

plotmerit(X=None, X_hat=None, **kwargs)[source]

Plot the input (X), reconstructed (X_hat) and residuals.

\(X\) and \(\hat{X}\) can be passed as arguments. If not, the X attribute is used for \(X`and :math:\)hat{X}`is computed by the inverse_transform method

Parameters:
  • X (NDDataset, optional) – Original dataset. If is not provided (default), the X attribute is used and X_hat is computed using inverse_transform.

  • X_hat (NDDataset, optional) – Inverse transformed dataset. if X is provided, X_hat must also be provided as compuyed externally.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns:

Axes – Matplotlib subplot axe.

Other Parameters:
  • colors (tuple or ndarray of 3 colors, optional) – Colors for X , X_hat and residuals E . in the case of 2D, The default colormap is used for X . By default, the three colors are NBlue , NGreen and NRed (which are colorblind friendly).

  • offset (float, optional, default: None) – Specify the separation (in percent) between the \(X\) , \(X_hat\) and \(E\).

  • nb_traces (int or 'all', optional) – Number of lines to display. Default is 'all'.

  • **others (Other keywords parameters) – Parameters passed to the internal plot method of the X dataset.

reconstruct(X_transform=None, **kwargs)[source]

Transform data back to its original space.

In other words, return an input X_original whose reduce/transform would be X_transform.

Parameters:
  • X_transform (array-like of shape (n_observations, n_components), optional) – Reduced X data, where n_observations is the number of observations and n_components is the number of components. If X_transform is not provided, a transform of X provided in fit is performed first.

  • **kwargs (keyword parameters, optional) – See Other Parameters.

Returns:

NDDataset – Dataset with shape (n_observations, n_features).

Other Parameters:

n_components (int, optional) – The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the fit process.

See also

reconstruct

Alias of inverse_transform (Deprecated).

Notes

Deprecated in version 0.6.

reduce(X=None, **kwargs)[source]

Apply dimensionality reduction to X.

Parameters:
Returns:

NDDataset – Dataset with shape (n_observations, n_components).

Other Parameters:

n_components (int, optional) – The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the fit process.

Notes

Deprecated in version 0.6.

reset()[source]

Reset configuration parameters to their default values.

to_dict()[source]

Return config value in a dict form.

Returns:

dict – A regular dictionary.

transform(X=None, **kwargs)

Apply dimensionality reduction to X.

Parameters:
Returns:

NDDataset – Dataset with shape (n_observations, n_components).

Other Parameters:

n_components (int, optional) – The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in the fit process.

Examples using spectrochempy.MCRALS

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS example (adapted from Jaumot et al. 2005)

MCR-ALS with kinetic constraints

MCR-ALS with kinetic constraints