我正试图在gpflow中实现我自己的多输出内核(MOK),
然而,我被(Kernel, Inducing Variable)
组合的多重分派所困扰
根据docs,组合MultioutputKernel
和InducingPoints
的回退方法应该是调用fully_correlated_conditional
(通过gpf.conditionals.multioutput.inducing_point_conditional
)
然而,我不能让任何MOK处理非独立的诱导变量,即使是预实现的变量。
下面是SharedIndependent
的一个最低限度不起作用的示例:
######################## toy data
d = 1
X = np.random.normal(0, 10, (100, d))
xx = np.linspace(-10, 10, 200).reshape(-1, 1)
f = lambda x: x ** 2
f_ = lambda x: 2 * x
Y = f(X)
Y_ = f_(X)
Y_combined = np.hstack((Y, Y_))
data = (X, Y_combined)
######################### gpflow stuff
kernel = gpf.kernels.RBF(lengthscales=[1.0] * d)
Z = X.copy()
# create multi-output inducing variables from Z
iv = gpf.inducing_variables.InducingPoints(Z)
MOK_K = gpf.kernels.SharedIndependent(kernel, output_dim=2)
m = gpf.models.SVGP(likelihood=gpf.likelihoods.Gaussian(), kernel=MOK_K, num_latent_gps=2,
inducing_variable=iv)
optimizer = gpf.optimizers.Scipy()
optimizer.minimize(
m.training_loss_closure(data),
variables=m.trainable_variables,
method="l-bfgs-b",
options={"disp": True, "maxiter": 1000},
)
这是不起作用的,除非你用
iv = gpf.inducing_variables.SharedIndependentInducingVariables(
gpf.inducing_variables.InducingPoints(Z)
)
但是对于我的自定义非独立内核,我需要完全相关的条件。 我得到的错误是
ValueError: base_conditional() arguments [Note that this check verifies the shape of an alternative representation of Kmn. See the docs for the actual expected shape.]
在inducing_point_conditional
方法中,它似乎试图将内核矩阵“展平”(到2d)到经典的多输出表示,然后再将其传递到base_conditional
。然而,我不明白哪里出了问题,因为形状应该是好的。它们与文档中的定义相同
为了让它运行在完全相关的条件下,我需要做什么更改
问题是变分分布参数的维数,
q_mu
和q_sqrt
必须事先手动定义它们,以便它们分别具有
[N*P, 1]
和[1, N*P, N*P]
的形状,其中p是输出维度(在我的示例中为2)请注意,这与文档略有不同,它们说
q_mu
必须是[1, N*P]
我的问题代码在以下情况下正确运行:
相关问题 更多 >
编程相关推荐