Fit a 2d model with multiple peaks

20 views
Skip to first unread message

melika moradi

unread,
Jun 8, 2024, 7:17:43 AMJun 8
to lmfit-py
Hi, I would like to know how to fit a 2d model with multiple peaks. I have used leastsq and cg methods, but the fit is not good, some parameters are at the initial or the fit is not successful! 


Thank you in advance,
Melika 

Matthew Newville

unread,
Jun 8, 2024, 9:21:33 AMJun 8
to lmfi...@googlegroups.com

Hi Melika,

 

> I would like to know how to fit a 2d model with multiple peaks. I have used leastsq and cg methods, but the fit is not good, some parameters are at the initial or the fit is not successful! 

 

Without some details of what you did, we cannot give much guidance beyond what is already documented, including at places like

https://lmfit.github.io/lmfit-py/faq.html#why-are-parameter-values-sometimes-stuck-at-initial-values

 

We always encourage posting a minimal but complete example. That way, we can better understand what you are doing, and maybe help identify the problem.  The process of simplifying code to an example that others might be able to understand is also a good way to find such problems.

 

--Matt

Laurence Lurio

unread,
Jun 8, 2024, 5:52:17 PMJun 8
to lmfi...@googlegroups.com
I can venture a few suggestions: 

1.  If your initial values for the peak positions are not close , then the peaks will not lock in.  You need to have initial guess values that at least have significant overlap with the positions of the peaks.
2.  If you know your peak widths, try to fix them, or run sequential fits, one with the peak widths fixed to get close to the right parameters, then a second fit with the peak widths varied.  If the peak widths start to diverge to infinity, then the fitting program tends to turn them into "flat lines". 
3.  Keep your background function (assuming you are using one) as simple as possible.  Try to get away with a constant or a simple line.  Alternately, if you need a more complicated background function, run a preliminary fit with a constant or flat line, then follow up with a second fit, once the parameters lock in.

Good luck.

Larry Lurio

--
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 on the web visit https://groups.google.com/d/msgid/lmfit-py/MN6PR11MB8219B7FF8FEF26F2B983B55596C42%40MN6PR11MB8219.namprd11.prod.outlook.com.
Reply all
Reply to author
Forward
0 new messages