surface fitting library for Python?

David M. Cooke cookedm+news at physics.mcmaster.ca
Thu Apr 8 16:07:37 EDT 2004


At some point, Grant Edwards <grante at visi.com> wrote:

> I'm looking for a surface fitting library for Python. 
>
> Something like the least-squares module in scientific python,
> except I want to fit a surface (z = f(x,y)) instead of a curve
> (y = f(x)).

You mean Konrad Hinsen's ScientificPython?
Scientific.Functions.LeastSquares.leastSquaresFit should still work
for you. You just need to make your data a list of tuples of (x,y) and z.

Example:

from Scientific.Functions.LeastSquares import leastSquaresFit

data = [ ((x1,y1), z1), ((x2,y2), z2), ...]

parameters = [initialc0, initialc1, initialc2]
def model(params, xy):
    c0, c1, c2 = params
    x, y = xy
    return c0*x + c1*sin(c2*y)

params, chisquared = leastSquaresFit(model, parameters, data)

If your model isn't amiable to having derivatives taken, you might
check out the wrapping by Robert Kern of ODRPACK:
http://starship.python.net/crew/kernr/Projects.html
I've used this successfully.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list