简体   繁体   English

云数据点的加权一维插值

[英]Weighted 1D interpolation of cloud data point

I have a cloud of data points (x,y) that I would like to interpolate and smooth. 我想对数据点(x,y)进行插值和平滑处理。

Currently, I am using scipy : 目前,我正在使用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

This is working pretty well, except that I would like to give some weights to the data points given at interp1d . 这工作得很好,除了我想对interp1d给出的数据点赋予一些权重。 Any suggestion for another function that is handling this ? 对处理此问题的另一个功能有什么建议吗?

Basically, I thought that I could just multiply the occurrence of each point of the cloud according to its weight, but that is not very optimized as it increases a lot the number of points to interpolate, and slows down the algorithm .. 基本上,我认为我可以根据其权重乘以每个云点的出现次数,但这并不是很优化,因为它增加了很多要插值的点数,并且减慢了算法的速度。

The default interp1d uses linear interpolation , ie, it simply computes a line between two points. 默认的interp1d使用线性插值 ,即,它仅计算两个点之间的线。 A weighted interpolation does not make much sense mathematically in such scenario - there is only one way in euclidean space to make a straight line between two points. 在这种情况下,加权插值在数学上没有多大意义-欧氏空间中只有一种方法可以在两点之间形成一条直线。

Depending on your goal, you can look into other methods of interpolation, eg, B-splines . 根据您的目标,您可以研究其他插值方法,例如B样条 Then you can use scipy's scipy.interpolate.splrep and set the w argument: 然后,您可以使用scipy的scipy.interpolate.splrep并设置w参数:

w - Strictly positive rank-1 array of weights the same length as x and y. w-权重严格为1的正数组,长度与x和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. 如果y值中的误差具有矢量d给出的标准偏差,则w应为1 / d。 Default is ones(len(x)). 默认值为1(len(x))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM