How to convert fit into a function

37 views
Skip to first unread message

Brenden Hawk

unread,
Dec 4, 2024, 3:00:02 PM12/4/24
to lmfit-py
Hello all,

I am trying to use a fit of my data to generate more data points. I have an instrument with a limited read rate, and I would like to estimate points between reads.

Is there a built-in function in the fit output that I can feed a np.linspace into to get estimated y values?

Thanks for the help,
Brenden

Brenden Hawk

unread,
Dec 4, 2024, 3:46:27 PM12/4/24
to lmfit-py
I think that I found that the split lorentzian model gives the best fit:
Figure 2024-12-04 144503.png
x =
3.116667000000000076e+00
3.133332999999999924e+00
3.149999999999999911e+00
3.166666999999999899e+00
3.183333000000000190e+00
3.200000000000000178e+00
3.216667000000000165e+00
3.233333000000000013e+00
3.250000000000000000e+00
3.266666999999999987e+00
3.283332999999999835e+00
3.299999999999999822e+00
3.316666999999999810e+00
3.333333000000000101e+00
3.350000000000000089e+00
3.366667000000000076e+00
3.383332999999999924e+00
3.399999999999999911e+00
3.416666999999999899e+00
3.433333000000000190e+00
3.450000000000000178e+00
3.466667000000000165e+00
3.483333000000000013e+00
3.500000000000000000e+00
3.516666999999999987e+00
3.533332999999999835e+00
3.549999999999999822e+00
3.566666999999999810e+00
3.583333000000000101e+00
3.600000000000000089e+00
3.616667000000000076e+00
3.633332999999999924e+00

y = 
7.880480981113159089e+00
7.918671516560074508e+00
9.385572179364208623e+00
1.851946784216834629e+01
5.663187437761525445e+01
1.574181300404193848e+02
3.089728857032235396e+02
4.202220422386704399e+02
4.142640979014745994e+02
3.169517535642787038e+02
2.069587100997256357e+02
1.300115657625297558e+02
8.751943142533390585e+01
6.606347796078081558e+01
5.449620362358494674e+01
4.707833928638908816e+01
4.165168582183599710e+01
3.680999148464013615e+01
3.225052714744426652e+01
2.827309368289118652e+01
2.454272934569532438e+01
2.148618500849945789e+01
1.915621154394637315e+01
1.679010720675050905e+01
1.436541286955464436e+01
1.224343940500155803e+01
1.078260506780569372e+01
9.649900730609829225e+00
8.689067266056744288e+00
7.898156928860879056e+00
7.200018591665015677e+00
6.358327127111929045e+00

Jeremy DeJournett

unread,
Dec 4, 2024, 11:09:12 PM12/4/24
to lmfi...@googlegroups.com
For more generic curves (the ones that aren't standard in the library), I can recommend spline interpolation, in particular pchip splines do a great jobs at capturing the data without being *too* creative with the interpolation (avoids the wild swings sometimes present in cubic splines)

Good luck!

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lmfit-py/77610f8f-55e8-4afc-b96c-a7a90650445dn%40googlegroups.com.

Matt Newville

unread,
Dec 4, 2024, 11:23:11 PM12/4/24
to lmfi...@googlegroups.com
Hi Brenden,

It is always helpful to provide some example code showing what you are doing, or trying to do. 

If you do a fit with lmfit.Model.fit(), then the returned ModelResult will have an `eval()` method.  You can pass any values for  `x` (or other independent parameters) you like to get predicted values for the model with the best-fit parameter values.

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.

Brenden Hawk

unread,
Dec 5, 2024, 2:29:33 PM12/5/24
to lmfi...@googlegroups.com
You are awesome!! That is exactly what I needed!! Thanks so much!

Geoffrey Lewen

unread,
Dec 5, 2024, 2:29:50 PM12/5/24
to lmfi...@googlegroups.com

Brenden Hawk

unread,
Dec 10, 2024, 12:23:55 AM12/10/24
to lmfi...@googlegroups.com
Thank you so much. That is exactly what I needed :-)

Reply all
Reply to author
Forward
0 new messages