【发布时间】:2020-03-12 16:42:36
【问题描述】:
我已经在平面图上为传感器之间的温度数据实现了 2 种类型的插值。由于我对我使用的软件包的底层流程和数学不是很精通,我发现很难理解为什么它们通过 pcolormesh 的输出如此不同。
我使用了scipy.interpolate.Rbf 和sklearn.gaussian_process。
这些是图片。
Radial Basis Function interpolation
RBF 示例看起来与网络上的实现完全一样,但 GPR 显示的是这些长线而不是圆形。在 Scikit learn 的 GPR 实现中,什么参数可以调节这些形状?为什么当 GPR 的温度结果发生轻微变化时,它们的形状甚至有时颜色强度会如此不同。
平面图上的 9 个传感器(点)均匀分布。
RBF 代码。
# Set X and Y Coordinates for each sensor (pixels)
days_data['xCoordinate'] = days_data.nodeid.apply(lambda id: createXCoord(id))
days_data['yCoordinate'] = days_data.nodeid.apply(lambda id: createYCoord(id))
# Define location of "sensors" on the axes
x = days_data.xCoordinate.to_list()
y = days_data.yCoordinate.to_list()
z = days_data.avgtemperature.to_list() #temperature
# Use Gaussian function
rbf_adj = Rbf(x, y, z, function = 'gaussian')
# Set extent to which colour mesh stretches over
# the underlying image
x_fine = np.linspace(0, 1000, 81) #81 - num of samples
y_fine = np.linspace(0, 700, 81)
x_grid, y_grid = np.meshgrid(x_fine, y_fine)
z_grid = rbf_adj(x_grid.ravel(), y_grid.ravel()).reshape(x_grid.shape)
# Remove the colorbar created by the previous plot, if any
# To avoid a new colorbar being plotted alongside the previous one each time a different date is selected
try:
cb = p.colorbar
cb.remove()
except:
pass
# plot the pcolor on the Axes. Use alpha to set the transparency
p=ax.pcolor(x_fine, y_fine, z_grid, alpha=0.3)
ax.invert_yaxis() #invert Y axis for X and Y to have same starting point
# Add a colorbar for the pcolor field
fig.colorbar(p,ax=ax)
GPR 代码
# Define location of "sensors" on the axes
x = days_data.xCoordinate.to_list()
y = days_data.yCoordinate.to_list()
z = days_data.avgtemperature.to_list() #temperature
X = np.array([[a, b] for a, b in zip(x, y)])
# Set extent to which colour mesh stretches over
# the underlying image
x_fine = np.linspace(0, 1000, 81) #81 - num of samples
y_fine = np.linspace(0, 700, 82)
X_fine = np.array([[a_fine, b_fine] for a_fine, b_fine in zip(x_fine, y_fine)])
x_grid, y_grid = np.meshgrid(x_fine, y_fine)
# Instantiate a Gaussian Process model
kernel = C(1.0, (1e-3, 1e3)) * RBF(10, (1e-2, 1e2))
gp = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=9)
# Fit to data using Maximum Likelihood Estimation of the parameters
gp.fit(X, z)
z_grid, sigma = gp.predict(X_fine, return_std=True)
# Remove the colorbar created by the previous plot, if any
# To avoid a new colorbar being plotted alongside the previous one each time a different date is selected
try:
cb = p.colorbar
cb.remove()
except:
pass
# plot the pcolor on the Axes. Use alpha to set the transparency
p = ax.pcolor(x_grid, y_grid, np.meshgrid(z_grid, y_fine)[0], alpha=0.3)
ax.invert_yaxis() #invert Y axis for X and Y to have same starting point
# Add a colorbar for the pcolor field
fig.colorbar(p,ax=ax)
【问题讨论】:
-
在GPR代码中,你为什么使用
np.meshgrid(z_grid, y_fine)[0]作为pcolor的第三个参数?
标签: python scikit-learn scipy interpolation