<div dir="ltr">I tried to pay more attention to the initial guess as suggested, and found a very nearly close fit! The new initial guess I used is <div><br></div><div>p0=[V.max(), std_dev, V.max(), 2]<br></div><div><br></div><div>See attached for new fit.</div><div><br></div><div>I then used the resulting values for my parameters ps1, ps2,ps3, ps4 as a new initial guess, but surprisingly, there is no improvement in the fit. It just remains the same, even after repeatedly using new parameters as initial guess for like five successive times. Any way I can improve my guess?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 5, 2017 at 6:39 PM, Matt Newville <span dir="ltr"><<a href="mailto:newville@cars.uchicago.edu" target="_blank">newville@cars.uchicago.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Apr 5, 2017 at 10:41 AM, Daπid <span dir="ltr"><<a href="mailto:davidmenhur@gmail.com" target="_blank">davidmenhur@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class="m_412714579513587144gmail-"><br><div class="gmail_quote">On 5 April 2017 at 17:24, Otto Ngeke <span dir="ltr"><<a href="mailto:lieemlieem@gmail.com" target="_blank">lieemlieem@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font color="#cc0000">I still get the same fit as before</font>. However, I am worried because my Gaussians are such that the amplitude of the second Gaussian term is the standard deviation of the first: some kind of coupling between the terms. I don't know if this new function definition actually represents that property.</blockquote></div><br></span><div>It should be:<br><br></div><span class="m_412714579513587144gmail-"><div>def func(x, params):<br> ps1, ps2, ps3, ps4 = params</div></span><span class="m_412714579513587144gmail-"><div> return ps1*np.exp(-(x/ps2)**2) + ps2*np.exp(-(x/ps3)**2) + ps3*np.exp(-(x/ps4)**2)<br><br><br></div></span></div><div class="gmail_extra">Note that in your initialisation you have a symmetry between the first and the third Gaussian:<br><br></div><div class="gmail_extra"><span class="m_412714579513587144gmail-"><div>popt, pcov = optimize.curve_fit(func, r, V, p0=[50, std_dev, 50, std_dev], maxfev=10000)<br><br></div></span><div>So unless curve_fit adds some random noise, the two are going to be always the same because you cannot break the symmetry. </div></div></div></blockquote></span><div><br>That is not correct. Setting multiple parameters to the same initial values does not
make them always have the same value. Each parameter here is separate, and there is no symmetry here at all.<br><br> </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div>Instead, give them different values, for example:<br><br>[50, 1.2 * std_dev, 30, std_dev / 1.2]<br><br></div><div>(I have no idea if this particular values make sense, but they do will allow you to get two independent Gaussians, not too far from your initial guess.)<br><br></div></div></div></blockquote><div><br></div></span><div>Certainly giving initial values that are close as possible is a good idea, but they do not need to have values that are unique.<br></div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><br></div><div>For hard fits (and arbitrary fits are surprisingly hard!), iminuit is a quite powerful option.<br></div><div><br></div></div></div></blockquote><div><br></div></span><div>Lmfit might also be useful here. But the basic problem is that the model of multiple Gaussians with the same center will have a very hard time describing the data shown.<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>--Matt <br><br></div></font></span></div></div></div>
<br>______________________________<wbr>_________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scipy-user</a><br>
<br></blockquote></div><br></div>