[SciPy-user] incorrect variance in optimize.curvefit and leastsq
Travis E. Oliphant
Sat Feb 14 16:10:15 CST 2009
>> 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
>> 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 =
> 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
> 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
(512) 536-1057 (office)
(512) 536-1059 (fax)
More information about the SciPy-user