[AstroPy] non-linear least square fitting in python

Matteo matteo at matteobachetti.it
Thu May 14 08:45:22 EDT 2015


In scipy, there is a fitting algorithm that is called basinhopping. It's
*far* slower than normal least-square fitting routines, but it's very
helpful when you think you risk having local minima.
http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.optimize.basinhopping.html
If execution time is not an issue (datasets are sufficiently small), it's
worth trying.

Cheers,
Matteo

On Thu, May 14, 2015 at 12: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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150514/731e5a93/attachment.html>


More information about the AstroPy mailing list