高斯进展回归:错误的预测

Gaussian progress regression: wrong prediction

我的输入由长度为 10 的 xy 组成。我想训练我的 GP,以便它可以预测相应的 z。但是不知何故,在训练之后,预测的 z 值与应有的值有很大不同。到目前为止,我已经尝试了不同长度尺度的不同内核,但预测仍然相差太多。如果有任何提示和建议,我将不胜感激。

import gpflow
import numpy as np
import matplotlib
from gpflow.utilities import print_summary
import math
import socket
import pickle
import time
import matplotlib.pyplot as plt
import select
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors

from mpl_toolkits.mplot3d import Axes3D
def objective_closure():
    return - m.log_marginal_likelihood()

x =[9.953, 15.12, 20.29, 25.44, 30.6, 35.74, 40.88, 46.01, 51.14, 56.26]
y =[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
z =[100.5619, 99.8705, 98.7587, 97.2267, 95.2744, 92.9017, 90.1087, 86.8954, 83.2618, 79.2079]

x_np= np.reshape(x[0:10],(-1,1))
y_np= np.reshape(y[0:10],(-1,1))
z_np= np.reshape(z[0:10],(-1,1))

X = np.array([x_np, y_np]).T[0]
Y = z_np

k = gpflow.kernels.SquaredExponential()
m = gpflow.models.GPR(data=(X, Y), kernel=k)


m.likelihood.variance.assign(0.01)
m.kernel.lengthscale.assign(0.1)

print_summary(m)
opt = gpflow.optimizers.Scipy()
opt_logs = opt.minimize(objective_closure,
                        m.trainable_variables, 
                        options=dict(maxiter=100))
print_summary(m)
################################################################## Done with generating GPR

## generate samples
xx = np.linspace(x_np.min(), x_np.max(), 2).reshape(-1, 1)  # test points must be of shape (N, D)
yy = np.linspace(y_np.min(), y_np.max(), 2).reshape(-1, 1)  # test points must be of shape (N, D)

test_points = np.array([xx, yy]).T[0]


## predict mean and variance of latent GP at test points
mean, var = m.predict_f(test_points)

## generate 10 samples from posterior
samples = m.predict_f_samples(test_points, 2)  


###########plot 
ax = plt.axes(projection="3d")
ax.scatter3D(X[:,0],X[:,1], Y, cmap='hsv')
for idx,val in enumerate(samples):

    ax.scatter3D(xx,yy,samples[idx], c="black")

ax.set_xlabel('X_axis')
ax.set_ylabel('Y_axis')
ax.set_zlabel('Z_axis')
plt.show()

用于训练的数据集图 (Blue) 和预测值 (Black)。

训练前后GP模型参数:

您可以修复您的似然方差,使其无法使用

进行训练

gpflow.utilities.set_trainable(m.likelihood.variance, False)

但更好的方法是只切换内核,因为你的内核似乎不够。


k1 = gpflow.kernels.SquaredExponential(lengthscales = [0.1], active_dims=[0])
k2 = gpflow.kernels.SquaredExponential(lengthscales = [0.1], active_dims=[1])

m = gpflow.models.GPR(data=(X, Y), kernel=k1+k2)


m.likelihood.variance.assign(0.01)