[SciPy-user] Polynomial interpolation
Eike Welk
eike.welk at gmx.net
Mon Apr 28 17:21:38 EDT 2008
On Monday 28 April 2008 22:36, Anne Archibald wrote:
> 2008/4/28 Robert Kern <robert.kern at gmail.com>:
> > Well those certainly aren't useful. The only functions I would
> > consider adding would be "one-shot" functions, e.g.:
> >
> > def krogh(xi, yi, x):
> > return KroghInterpolator(xi,yi)(x)
>
> The problem here is that construction of the splines is an order
> degree**2 process, so I want an interface that encourages users to
> construct them once and for all. I think such an approach also
> discourages people from just
>
> y_interp = krogh(all_my_data_x, all_my_data_y, x_interp)
>
> with hundreds of points, the results of which will be meaningless
> and horrible.
You could store already constructed interpolation objects in a
dictionary. (I didn't test it.):
krogh_interpolator_cache={}
def evaluate_krogh_interpolation(all_my_data_x, all_my_data_y,
x_interp):
global krogh_interpolator_cache
if (all_my_data_x, all_my_data_y) in krogh_interpolator_cache:
theInterpolator = krogh_interpolator_cache[(all_my_data_x,
all_my_data_y)]
return theInterpolator(x_interp)
else:
newInterpolator = KroghInterpolator(all_my_data_x,
all_my_data_y)
krogh_interpolator_cache[(all_my_data_x, all_my_data_y)] \
= newInterpolator
return newInterpolator(x_interp)
Offcourse you could empty the dictionary when there are more than a
certain number of objects in it, to avoid memory leaks. When you have
implemented this too, the function doesn't look so empty anymore, and
then nobody has to feel like an idiot.:-)
Kind regards,
Eike.
More information about the SciPy-User
mailing list