surface fitting library for Python?

Carl Banks imbosol at aerojockey.com
Thu Apr 8 17:00:31 EDT 2004


Grant Edwards <grante at visi.com> wrote in message news:<40748902$0$17253$a1866201 at newsreader.visi.com>...
> 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)).


Idea: see if you can use the versatility of Python to fool SciPy into
fitting a surface when it thinks it's fitting a curve.  I don't know
the exact interface of the function you speak of, but I assume you
pass in a function taking two arguments (a paramter vector and an
independent variable), a data vector of x values, and a data vector of
f(x) values.  I wonder if these vectors can be Python vectors, or do
they have to be a Numeric vectors?  If a Python vector suffices, then
you can perhaps write your function to accept a tuple rather than a
single independent value:

    def f(paramters,(x,y)):
        whatever

Then, for your independent values vector, instead of [1,2,3,4] you'd
use with a 2-D curve, use [(1,1),(1,2),(2,1)].

Even if a Scipy requires Numeric vectors, I think there's a good
chance it can still do this.  Knowing what I know about Numeric, I
suspect SciPy might do the right thing if you pass in a rank 2 array
as the independent variable vector.  It might directly pass the an
element of your rank 2 array, which is a rank 1 array, to your
function (and it might not).


> I found a couple other curve fitting libraries (some are
> wrappers to C/Fortran libs I don't have), and I found a
> curve and surface-fitting web page (www.zuzun.com) that's
> written in Python -- I found a couple postings by James R.
> Phillips (zunzun's author) and I suspect he's calling a
> non-Python library of some sort.
> 
> What's the recommended method for doing surface fitting in
> Python?

If SciPy can't do it, it's not too hard to do it by hand, unless there
are bounds or unless you want to minimize a non-Euclidean distance. 
The setup is the hard part; Numeric can do solve a linear least
squares problem in one call.


-- 
CARL BANKS



More information about the Python-list mailing list