[SciPy-User] Sotring data for fast access

Rob Clewley rob.clewley@gmail....
Sun Aug 28 13:40:52 CDT 2011


Hi Ali,

On Sat, Aug 27, 2011 at 11:21 PM, ali franco <ali.franco95@gmail.com> wrote:
> There are two parts to my question.

I'm not sure I understand enough about the first q to answer it with
authority, but my gut instinct, FWIW, is that using a table of
pre-computed values on some mesh of (x,y) means you'll have to accept
interpolated values for the Bessel function when it's needed at new
(x,y) values. I mean, if you already know all the (x,y) values you'll
need, I don't see the benefit in any precomputation. Maybe the best
splines to use in this and your ODE problem are ones where you impose
the knots from the sampled values and their first derivatives there,
since you can explicitly compute the derivatives for Bessel functions
and for ODE right-hand sides. That guarantees pretty good accuracy of
the fit, and you'll be using quadratics between every pair of knots.
If you don't specify the derivatives and use cubics, you'll run the
risk of nasty behavior such as Runge's phenomenon.

> Second question: I have numerically integrated a differential equation and I
> use the splined solution to solve other differential equations. However the
> splined solution is slow. Is there a way to make this faster?

What exactly do you mean by using the solution to solve other DEs? It
would help for you to provide concrete examples when posting on
forums. If you mean that you are using a spline-interpolated curve as
a time-dependent term in another DE's right-hand side, then yes,
that's going to be slower in pure python. But if speed is such an
issue, you shouldn't be using odeint. PyDSTool supports external input
signals of a similar kind running C-based integrators very quickly
compared to odeint, but currently only supports piecewise-linear
interpolation of those signals. This can be accurate enough if you
have a very high sampling rate for that signal relative to your new
DE's time steps, particularly because the integrator is guaranteed to
step to the knot points. Higher order splines in C are on my to do
list, though. PyDSTool's interface to scipy's vode wrapper does
support higher order splines but it's done in python, so probably
won't be faster than what you're already doing.

-Rob


More information about the SciPy-User mailing list