具有多个变量的高斯过程回归:核的适应

Gaussian Process Regression with multiple variables: adaptation of kernels

好的,所以我知道这个问题已经被问了很多,但我似乎找不到任何解释性的、好的答案。 我的问题本身很简单:在使用多变量输入 X 执行高斯过程回归时,如何指定哪个内核适用于哪个变量?

举个例子可能会更清楚。看下面的代码:

import matplotlib as mpl
mpl.use('TkAgg')
from matplotlib import pyplot as plt
import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF
from sklearn.gaussian_process.kernels import ExpSineSquared, WhiteKernel, ConstantKernel

np.random.seed(0)

X = np.array([[0, 1, 2], [1, 3, 4], [2, 5, 1], [3, 7, 5], [4, 9, 7], [5, 0, 8], [6, 1, 2], [7, 3, 4], [8, 5, 1],
              [9, 7, 5], [10, 9, 7], [11, 0, 8], [12, 1, 2], [13, 3, 4], [14, 5, 1], [15, 7, 5],
              [16, 9, 7], [17, 9, 8]])

y = np.random.uniform(200, 300, len(X))

gp_kernel = 1**2*RBF(length_scale=[0, 0.01, 0]) * ExpSineSquared(0.02, 6, periodicity_bounds='fixed') + WhiteKernel()

gpr = GaussianProcessRegressor(kernel=gp_kernel, n_restarts_optimizer=2, normalize_y=True)
gpr.fit(X, y)

X1 = np.vstack((X, np.array([18, 3, 5])))
y_pred, sigma = gpr.predict(X1, return_std=True)

print(y_pred)
plt.plot(range(len(X)), y)
plt.plot(range(len(X1)), y_pred)
plt.show()

如果你看一下 X,就会发现它在二维空间中显然是周期性的。我想具体说明一下,所以我的第一次尝试是这样的 ExpSineSquared([0, 0.2, 0], 6, periodicity_bounds='fixed'),我复制了我找到​​的针对此类问题的大部分答案的方法,并为内核所做的变量设置了 0不举行。但遗憾的是,ExpSineSquared 不允许将数组作为 length_scale 参数的输入。

因此,我尝试将它与允许这样做的东西相乘,例如 RBF,然后查看结果。这确实给了我一些预测,但是如果我们改变 gp_kernel = 1**2*RBF(length_scale=[0, 0.01, 0]) * ExpSineSquared(0.02, 6, periodicity_bounds='fixed') + WhiteKernel()gp_kernel = 1**2*RBF(length_scale=[0.01, 0, 0]) * ExpSineSquared(0.02, 6, periodicity_bounds='fixed') + WhiteKernel(), 结果保持完全相同,这不可能是正确的(第一个维度远不是周期性的),所以你会期望一些更糟或至少不同的结果。

简而言之:如果您有一个多变量输入并且构建了适用于某些但不是所有变量的内核,那么如何指定哪个内核适用于哪个变量?

我发现 George 包在这种情况下非常有用。首先,您可以使用 lot 个更多的各向异性内核,这是一个很大的优势。其次,您可以指定它们作用于哪个维度。例如,ExpSquaredKernel(length_scale=1, ndim=4, axes=1) 是一个 RBF 内核,它作用于的第二个维度(参见轴参数)。由 4 个维度组成的数据。