scipy.interpolate.Rbf的意外结果 [英] Unexpected results from scipy.interpolate.Rbf

查看:418
本文介绍了scipy.interpolate.Rbf的意外结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用RBF进行插值时出现一些错误.这是一维的示例.我认为这与我的y值之间的接近程度有关.有什么解决办法吗?

I am getting some errors when interpolating with RBF. Here is an example in 1D. I think that it has to do with how close my y values are to each other. 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.

不幸的是,尽管名称如此,scipy.interpolate.Rbf似乎并不是从近似理论已知的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. The error is around the line

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

他们忘记了多谐波RBF的构造中的(线性)多项式项!该系统应为(2).

They forgot the (linear) polynomial term in the construction of the polyharmonic RBF! The system should have been (2).

现在,也不应该盲目地信任interp1d. 在scipy.interpolate中的interp1d函数中使用了什么算法表明它可能不是使用自然三次样条,而是使用了不同的条件.在帮助页面中没有提及它:一个需要进入python源,我担心在那里会发现什么.

Now, one shouldn't trust interp1d blindly either. What algorithm used in interp1d function in scipy.interpolate suggests that it may not be using natural cubic spline but a different condition. 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.

是否有此解决方法?

Is there a fix for this?

如果这是一项严肃的工作,请自行实现RBF插值算法.或者,如果您想尝试使用python的其他实现,则显然是密歇根大学的一个实现: https://rbf .readthedocs.io .如果这样做,您可以在这里发布您的发现吗?如果没有,那么您将通过显示一个重要的SciPy错误来为您提供良好的服务-谢谢!

If it's a serious work, make your own implementation of the RBF interpolation algorithm. Or, if you want to try a different implementation in python, there is apparently one from the University of Michigan: 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.interpolate.Rbf的意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆