[SciPy-User] Fitting data with optimize.curve_fit
josef.pktd at gmail.com
josef.pktd at gmail.com
Thu Oct 3 09:46:59 EDT 2013
On Tue, Sep 24, 2013 at 8:10 PM, TFSM <tesla.bamf at gmail.com> wrote:
> lab1.py <http://scipy-user.10969.n7.nabble.com/file/n18692/lab1.py>
> I have a couple questions. The data show as counts is the total number of
> counts in 60 seconds. When using the count rate instead of the total counts
> as the y data, curve_fit does not want to give a meaningful answer. It gives
> the co-variance as infinity and the cosine that is fit does not match the
> data. Using total counts y*60, the co-variance is reasonable and the cosine
> fits the data.
>
> Why does increasing the counts by 60 allow curve_fit to give a reasonable
> answer?
>
> A similar problem happens when trying to fit the first harmonic to this
> data, A11*cos(3x/pi) + A31*cos(3x/pi) but I must increase the counts
> artificially by at least 10 times for curve_fit to give me a curve that
> resembles the data being fit.
>
> Is there a better way to fit this data? Is what I am doing here legitimate
> artificially increase y to get a fit then just dividing by that amount to
> get the data back to count rate? Sorry for the noob questions and thanks.
The mysteries of numerical optimization
Many or most optimizers are not scale invariant, at least not under
default options
for example
default starting values are ones, which might not be good in a rescaled version
forward derivative: it could also be that epsfcn is not appropriate in
the rescaled version
http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html
ftol looks scale invariant but not xtol which should, however, only
affect the precision of the final estimate.
Josef
>
>
>
>
>
>
> --
> View this message in context: http://scipy-user.10969.n7.nabble.com/Fitting-data-with-optimize-curve-fit-tp18692.html
> Sent from the Scipy-User mailing list archive at Nabble.com.
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list