Note that there are some explanatory texts on larger screens.

plurals
  1. PODifference between Levenberg-Marquardt-Algorithm and ODR
    primarykey
    data
    text
    <p>I was able to fit curves to a x/y dataset using <a href="http://lorentz.sourceforge.net/" rel="nofollow noreferrer">peak-o-mat</a>, as shown below. Thats a linear background and 10 lorentzian curves. <img src="https://i.stack.imgur.com/FKXNH.png" alt="Peak-o-mat results"></p> <p>Since I need to fit many similar curves I wrote a scripted fitting routine, using <a href="http://code.google.com/p/agpy/source/browse/trunk/mpfit/?r=399" rel="nofollow noreferrer">mpfit.py</a>, which is a Levenberg-Marquardt-Algorithm. However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result:</p> <p><strong>Starting values</strong> <img src="https://i.stack.imgur.com/yXS2D.png" alt="Starting values"></p> <p><strong>Fit result with fixed linear background</strong> (values for linear background taken from the peak-o-mat result) <img src="https://i.stack.imgur.com/dTbVr.png" alt="Fit fixed"></p> <p><strong>Fit result with all variables free</strong> <img src="https://i.stack.imgur.com/Zvs62.png" alt="Fit free"></p> <p>I believe the starting values are already very close, but even with the fixed linear background, the left lorentzian is clearly a degradation of the fit.</p> <p>The result is even worse for total free fit.</p> <p>Peak-o-mat appears to use <a href="http://www.scipy.org/doc/api_docs/SciPy.odr.odrpack.html" rel="nofollow noreferrer">scipy.odr.odrpack</a>. Now what is more likely:</p> <ol> <li>I did some implementation error? </li> <li>odrpack is more suitable for this particular problem?</li> </ol> <p>Fitting to a more simple problem (linear data with one peak in the middle) shows very good correlation between peak-o-mat and my script. Also I did not find a lot about ordpack.</p> <p><strong><em>Edit:</em></strong> It seems I could answer the question by myself, however the answer is a bit unsettling. Using scipy.odr (which allows fitting with odr or leastsq method) both give the result as peak-o-mat, even without constraints.</p> <p>The image below shows again the data, the start values (almost perfect) and then the odr and leastsq fits. The component curves are for the odr one</p> <p><img src="https://i.stack.imgur.com/y46w2.png" alt="scipy.odr"></p> <p>I will switch to odr, but this still leaves me upset. The methods (mpfit.py, scipy.optimize.leastsq, scipy.odr in leastsq mode) 'should' yield the same results.</p> <p>And for people stumbling upon this post: to do the odr fit an error must be specified for x and y values. If there is no error, use small values with sx &lt;&lt; sy. </p> <pre><code>linear = odr.Model(f) mydata = odr.RealData(x, y, sx = 1e-99, sy = 0.01) myodr = odr.ODR(mydata, linear, beta0 = beta0, maxit = 2000) myoutput1 = myodr.run() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload