[SciPy-user] Questions to optimize.leastsq
Alexander Dietz
Alexander.Dietz at astro.cf.ac.uk
Thu Dec 20 04:58:01 EST 2007
Hi,
I am using optimize.leastsq for the first time, and I seem to have some
trouble with it. I am following the example given on the scipy webpage to
fit a either 3 or 4 parameter function. The fit itself works fine, and I get
reasonable results.
My problem is to extract the errors on my 3 or 4 fitting parameters. Here is
what I do exactly:
q,cov,w,e, success = optimize.leastsq(errfunc, p[:], args = (xData, yData),
full_output=1 )
if success==1:
sigma = sqrt(diag(cov))
For the errors on my fitting parameters 'q' I take the square-root in the
diagonal elements of the covariance matrix. For one or two parameters I get
reasonable errors (i.e. the relative error is in the range of 30%), but for
other parameters the errors are a million times larger than the parameter
itself!
Example:
bestfit parameter 0: -1.743351 +- 3226113.032304
bestfit parameter 1: 0.778228 +- 0.145904
bestfit parameter 2: 4.261635 +- 48185218.007348
bestfit parameter 3: 21183.401658 +- 23799.387162
I checked the function I am fitting and when varying one of these parameters
everything looks 'ok' (i.e. no sudden change of the values in the order of
millions or so). I my sense, these errors (except parameter 1) do not make
sense.
So how can I fit a function to data and obtain reasonable errors? Maybe I
need to set one of the extra options in leastsq? I would appreciate any help
in this.
Cheers
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071220/1fa36d77/attachment.html>
More information about the SciPy-User
mailing list