简体   繁体   English

来自 scipy.interpolate.Rbf 的意外结果

[英]Unexpected results from scipy.interpolate.Rbf

I am getting some errors when interpolating with RBF.使用 RBF 进行插值时出现一些错误。 Here is an example in 1D.这是 1D 中的示例。 I think that it has to do with how close my y values are to each other.我认为这与我的 y 值彼此之间的接近程度有关。 Is there any fix for this?有什么解决办法吗?

import numpy as np
from scipy.interpolate import Rbf, interp1d
import matplotlib.pyplot as plt

x = np.array([0.77639752, 0.8136646, 0.85093168, 0.88819876, 0.92546584, 0.96273292, 1.])
y = np.array([0.97119742, 0.98089758, 0.98937066, 0.99540737, 0.99917735, 1., 0.99779049])
xi = np.linspace(min(x),max(x),1000)

fig = plt.figure(1)
plt.plot(x,y,'ko', label='Raw Data')

#RBF
rbfi = Rbf(x,y, function='linear')
plt.plot(xi,rbfi(xi), label='RBF (linear)')

rbfi = Rbf(x,y, function='cubic')
plt.plot(xi,rbfi(xi), label='RBF (cubic)')

#1D
f = interp1d(x,y, kind='cubic')
plt.plot(xi,f(xi), label='Interp1D (cubic)')


plt.plot(x,y,'ko', label=None)
plt.grid()
plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.tight_layout()

plt.savefig('RBFTest.png')

在此处输入图片说明

Indeed, when implemented properly, RBF interpolation using the polyharmonic spline r^3 in 1D coincides with the natural cubic spline, and is a "smoothest" interpolant.实际上,如果实施得当,使用 1D 中的多谐波样条r^3 的 RBF 插值与自然三次样条重合,并且是“最平滑”的插值。

Unfortunately, the scipy.interpolate.Rbf, despite the name, does not appear to be a correct implementation of the RBF methods known from the approximation theory.不幸的是,尽管名称如此,scipy.interpolate.Rbf 似乎并不是近似理论中已知的 RBF 方法的正确实现。 The error is around the line错误就在这条线上

self.nodes = linalg.solve(self.A, self.di)

They forgot the (linear) polynomial term in the construction of the polyharmonic RBF!他们忘记了多谐 RBF 构造中的(线性)多项式项! The system should have been (2) .该系统应该是(2)

Now, one shouldn't trust interp1d blindly either.现在,人们也不应该盲目地相信interp1d What algorithm used in interp1d function in scipy.interpolate suggests that it may not be using natural cubic spline but a different condition. scipy.interpolate 中的 interp1d 函数中使用的算法表明它可能不是使用自然三次样条,而是使用不同的条件。 No mentioning of it in the help page: one needs to go into the python source, and I'm afraid of what we will find there.帮助页面中没有提到它:需要进入python源代码,我担心我们会在那里找到什么。

Is there a fix for this?有没有办法解决这个问题?

If it's a serious work, make your own implementation of the RBF interpolation algorithm.如果这是一项严肃的工作,请自行实现 RBF 插值算法。 Or, if you want to try a different implementation in python, there is apparently one from the University of Michigan: https://rbf.readthedocs.io .或者,如果您想在 python 中尝试不同的实现,显然有来自密歇根大学的一个: https : //rbf.readthedocs.io If you do, could you post your findings here?如果你这样做了,你能在这里发布你的发现吗? If not, you've already did a good service by demonstrating an important SciPy error -- thank you!如果没有,您已经通过演示一个重要的 SciPy 错误提供了很好的服务——谢谢!

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

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