[SciPy-user] Polynomial interpolation
Sun Apr 20 20:03:05 CDT 2008
On 20/04/2008, Robert Kern <email@example.com> wrote:
> On Sat, Apr 19, 2008 at 4:27 PM, Anne Archibald
> <firstname.lastname@example.org> wrote:
> > They all need work, in particular, efficiency would be improved by
> > making the y values vectors, error checking needs to be more robust,
> > and documentation is not in reST form. Ultimately, too, the evaluation
> > functions at least should be written in a compiled language (cython?).
> > But I thought I'd solicit comments on the code first - is the
> > object-oriented design cumbersome?
> It looks fine although Gabriel's suggestions would be good
> improvements. Some people may want single-function interfaces (e.g.
> krogh(xi, yi, x)); they can be written on top of the OO implementation
> rather more easily than otherwise.
Reasonable, though really, is krogh_interpolate(xi, yi, x) much better
than KroghInterpolator(xi, yi)(x)? It's also good to emphasize that
the construction of the interpolating polynomial is a relatively slow
process compared to its evaluation.
> > Is the calling convention for Hermite
> > polynomials too confusing or error-prone?
> It looks fine to me. For PiecewisePolynomial, I might transpose the yi
> input such that yi is the function value, yi is the first
> derivative, etc.
The problem with this is that it forces the user to specify the same
number of derivatives at each point. It may be desirable (for example)
to specify the derivative at only one point but the function value at
many. The way I did it you just pass in a nested list. If you have
them in the form you suggest, a quick np.transpose([y,yp,ypp]) should
get the form that I want.
> A nitpick: the code
> pos[pos==-1] = 0
> pos[pos==self.n-1] = self.n-2
> can be replaced with
> pos.clip(0, self.n-2, out=pos)
> But this all looks good, and I want it in scipy.
What's the story on including cython code in scipy? Is it an
additional build dependency, and so to be avoided? Can it be used in a
SWIG-like role to produce files that can be distributed and compiled
with a C compiler? For any interpolation scheme, it's obviously
essential that it be able to be evaluated rapidly...
More information about the SciPy-user