[AstroPy] non-linear least square fitting in python

Kevin Gullikson kevin.gullikson at gmail.com
Thu May 14 10:05:56 EDT 2015


A few thoughts:

- As Tom mentioned, the function is simple enough that I would bet that
scipy.optimize.leastsq is already finding the global minimum.
- You could do a full grid search in parameters, and visualize the
parameter space in terms of parameter vs chi^2. That way you can see where
the global minimum is.
- "chi by eye": A local minimum probably won't "look" right if you plot the
solution curve on top of the data. If it looks right, it probably is.


Kevin Gullikson

On Thu, May 14, 2015 at 8:04 AM, gonghang.naoc <ghang.naoc at gmail.com> wrote:

>
>
> *Hi Tom,For y=a*e^(-b*x) , we can get an analytic solution. So it is not
> necessary to guess. For y=a*e^(-b*x)+c, we can not get an analytic
> solution, right?*
>
> *Hang*
>
> On Thu, May 14, 2015 at 6:47 PM, Aldcroft, Thomas <
> aldcroft at head.cfa.harvard.edu> wrote:
>
>>
>>
>> On Thu, May 14, 2015 at 5:52 AM, gonghang.naoc <ghang.naoc at gmail.com>
>> wrote:
>>
>>> Hi all,
>>> We can use scipy.optimize.leastsq to do least square fitting in python.
>>> However we need to make an initial guess. (
>>> http://python4mpia.github.io/fitting_data/least-squares-fitting.html).
>>> So I am not sure we can get a global optimum.
>>>
>>
>> Ensuring that you have a global optimum for a non-linear is generally a
>> difficult problem.  In your case though you have a reasonably simple fit
>> function so that if you provide a decent initial guess then most optimizers
>> should converge to something near the global optimum.
>>
>> You can make an initial guess in your case by taking 3 data points, at
>> the beginning, middle, and end of your data.  With those three data points
>> you can analytically solve for a, b, and c.  Then use those as the starting
>> point.  If your data are very noisy you might average a few.
>>
>> Cheers,
>> Tom
>>
>>
>>>
>>> There is other simple way we can fit a *y=a*e^-(b*x)+c* curve? My data
>>> are  Xn, Yn and ERRORn. A constant c makes the fitting difficult since we
>>> can not make a log on both sides and use linear fitting any more.
>>>
>>> Thank you.
>>> best
>>> Hang
>>>
>>>
>>> _______________________________________________
>>> AstroPy mailing list
>>> AstroPy at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/astropy
>>>
>>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
>>
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150514/a7bcb5db/attachment.html>


More information about the AstroPy mailing list