相关文章推荐
眉毛粗的电梯  ·  python ...·  2 周前    · 
沉着的抽屉  ·  python for循环 ...·  1 周前    · 
一直单身的手链  ·  panda ...·  3 天前    · 
刀枪不入的斑马  ·  GitHub ...·  1 年前    · 
礼貌的金鱼  ·  Django 安装 | 菜鸟教程·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams x_coarse, y_coarse = np.mgrid[0:5, 0:5] x_fine, y_fine = np.mgrid[1:4:0.23,1:4:0.23] data_coarse = np.ones([5,5]) rbfi = Rbf(x_coarse.ravel(), y_coarse.ravel(), data_coarse.ravel()) interpolated_data = rbfi(x_fine.ravel(), y_fine.ravel()).reshape([x_fine.shape[0], y_fine.shape[0]]) plt.imshow(interpolated_data)

the array interpolated_data has values ranging from 0.988 to 1.002 and the corresponding plot looks like this:

However, I would expect that in such a simple interpolation case, the interpolated values would be a lot closer to the correct value, i.e. 1.000.

I think the variations in the interpolated values are caused by the different distances from the interpolated points to the given data points.

My question is: Is there a way to avoid this behavior? How can I get an interpolation that is not weighted by the distance of the interpolated points to the data points and gives me nothing but 1.000 in interpolated_data ?

have a look on the first graph on this answer (similar example but in 1d): stackoverflow.com/a/51653039/8069403 . It looks like the same overshoot just before the last point. (The basis function is not the same.) Did you try griddata ? xdze2 Aug 6, 2018 at 9:19

An unwarranted expectation. The RBF interpolation, as its name says, uses radial basis functions. By default the basis function sqrt((r/epsilon)**2 + 1) where r is the distance from a data point and epsilon is a positive parameter. There is no way for a weighted sum of such functions to be identically constant. RBF interpolation isn't like a linear or bilinear interpolation. It's a rough interpolation suitable for rough data.

By setting an absurdly large epsilon, you can get closer to 1; just because it makes the basis functions nearly identical on the grid.

rbfi = Rbf(x_coarse.ravel(), y_coarse.ravel(), data_coarse.ravel(), epsilon=10)
# ... 
print(interpolated_data.min(), interpolated_data.max())
# outputs 0.9999983458255883 1.0000002402521204 

However this is not a good idea, because when the data is not constant, there will be too much long-range influence in the interpolant.

gives me nothing but 1.000 in interpolated_data?

That would be linear interpolation. LinearNDInterpolator has similar syntax to Rbf, in that it returns a callable.

linear = LinearNDInterpolator(np.stack((x_coarse.ravel(), y_coarse.ravel()), axis=-1), 
                              data_coarse.ravel())
interpolated_data = linear(x_fine.ravel(), y_fine.ravel()).reshape([x_fine.shape[0], y_fine.shape[0]])
print(interpolated_data.min(), interpolated_data.max())
# outputs 1.0 1.0 

There is also a griddata which has more interpolation modes.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.