[Numpy-discussion] ScientificPython with numarray support

Sebastian Haase haase at msg.ucsf.edu
Fri Jan 14 17:24:19 CST 2005


On Friday 14 January 2005 04:15 pm, John Hunter wrote:
> >>>>> "Sebastian" == Sebastian Haase <haase at msg.ucsf.edu> writes:
>
>     Sebastian> The LeastSquare-fit is exactly what I'm interested in,
>     Sebastian> since I couldn't find something similar anywhere else
>     Sebastian> (like: It's not in SciPy, right?)
>
> from scipy import exp, arange, zeros, Float, ones, transpose
> from RandomArray import normal
> from scipy.optimize import leastsq
>
> parsTrue = 2.0, -.76, 0.1
> distance = arange(0, 4, 0.001)
>
> def func(pars):
>     a, alpha, k = pars
>     return a*exp(alpha*distance) + k
>
> def errfunc(pars):
>     return data - func(pars)  #return the error
>
> # some pseudo data; add some noise
> data = func(parsTrue) + normal(0.0, 0.1, distance.shape)
>
>
> guess = 1.0, -.4, 0.0   # the intial guess of the params
>
> best, info, ier, mesg = leastsq(errfunc, guess, full_output=1)
>
> print 'true', parsTrue
> print 'best', best
>
Thanks John,
I thought it should be there. 
Is the code / algorithm about similar to what Konrad has in Scientific ?

- Sebastian




More information about the Numpy-discussion mailing list