【发布时间】:2019-08-22 20:31:27
【问题描述】:
我正在尝试使用多维输入数据在 GPFlow 中实现多输出 GP。
我从 GPflow 中的this issue 看到,通过“定义多维基础内核,然后在其上应用协同区域”,可以实现多维输入。
我已经编写了以下代码,我知道对于同位素数据(获得所有输出),可以使用this notebook 中描述的替代方法,但在这里我需要尝试 ICM,所以让我们继续使用下面的代码。
但是,当我尝试运行以下代码时:
from gpflow.gpr import GPR
import gpflow
import numpy as np
from gpflow.kernels import Coregion
def f(x):
def _y(_x):
function_sum = 0
for i in np.arange(0, len(_x) - 1):
function_sum += (1 - _x[i]) ** 2 + 100 * ((_x[i + 1] - _x[i] ** 2) ** 2)
return function_sum
return np.atleast_2d([_y(_x) for _x in (np.atleast_2d(x))]).T
isotropic_X = np.random.rand(100, 2) * 4 - 2
Y1 = f(isotropic_X)
Y2 = f(isotropic_X) + np.random.normal(loc=2000, size=(100,1))
Y3 = f(isotropic_X) + np.random.normal(loc=-2000, size=(100,1))
# a Coregionalization kernel. The base kernel is Matern, and acts on the first ([0]) data dimension.
# the 'Coregion' kernel indexes the outputs, and actos on the second ([1]) data dimension
k1 = gpflow.kernels.Matern32(2)
coreg = Coregion(1, output_dim=3, rank=1, active_dims=[3]) # gpflow.kernels.Coregion(2, output_dim=2, rank=1)
coreg.W = np.random.rand(3, 1)
kern = k1 * coreg
# Augment the time data with ones or zeros to indicate the required output dimension
X_augmented = np.vstack((np.hstack((isotropic_X, np.zeros(shape=(isotropic_X.shape[0], 1)))),
np.hstack((isotropic_X, np.ones(shape=(isotropic_X.shape[0], 1)))),
np.hstack((isotropic_X, 2 * np.ones(shape=(isotropic_X.shape[0], 1))))))
# Augment the Y data to indicate which likeloihood we should use
Y_augmented = np.vstack((np.hstack((Y1, np.zeros(shape=(Y1.shape[0], 1)))),
np.hstack((Y2, np.ones(shape=(Y2.shape[0], 1)))),
np.hstack((Y3, 2 * np.ones(shape=(Y3.shape[0], 1))))))
# now buld the GP model as normal
m = GPR(X_augmented, Y_augmented, kern=kern)
m.optimize()
print(m.predict_f(np.array([[0.2, 0.2, 0], [0.4, 0.4, 0]])))
它返回给我类似的东西:
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
Traceback (most recent call last):
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call
return fn(*args)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0] = 3 is not in [0, 3)
[[{{node name.build_likelihood/name.kern.K/name.kern.coregion.K/GatherV2}}]]
所以我的问题是:
- 这是什么问题以及如何启用多维输入的多输出GP
- 我没有完全从this multi-output gp slide 获得具有coregion 的gpflow 的工作流程,ICM 从潜在过程$u$ 的加法形式返回输出GP,该潜在过程$u$ 采样自按权重$W$ 参数化的GP。但是在 gpflow notebook demo 中,我看不到任何潜在的过程,笔记本上说“‘Coregion’内核对输出进行索引,并作用于增强 X 的最后一个 ([1]) 数据维度(索引) values',这与幻灯片完全不同,我对这些不同的描述感到很困惑,有什么提示吗?
【问题讨论】:
-
如果您查看您链接的 Mauricio Álvarez 幻灯片的第 19 张幻灯片(PDF 中的第 82 页),GPflow 中
Coregion内核的rank参数等效于 R 在那张幻灯片上。 GPflow 在 B 的参数化中添加了一个对角项,以确保它是正定的。潜在的 GP 被整合出来。
标签: gpflow