[SciPy-User] Cubic splines - MATLAB vs Scipy.interpolate

Hjalmar Turesson hturesson at gmail.com
Sat Oct 1 06:46:53 EDT 2011


Hi,

splmake and spleval (in scipy.interpolate) appear to run as fast as spline
in matlab. They are approximately 30 times faster than cspline1d and
cspline1d_eval. splmake with order = 3 gives the same output as cspline1d.
The documentation for splmake and spleval is unfortunately minimal.


Best,
Hjalmar

On Tue, Sep 27, 2011 at 11:08 PM, Charles R Harris <
charlesr.harris at gmail.com> wrote:

>
>
> On Tue, Sep 27, 2011 at 5:50 PM, <josef.pktd at gmail.com> wrote:
>
>> On Tue, Sep 27, 2011 at 7:27 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>> >
>> >
>> > On Tue, Sep 27, 2011 at 2:27 PM, Zachary Pincus <
>> zachary.pincus at yale.edu>
>> > wrote:
>> >>
>> >> scipy.signal has some cubic and quadratic spline functions:
>> >> cspline1d
>> >> cspline1d_eval
>> >> cspline2d
>> >>
>> >> (and replace the c with q for the quadratic versions).
>> >>
>> >> I have no idea how fast they are, or if they're at all drop-in
>> >> replacements for the matlab ones. The stuff in scipy.interpolate is
>> >> powerful, but the fitpack spline-fitting operations can be a bit
>> >> input-sensitive and prone to strange ringing.
>> >>
>> >> Zach
>> >>
>> >>
>> >>
>> >> On Sep 27, 2011, at 3:32 PM, Charles R Harris wrote:
>> >>
>> >> >
>> >> >
>> >> > On Tue, Sep 27, 2011 at 1:04 PM, Jaidev Deshpande
>> >> > <deshpande.jaidev at gmail.com> wrote:
>> >> > Hi
>> >> >
>> >> > The big question: Why does the MATLAB function spline operate faster
>> >> > than the cubic spline alternatives in Scipy, especially splrep and
>> splev ?
>> >> >
>> >> > ------
>> >> >
>> >> > The context: I'm working on an algorithm that bottlenecks on spline
>> >> > interpolation.
>> >> >
>> >> > Some functions in Scipy return an interpolation object function
>> >> > depending on the input data which needs to be evaluated independently
>> over
>> >> > the whole range.
>> >> >
>> >> > So I used 'lower order' functions like splrep and splev. Even that
>> was
>> >> > too slow.
>> >> >
>> >> > Then I tried to write my own code for cubic splines, generating and
>> >> > solving a system of 4N simultaneous equations for interpolation
>> between N+1
>> >> > points.
>> >> >
>> >> > No matter what I do, the code is quite slow. How come the MATLAB
>> >> > function spline operate so fast? What am I missing? What can I do to
>> speed
>> >> > it up?
>> >> >
>> >> >
>> >> > I suspect it is because the scipy routines you reference are based on
>> >> > b-splines, which are needed for least squares fits. Simple cubic
>> spline
>> >> > interpolation through a give set of points tends to be faster and I
>> believe
>> >> > that is what the Matlab spline function does. To get b-splines in
>> Matlab you
>> >> > need one of the toolboxes, it doesn't come with the core. I don't
>> think
>> >> > scipy has a simple cubic spline interpolation, but I may be wrong.
>> >> >
>> >
>> > I believe the splines in signal are periodic and the boundary conditions
>> > aren't flexible. The documentation is, um..., well, they are effectively
>> > undocumented. We really need better spline support in scipy.
>>
>> I thought the main difference of the signal compared to interpolate
>> splines is that they work only on a regular grid.
>> They have a smoothing coefficient lambda, so they don't seem to be
>> pure interpolating splines.
>>
>>
> The equally spaced points are what I meant by periodic, i.e., the same
> basis function can be repeated. The signal itself it periodic if extended to
> twice its length with the mirror symmetry at the ends. I'm not sure how the
> smoothing factor works. The ndimage map_coordinates would work for
> interpolating equally spaced points and has more boundary conditions, but
> they are still can't be arbitrary. I think scipy could use a simple
> interpolating spline with not a knot default boundary conditions and no
> repeated knot points. The not a knot boundary conditions means to use finite
> differences at the ends to estimate the slopes which then become the
> boundary conditions.
>
> Chuck
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20111001/61f4563d/attachment.html>


More information about the SciPy-User mailing list