[SciPy-user] incorrect variance in optimize.curvefit and leastsq
Travis E. Oliphant
oliphant@enthought....
Sat Feb 14 16:10:15 CST 2009
josef.pktd@gmail.com wrote:
>> I think for the weighted least squares problem the weights should go
>> into the SSE calculation. I didn't find directly the reference, but I
>> am somewhat confident that this is correct, from the analogy to the
>> transformed
>> model ynew = y*weight where weight_i = 1/sigma_i in the linear case.
>> But it's too late today to try to check this.
>>
>> SSE = np.sum((err*weight)**2)
>>
>>
>
> I looked at the weighted function some more:
>
> Since the error calculation for the s_sq uses `func =
> _weighted_general_function`
> the above weighting for the SSE is automatically done. But then, in
> this case there is no renormalization
> necessary when calculation s_sq. The special casing of the weighted
> function should be dropped (the commented out part below)
>
> if (len(ydata) > len(p0)) and pcov is not None:
> s_sq = (func(popt, *args)**2).sum()/(len(ydata)-len(p0))
> ## if sigma is not None:
> ## s_sq /= (args[-1]**2).sum()
> pcov = pcov * s_sq
> else:
> pcov = inf
>
Thanks for figuring this out. I've updated the code in the trunk to
reflect this change.
I will add the test suite as soon as I get a power connection again ---
unless someone does it first.
Thanks for pointing out the NIST test-cases and sheparding the curve_fit
function.
Best regards,
-Travis
--
Travis Oliphant
Enthought, Inc.
(512) 536-1057 (office)
(512) 536-1059 (fax)
http://www.enthought.com
oliphant@enthought.com
More information about the SciPy-user
mailing list