Retrieve Mathematical Form of Fit Model?

23 views
Skip to first unread message

Heinz Heinz

unread,
Nov 25, 2019, 5:06:01 AM11/25/19
to lmfit-py
Hello everyone,

hopefully this problem has a trivial solution:
Is there a way to retrieve the mathematical model from a composite model?

For example, let's assume I fitted some spectroscopic data with a composite model
consisting of a linear background (LinearModel) and several gaussian peaks (GaussianModel).

Is it then possible to somehow return the model, not as an lmfit.Model, but as a "real" mathematical
model, i.e. model = a*x +b + amplitude*Exp(-(x-mu)^2/ sigma^2) + ...
where the parameters are replaced by the fitted parameters?

Best regards and thanks for the help,
Felix

Matt Newville

unread,
Nov 25, 2019, 7:42:39 AM11/25/19
to lmfit-py
I don't know what '"real" mathematical model' means to you, but I think it is not possible to return a simple textual expression for any Model.  Well, unless you consider (as perhaps you should) the text of the Python function (or perhaps the AST representation of that text) to be a real mathematical representation of the function. Of course, a model function is not a single expression but a Python function that can be arbitrarily complex.  Being Python code, the function really only makes sense in the context of a Python interpreter.  That is, 'a*x+b' is a sequence of 5 characters, and anything else is interpretation.

--Matt 

Reply all
Reply to author
Forward
0 new messages