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
getConcandgetSpecmechanisms ofMCRALS.Mapping semantics
The optional
mappingparameter controls how model output columns (forprofile="C") or rows (forprofile="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
Noneentry leaves the component unchanged (the ALS estimate is kept). IfmappingisNone(the default), model outputs are assigned in order: componentc_ireceives model outputi.The
mappingparameter 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 (forprofile="C") or row (forprofile="St") of the model output is assigned tocomponents[i].Noneentries 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
Noneentries: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
Block indices for augmented data (
Nonemeans all blocks).Component selection (
Nonemeans "all").Profile mapping from ALS components to model output columns/rows.
Model callable used to regenerate the constrained profile.
Extra positional arguments for the model.
Extra keyword arguments for the model.
Short human-readable name of the constraint family.
Canonical profile identifier (
"C"or"St").Attributes Documentation
- 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
Examples using spectrochempy.analysis.constraints.ModelProfile