首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多输入多输出GP?

多输入多输出GP?
EN

Stack Overflow用户
提问于 2019-08-05 15:31:59
回答 1查看 1K关注 0票数 3

我试图用多维输入数据在GPFlow中实现多输出GP .

我从本期在GPflow中看到,多维输入可以通过‘定义多维基内核,然后在此基础上应用define’来实现。

我已经编写了以下代码,我知道对于同位素数据(所有的输出都是获得的),可以使用类似于这个笔记本中描述的东西,但是在这里,由于我需要尝试ICM,所以让我们继续下面的代码。

但是,当我尝试运行以下代码时:

代码语言:javascript
复制
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]])))

它给我的回报是:

代码语言:javascript
复制
  "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}}]]

所以我的问题是:

代码语言:javascript
复制
 - What is this problem and how to enable multi-output GP with multi-dimension input
 - I didn't quite get the workflow of gpflow with coregion, from [this multi-output gp slide](http://gpss.cc/gpss17/slides/multipleOutputGPs.pdf), The ICM returns output GP from a additive form of a latent process $u$ sampled from a GP parameterized by its weight $W$. But in the gpflow [notebook demo](https://nbviewer.jupyter.org/github/GPflow/GPflow/blob/develop/doc/source/notebooks/advanced/coregionalisation.ipynb) I can't see any latent process of that and the notebooks says 'The 'Coregion' kernel indexes the outputs, and acts on the last ([1]) data dimension (indices) of the augmented X values', which is quite different than the slides, I am really confused about these different descriptions, any hint on these?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-05 15:59:43

问题仅仅在于您的偏移索引:共同区域化内核应该是

代码语言:javascript
复制
coreg = Coregion(input_dim=1, output_dim=3, rank=1, active_dims=[2])

因为active_dims=[2]索引第三列。

谢谢你提供了一个完全可复制的例子!我成功地运行了您的代码,并成功地使用AdamOptimizer和ScipyOptimizer的几个步骤对模型进行了优化,其日志似然值为-2023.4。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57361754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档