二次或三次一维插值,而没有大量的插值器构建开销? [英] Quadratic or cubic 1d interpolate without large interpolator-building overhead?

查看:77
本文介绍了二次或三次一维插值,而没有大量的插值器构建开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对1d中的一连串浮点数(或向量)进行四边形或立方插值,其中long可能是1E + 05或1E + 06(或更多).由于某种原因,对于二次和三次样条曲线,SciPi方便的interp1d()花费的时间来准备内插器的比例几乎为n ^ 3.

I'd like to quad or cube interpolate a long series of floats (or vectors) in 1d, where long could be 1E+05 or 1E+06 (or more). For some reason SciPi's handy interp1d()'s time overhead to prepare the interpolators scales as almost n^3 for both quadratic and cubic splines.

我不需要花键插值器.我可以很容易地编写一个代码(至少对于等距数据),它只使用最接近的3或4个点进行局部(逐段)二次或三次插值,尽管最终可能很丑陋甚至很慢.

I don't need a spline interpolator necessarily. I can write one fairly easily (at least for equal-spaced data) that just uses the closest 3 or 4 points to do a local (piecewise) quadratic or cubic interpolation, though it may end up being ugly and possibly slow.

但是我想知道是否已经存在类似的东西?比interp1d的样条线生成速度更快的吗?

But I'm wondering if something like that exists already? Something faster to generate than the splines from interp1d?

使用scipy v.0.17.0和numpy v.1.13.0

Using scipy v.0.17.0 and numpy v.1.13.0

使用最近安装的Anaconda(我原以为是):scipy v.0.17.0和numpy v.1.11.0

Using a (what I thought was) recent Anaconda installation: scipy v.0.17.0 and numpy v.1.11.0

import time
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

times = []
for n in np.logspace(1, 3.5, 6).astype(int):
    x = np.arange(n, dtype=float)
    y = np.vstack((np.cos(x), np.sin(x)))
    start = time.clock()
    bob = interp1d(x, y, kind='quadratic', assume_sorted=True)
    times.append((n, time.clock() - start))

n, tim = zip(*times)

plt.figure()
plt.plot(n, tim)
plt.xscale('log')
plt.yscale('log')
plt.show()

推荐答案

由于某种原因,SciPi方便的interp1d()用于准备插值器的时间开销对于二次和三次样条曲线几乎都缩放为n ^ 3.

For some reason SciPi's handy interp1d()'s time overhead to prepare the interpolators scales as almost n^3 for both quadratic and cubic splines.

根据此 answer :

简短答案:更新您的scipy安装.

Short answer: update your scipy installation.

更长的答案:在0.19之前,interp1d基于splmake,后者使用具有完整矩阵的线性代数.在scipy 0.19中,将其重构为使用带状线性代数.结果,(下面是scipy 0.19.1)

Longer answer: pre-0.19, interp1d was based on splmake which is using linear algebra with full matrices. In scipy 0.19, it was refactored to use banded linear algebra. As a result, (below is with scipy 0.19.1)

因此,您的问题的答案:

二次或三次一维插值,而没有大量的内插器构建开销?

Quadratic or cubic 1d interpolate without large interpolator-building overhead?

仍在使用scipy.interp1d,而不是您(在本例中为)正在使用的scipy的旧版本.确保使用scipy 0.19或更高版本. Fyi 1.0版已经发布,因此您(I)应该进行相应的更新.

is still use scipy.interp1d just not the old version of scipy that you were (in this case I was) using. Be sure to use scipy 0.19 or newer. Fyi version 1.0 has been released and so you (I) should update accordingly.

这篇关于二次或三次一维插值,而没有大量的插值器构建开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆