spectrochempy.analysis.constraints.ModelProfile๏ƒ

class ModelProfile(profile, components=None, model=None, model_args=None, model_kwargs=None, mapping=None, blocks=None)[source]๏ƒ

Profile generator constraint.

States that a profile must lie in the family of profiles generated by a user-supplied model. The model is a callable fitted at each ALS iteration on the current least-squares profile and used to regenerate the constrained profile. This generalises the historical getConc and getSpec mechanisms of MCRALS.

Mapping semantics

The optional mapping parameter controls how model output columns (for profile="C") or rows (for profile="St") are assigned to ALS components.

The direction is from ALS components to model outputs:

components=[c0, c1, c2]

mapping=[m0, m1, m2]

means:

ALS component c0  <-  model output m0
ALS component c1  <-  model output m1
ALS component c2  <-  model output m2

A None entry leaves the component unchanged (the ALS estimate is kept). If mapping is None (the default), model outputs are assigned in order: component c_i receives model output i.

The mapping parameter is primarily intended for models whose output ordering differs from the ALS component ordering, or when only a subset of ALS components is generated by the model.

Duplicate indices are allowed โ€” multiple components can reference the same model output column/row.

Parameters
  • profile (str) โ€“ Must be "C" (concentrations) or "St" (spectra).

  • components (list[int], optional) โ€“ Component indices to which the model applies. None (default) means โ€œall componentsโ€.

  • model (callable) โ€“ A callable that, given the current ALS profile for the selected side ("C" or "St"), returns the model-constrained profile. Validation is limited to checking that it is callable; signature enforcement is deferred to the enforcement engine.

  • model_args (tuple or list, optional) โ€“ Extra positional arguments passed to the model after the current ALS profile. Defaults to ().

  • model_kwargs (dict or None, optional) โ€“ Extra keyword arguments passed to the model. Defaults to None.

  • mapping (list or None, optional) โ€“ Mapping from ALS components to model output columns/rows. mapping[i] selects which column (for profile="C") or row (for profile="St") of the model output is assigned to components[i]. None entries keep the ALS estimate. None (the default) means identity: components receive model outputs in order. Duplicate indices are allowed.

Examples

>>> from spectrochempy import ModelProfile
>>> def my_model(C):
...     return C
>>> ModelProfile("C", components=[0, 1], model=my_model)
ModelProfile(profile='C', components=[0, 1], model=<function my_model at ...>)
>>> ModelProfile("St", components=[0], model=my_model)
ModelProfile(profile='St', components=[0], model=<function my_model at ...>)

With a swap mapping:

# Model returns [col_for_1, col_for_0]; swap them back.
ModelProfile(
    "C",
    components=[0, 1],
    mapping=[1, 0],
    model=my_model,
)
# ALS component 0  <-  model output 1
# ALS component 1  <-  model output 0

With None entries:

ModelProfile(
    "C",
    components=[0, 1, 2],
    mapping=[2, None, 0],
    model=my_model,
)
# ALS component 0  <-  model output 2
# ALS component 1  <-  unchanged (keeps ALS estimate)
# ALS component 2  <-  model output 0

Attributes Summary

blocks

Block indices for augmented data (None means all blocks).

components

Component selection (None means "all").

mapping

Profile mapping from ALS components to model output columns/rows.

model

Model callable used to regenerate the constrained profile.

model_args

Extra positional arguments for the model.

model_kwargs

Extra keyword arguments for the model.

name

Short human-readable name of the constraint family.

profile

Canonical profile identifier ("C" or "St").

Attributes Documentation

blocks๏ƒ

Block indices for augmented data (None means all blocks).

Type

list[int] or None

components๏ƒ

Component selection (None means โ€œallโ€).

Type

list[int] or None

mapping๏ƒ

Profile mapping from ALS components to model output columns/rows.

Type

List or None

model๏ƒ

Model callable used to regenerate the constrained profile.

Type

callable

model_args๏ƒ

Extra positional arguments for the model.

Type

tuple

model_kwargs๏ƒ

Extra keyword arguments for the model.

Type

dict

name๏ƒ

Short human-readable name of the constraint family.

Type

str

profile๏ƒ

Canonical profile identifier ("C" or "St").

Type

str

Examples using spectrochempy.analysis.constraints.ModelProfile

MCR-ALS with kinetic constraints

MCR-ALS with kinetic constraints