我用interp1d適合三次樣條,但遇到一些memmory問題,所以按照以下question我已切換到使用InterpolatedUnivariateSpline。但是,我注意到在結果函數之間存在一些(非常)小的差異。因此我的問題是;稍有不同的結果interp1d
答:根據這個answer,據我所知它與底層方法(使用FITPACK或不)有什麼不同。但是,如果底層數學不一樣?
B.是否有可能使用InterpolatedUnivariateSpline重新生成interp1d結果(更改平滑樣條函數的程度或邊界只會使兩個圖形更加不同)?
最小代碼重現的細微差別:
from scipy.interpolate import interp1d
from scipy.interpolate import InterpolatedUnivariateSpline
import matplotlib.pyplot as plt
import matplotlib
import numpy
x = [916.03189697265634, 916.0718969726563, 916.11189697265627, 916.15189697265623, 916.1918969726562, 916.23189697265627, 916.27189697265624, 916.31189697265631, 916.35189697265628, 916.39189697265624, 916.4318969726562, 916.47189697265628, 916.51189697265625, 916.55189697265632, 916.59189697265629, 916.63189697265625, 916.67189697265621, 916.71189697265618]
y = [893483.0, 2185234.0, 3903053.0, 4264327.0, 3128900.0, 1374942.0, 554350.0, 442512.0, 414232.0, 403098.0, 413778.0, 264185.0, 363063.0, 473762.0, 452284.0, 526806.0, 461402.0, 424270.0]
newX = numpy.linspace(x[0],x[-1],2500*(x[-1]-x[0]))
f_interp1d = interp1d(x,y, kind='cubic')
f_Univariate = InterpolatedUnivariateSpline(x,y)
yINTER = f_interp1d(newX)
yUNIVAR = f_Univariate(newX)
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot(x,y,'b*')
plt.plot(newX,yINTER,'r--')
plt.plot(newX,yUNIVAR,'g--')
plt.legend(['Raw Data','Interp1d','Univariate Spline'],loc='best')
plt.show()
產生下列圖表(貌似精細):
然而,鑑於一個靠近顯示是有區別的: