大数组的内插和外推 [英] Interpolation and extrapolation for large arrays

查看:91
本文介绍了大数组的内插和外推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不均匀的有序网格x上定义了一个大数组y.阵列的长度通常为N〜2 ^ 14至N〜2 ^ 18.我想获得阵列的样条插值(或二次).我面临的问题是,即使对于较低的N值,插值也会花费很长时间.

I have a large array y defined on a non-uniform, ordered grid x. The length of the array is typically N~2^14 to N~2^18. I want to get a spline-interpolation (or quadratic) of the array. The problem I am facing is that even for lower values of N the interpolation takes very long.

import numpy as np
from scipy.interpolate import interp1d
N = 2 ** 12 # = 4096
x = np.linspace(0, 2*np.pi, N)
y = np.sin(x)
%time f = interp1d(x, y, 'cubic', )

CPU times: user 8min 5s, sys: 1.39 s, total: 8min 7s
Wall time: 8min 7s

我看到的一个选择是,仅在非常有限的一组数据点上才需要插值的值. 是否只有在需要时才可以计算插值?

One option I am seeing is that I need the values of the interpolation only at a very limited set of data points. Is there a way to compute the interpolation only when asked for it?

您能建议一个在x.min()以下和x.max()以上的值上还具有外推功能的替代方法吗?

Can you suggest an alternative that also features extrapolation at values below x.min() and above x.max()?

谢谢!

推荐答案

对于非均匀分布的横坐标,您可能需要考虑广义插值技术(例如B样条).

For non-uniformly distributed abscissa you might want to consider a generalized interpolation technique (such as B-splines).

将数据近似为多个系数乘以基函数的总和(例如,具有不均匀选择的结的B样条-或位置良好的高斯函数的径向基函数网络).这些功能只是必须涵盖感兴趣的空间.

Approximate your data as the sum of a number of coefficients times basis functions (for example B-splines with non-uniformly chosen knots - or a radial basis function network of well-placed Gaussians). These functions just must span the space of interest.

现在,您可以使用最小二乘方来近似加权系数-然后以所需的任何分辨率在任何地方重新采样.如果您采用这种方法,则可以基于平滑度对系统进行正则化,以便在x.min()和x.max()之外提供更多合理的值.

Now you can use least squares to approximate the weighting coefficients - and then re-sample anywhere at whatever resolution that you need. If you take this approach you may regularize the system based on smoothness as well to give more sane values outside of x.min() and x.max().

这是并置方法:假设您的样本值在向量x,y中.将基本向量设置为phi_k(x)的采样版本

This is the collocation method: Lets say your sample values are in the vectors x,y. set up your basis vectors as sampled versions of phi_k(x)

然后设置基础B = c_ [phi_1,phi_2,...,phi_M]并使用最小二乘:c,res,rnk,sv = lstsq(B,y).

then set up your basis B = c_[phi_1,phi_2,...,phi_M] and use least squares: c,res,rnk,sv = lstsq(B,y).

如果基本多项式的数量很少-那么可以快速进行.

if the number of basis polynomials is small - then this can go fast.

现在,向量c包含系数.您可以通过构建在其中采样的新基础向量来计算感兴趣点的新值:Bnew = c_ [phi_1_new,phi_2_new,...,phi_M_new]

Now your vector, c, contains the coefs. You compute new values at points of interest via building new basis vectors that are sampled there: Bnew = c_[phi_1_new,phi_2_new,...,phi_M_new]

并投影y_new = dot(Bnew,c)

and projecting y_new = dot(Bnew,c)

  • 此方法可以轻松使您进行控制,以选择的任何形式的正则化进行扩展
  • 然后在任意点对系统进行重新采样
  • 使用对您的问题有意义的任何基础函数
  • 如果M足够小,则可以快速求解系统

这篇关于大数组的内插和外推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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