[SciPy-user] estimating errors with optimize.leastsq

Christian Kristukat ckkart at hoc.net
Tue Jul 11 21:54:05 EDT 2006


Christian Kristukat wrote:
> Robert Kern wrote:
>> Christian Kristukat wrote:
>>> Robert Kern wrote:
>>>> Christian Kristukat wrote:
>>>>> Chiara Caronna wrote:
>>>>>> 2) Is there any way to get the estimated errors on the fitting parameter?
>>>>>> Maybe optimize.leastsq is not the right choice? Does anyone has some good 
>>>>>> hints?
>>>>> Everything you need is in here:
>>>>> http://www.boulder.nist.gov/mcsd/Staff/JRogers/papers/odr_vcv.dvi
>>>>> I haven't yet found time/will to dig into it, but I'm definitely interested in a
>>>>> good error estimation routine.
>>>> The implementation of the ideas in that paper is in ODRPACK by the same author. 
>>>> It is wrapped as scipy.sandbox.odr . The docstrings are fairly thorough, I 
>>>> think, but please let me know if something needs to be clarified.
>>> great! I just to tried to build from svn with sandbox.odr enabled. Upon
>>> importing odr I get the following error:
>>>
>>>>>> from scipy.sandbox import odr
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in ?
>>>   File "/usr/local/lib/python2.4/site-packages/scipy/sandbox/odr/__init__.py",
>>> line 55, in ?
>>>     import odrpack
>>>   File "/usr/local/lib/python2.4/site-packages/scipy/sandbox/odr/odrpack.py",
>>> line 113, in ?
>>>     from scipy.sandbox.odr import __odrpack
>>> ImportError: cannot import name __odrpack
>>>
>>> Looking at site-packages/scipy/sandbox/odr it looks like that the extension
>>> module has not been built.
>>>
>>> However I have been able to build the odr module alone. I had to comment out
>>> line 48 in setup_odr.py (I've no atlas) and in the last line a .todict()) was
>>> missing.
>> D'oh! I could have sworn I had that working. Oh well. It's fixed now.
> 

In addition I had to make some changes to odrpack.py to get it to work with
numpy from svn:

--- odrpack.py  2006-07-12 10:49:05.000000000 +0900
+++ odrpack_mod.py      2006-07-12 10:38:44.000000000 +0900
@@ -109,7 +109,7 @@
 Robert Kern
 robert.kern at gmail.com
 """
-
+import numpy
 from scipy.sandbox.odr import __odrpack
 from types import NoneType

@@ -740,7 +740,7 @@

         x_s = list(self.data.x.shape)

-        if type(self.data.y) is numpy.ArrayType:
+        if type(self.data.y) is numpy.ndarray:
             y_s = list(self.data.y.shape)
             if self.model.implicit:
                 raise odr_error, "an implicit model cannot use response data"
@@ -853,12 +853,12 @@
             lwork = (18 + 11*p + p*p + m + m*m + 4*n*q + 2*n*m + 2*n*q*p +
                      5*q + q*(p+m) + ldwe*ld2we*q)

-        if type(self.work) is numpy.ArrayType and self.work.shape == (lwork,)\
-           and self.work.dtype == numpy.Float:
+        if type(self.work) is numpy.ndarray and self.work.shape == (lwork,)\
+           and self.work.dtype == numpy.float64:
             # the existing array is fine
             return
         else:
-            self.work = numpy.zeros((lwork,), numpy.Float)
+            self.work = numpy.zeros((lwork,), numpy.float64)

     def set_job(self, fit_type=None, deriv=None, var_calc=None,
                 del_init=None, restart=None):

Regards, Christian



More information about the SciPy-User mailing list