云数据点的加权一维插值

Weighted 1D interpolation of cloud data point

我有一堆数据点 (x,y),我想对其进行插值和平滑处理。

目前,我正在使用 scipy :

from scipy.interpolate import interp1d
from scipy.signal import savgol_filter

spl = interp1d(Cloud[:,1], Cloud[:,0]) # interpolation
x = np.linspace(Cloud[:,1].min(), Cloud[:,1].max(), 1000)
smoothed = savgol_filter(spl(x), 21, 1) #smoothing

这工作得很好,除了我想给 interp1d 处给出的数据点一些权重。对处理此问题的另一个功能有什么建议吗?

基本上,我认为我可以根据云的权重乘以每个点的出现次数,但这不是很优化,因为它增加了很多要插值的点数,并减慢了算法..

默认 interp1d 使用 linear interpolation,即它只是计算两点之间的直线。在这种情况下,加权插值在数学上没有多大意义 - 欧几里德 space 只有一种方法可以在两点之间画一条直线。

根据您的目标,您可以研究其他插值方法,例如 B-splines。然后你可以使用 scipy 的 scipy.interpolate.splrep 并设置 w 参数:

w - Strictly positive rank-1 array of weights the same length as x and y. The weights are used in computing the weighted least-squares spline fit. If the errors in the y values have standard-deviation given by the vector d, then w should be 1/d. Default is ones(len(x)).