[SciPy-user] mpfit crashes (still)...
Steve Schmerler
elcorto at gmx.net
Tue Jul 18 07:38:57 EDT 2006
JF Moulin wrote:
> Robert Kern <robert.kern <at> gmail.com> writes:
>
>> It certainly won't give you that same NameError when you make those changes.
>> Could you copy-and-paste the error you get after you have made those changes?
>>
> Here we go....
>
> this is the script that calls mpfit for testing:
>
>
> import mpfit
> from scipy import *
> import numpy as Numeric
>
> def F(x,p):
> y = ( p[0] + p[1]*x + p[2]*x**2 + p[3]*sqrt(x) +p[4]*log(x))
> return y
>
> def myfunct(p,fjac=None,x=None,y=None,err=None):
> model=F(x,p)
> return([0,(y-model)/err])
>
>
> x = arange(100.0)
> p = [5.7, 2.2, 500., 1.5, 2000.]
> p0 = [5, 2, 250., 1.5, 2000.]
>
> y = F(x,p)
> print y
>
> err=array(ones(len(y)))
>
> fa = {'x':x, 'y':y, 'err':err}
> m = mpfit.mpfit('myfunct', p0, functkw=fa)
> print 'status = ', m.status
> if (m.status <= 0): print 'error message = ', m.errmsg
> print 'parameters = ', m.params
>
>
>
> This is the first output
>
> pythonw -u "testmpfit.py"
> [ -1.#INF0000e+000 5.09400000e+002 3.39851568e+003 6.71212265e+003
> 1.07900887e+004 1.57389299e+004 2.16060932e+004 2.84168889e+004
> ....SNIP....
> 4.61736029e+006 4.71388330e+006 4.81140608e+006 4.90992866e+006]
> Traceback (most recent call last):
> File "testmpfit.py", line 24, in ?
> m = mpfit.mpfit('myfunct', p0, functkw=fa)
> File "c:\Python24\lib\site-packages\mpfit.py", line 852, in __init__
> self.nfev = 0
> File "c:\Python24\lib\site-packages\mpfit.py", line 2249, in __init__
> self.maxgam = 171.624376956302725
> NameError: global name 'log' is not defined
> Exit code: 1
>
>
> This is the badly behaving code in mpfit:
> class machar:
> def __init__(self, double=1):
> if (double == 0):
> self.machep = 1.19209e-007
> self.maxnum = 3.40282e+038
> self.minnum = 1.17549e-038
> self.maxgam = 171.624376956302725
> else:
> self.machep = 2.2204460e-016
> self.maxnum = 1.7976931e+308
> self.minnum = 2.2250739e-308
> self.maxgam = 171.624376956302725
>
> self.maxlog = log(self.maxnum)
> self.minlog = log(self.minnum)
> self.rdwarf = sqrt(self.minnum*1.5) * 10
> self.rgiant = sqrt(self.maxnum) * 0.1
>
>
> Now let us add Numeric. :
>
> beginning of Mpfit contains
>
> import numpy as Numeric
> import types
> from scipy import *
>
> and then...
> self.maxlog = Numeric.log(self.maxnum)
> self.minlog = Numeric.log(self.minnum)
> self.rdwarf = Numeric.sqrt(self.minnum*1.5) * 10
> self.rgiant = Numeric.sqrt(self.maxnum) * 0.1
>
> this gives the following output:
> Traceback (most recent call last):
> File "testmpfit.py", line 24, in ?
> m = mpfit.mpfit('myfunct', p0, functkw=fa)
> File "c:\Python24\lib\site-packages\mpfit.py", line 852, in __init__
> self.nfev = 0
> File "c:\Python24\lib\site-packages\mpfit.py", line 2249, in __init__
> self.maxgam = 171.624376956302725
> NameError: global name 'log' is not defined
> Exit code: 1
>
>
> .... I am for sure as puzzled as you are....
> Thanks for looking....
>
> JF
>
Thats's crazy. However, if I convert my mpfit.py with convertcode.py the
only change in the code is to replace
import Numeric
by
import numpy.oldnumeric an Numpy
(as Travis mentioned earlier)
and this seems to work. However I still have this boolean array
comparison issue (works with Numeric arrays, not numpy but this should
be solvable fairly easily ...).
cheers,
steve
--
Random number generation is the art of producing pure gibberish as
quickly as possible.
More information about the SciPy-User
mailing list