[Numpy-discussion] ScientificPython with numarray support

John Hunter jdhunter at ace.bsd.uchicago.edu
Fri Jan 14 16:21:22 CST 2005


>>>>> "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





More information about the Numpy-discussion mailing list