[SciPy-user] incorrect variance in optimize.curvefit and leastsq

Travis E. Oliphant oliphant@enthought....
Thu Feb 12 23:24:13 CST 2009


josef.pktd@gmail.com wrote:
> On Thu, Feb 12, 2009 at 11:09 PM, Travis E. Oliphant
> <oliphant@enthought.com> wrote:
>   
>> josef.pktd@gmail.com wrote:
>>     
>>> I just saw the new optimize.curvefit which provides a wrapper around
>>> optimize.leastsq
>>>
>>>
>>>       
> the standard deviation of the error can be calculated and the
> corrected (this is written for the use from outside of curvefit):
>
> yhat = func(x,popt[0], popt[1])   # get predicted observations
> SSE = np.sum((y-yhat)**2)
> sig2 = SSE/(len(y)-len(popt))
> ecov = sig2*pcov       # this is the variance-covariance  matrix of
> the parameter estimates
>
>
> inside curvefit, this work (before the return):
>
> err  = func(popt, *args)
> SSE = np.sum((err)**2)
> sig2 = SSE / (len(ydata) - len(popt))
> pcov = sig2 * pcov
>   

Thanks very much for these...   I appreciate your help in getting 
curve_fit in better shape.   These functions were essentially added to 
curvefit so now curve_fit can be tested against those NIST pages.   
Thank you also for the unit tests.

A good project idea for somebody wanting to get their feet wet with 
SciPy would be to write unit-tests of curve_fit against some more of 
those NIST data-sets --- those look nice.   A combination of loadtxt and 
additional parsing fu and you could automate the whole thing --- nice 
project for a student out there ;-)

-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