scipy.interpolate.LinearNDInterpolator not producing desired functionality

牧云@^-^@ 提交于 2019-12-06 16:45:43

From http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html:

The interpolant is constructed by triangulating the input data with Qhull [R15], and on each triangle performing linear barycentric interpolation.

In your case, the triangles chosen appear to share the (0,0), (1,1) edge. Since (0.5, 0.5) is midway between (0,0) and (1,1), the interpolated value lies between the values at those vertices, so it is (0+4)/2 = 2.0.

Dan H

Because your four input points are co-circular, the underlying Delaunay triangulation is ambiguous; you might end up with an "edge" from (0,0) to (1,1), OR one along the "other diagonal", from (1,0) to (0,1).

In the first case, the interpolation of (0.5,0.5) will yield 2.0, in the latter case it will yield 1.5. You don't have control over which one you get.

If you want that control, you have two options:

1) supply the triangulation expressly by giving the interpolator an object that looks like one returned by the Delauney triangulation.

2) "nudge" one of your corners toward the center. For example, use (0.99999,0.99999) instead of (1,1); this will "force" the Delaunay triangulation to a deterministic outcome. (In this case, it would "force" the use of the (0,0) to (0.99999,0.99999) segment over the other diagonal.)

And, FWIW, I think it is no coincidence that the average of these two possible values (1.5 and 2.0) is what you observed when you used bilinear interpolation; I think that is expected, mathematically.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!