scipy.interpolate.Rbf 的意外结果

问题描述 投票:0回答:2

使用 RBF 插值时出现一些错误。这是一维的示例。我认为这与我的 y 值彼此之间的接近程度有关。有没有办法解决这个问题?

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')

python scipy interpolation
2个回答
5
投票

事实上,如果正确实施,在一维中使用多调和样条线 r^3 进行 RBF 插值与自然三次样条线一致,并且是“最平滑”插值。

不幸的是,scipy.interpolate.Rbf,尽管有这个名字,似乎并不是近似理论中已知的 RBF 方法的正确实现。错误在线

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

他们忘记了构建多调和 RBF 时的(线性)多项式项!该系统应该是(2)

现在,人们也不应该盲目信任

interp1d
scipy.interpolate中的 interp1d 函数使用的算法表明它可能没有使用natural三次样条,而是使用不同的条件。帮助页面中没有提及它:需要进入 python 源代码,我担心我们会在那里找到什么。

这个问题有解决办法吗?

如果这是一项严肃的工作,请自行实现 RBF 插值算法。或者,如果您想在 python 中尝试不同的实现,显然密歇根大学有一个:https://rbf.readthedocs.io。如果你这样做,你能在这里发布你的发现吗?如果没有,您已经通过演示重要的 SciPy 错误提供了良好的服务 - 谢谢!


0
投票

scipy.interpolate.Rbf

此类被视为遗留类,将不再接收更新。 这也可能意味着它将在未来的 SciPy 版本中被删除。 RBF 是遗留代码,对于新用途,请改用 RBFInterpolator。

使用 scipy.interpolate.RBFInterpolator

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 linear
rbfi = Rbf(x,y, function='linear')
plt.plot(xi,rbfi(xi), label='RBF (linear)')

#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()

#RBF cubic
from scipy.interpolate import RBFInterpolator
rbi =  RBFInterpolator(x[:, np.newaxis],y[:, np.newaxis], kernel= 'cubic' )   # radial basis function interpolator instance
fi= rbi(xi[:, np.newaxis])       # interpolated values
plt.plot(xi, fi, label='RBF_Interpolator (cubic)')
plt.legend()

plt.xlabel('x')
plt.ylabel('y')
plt.tight_layout()
plt.show()

© www.soinside.com 2019 - 2024. All rights reserved.