autoemx.core.fitter.fast_model_eval module

Faster evaluation of lmfit composite models.

The spectrum model is a CompositeModel with many components (one per X-ray peak plus the background factors). On every evaluation, lmfit’s Model.make_funcargs rebuilds the arguments of each component by scanning all parameters, which dominates the cost of a model evaluation.

FastCompositeModel builds the mapping from parameters to each component’s function arguments once per set of parameter names, following the same precedence rules as Model.make_funcargs, and then evaluates the same component functions, combined with the same operators. Results are therefore identical to CompositeModel.eval.

Main Class:
  • FastCompositeModel: CompositeModel with cached argument mapping in eval()

class autoemx.core.fitter.fast_model_eval.FastCompositeModel(left, right, op, **kws)[source]

Bases: CompositeModel

CompositeModel whose eval() reuses a precomputed parameter-to-argument mapping.

Only eval() is changed. eval_components(), components, param_names and fitting behave as in CompositeModel. Calls that lmfit handles specially (keyword arguments overriding parameter values, or params not given as a Parameters object) fall back to CompositeModel.eval.

eval(params=None, **kwargs)[source]

Evaluate the model with the supplied parameters (see lmfit CompositeModel.eval).

autoemx.core.fitter.fast_model_eval.with_fast_eval(model)[source]

Return model as a FastCompositeModel if it is a CompositeModel, else unchanged.