GPflow多维变点核问题

huangapple go评论106阅读模式
英文:

GPflow change point kernel issue with multiple dimensions

问题

I'm following the tutorial here for implementing a change point kernel in gpflow.
我正在按照此处的教程来实现在gpflow中使用变点核。

However, I have 3 inputs and 1 output and I would like the changepoint kernel to be on the first input dimension only and other standard kernels to be on the other two input dimensions.
然而,我有3个输入和1个输出,并且我希望变点核只作用在第一个输入维度上,而其他标准核作用在其他两个输入维度上。

I'm getting the following error:
我遇到了以下错误:

InvalidArgumentError: Incompatible shapes: [2000,3,1] vs. [3,2000,1] [Op:Mul] name: mul/

Below is a minimum working example. Could anyone please let me know where I'm going wrong?
以下是一个最小的工作示例。有人能告诉我我哪里出错了吗?

gpflow version 2.0.0.rc1
gpflow版本2.0.0.rc1

import pandas as pd
import gpflow
from gpflow.utilities import print_summary

df_all = pd.read_csv(
    'https://raw.githubusercontent.com/ipan11/gp/master/dataset.csv')

# Training dataset in numpy format
X = df_all[['X1', 'X2', 'X3']].to_numpy()
Y1 = df_all['Y'].to_numpy().reshape(-1, 1)

# Changepoint kernel only on the first dimension and standard kernels for the other two dimensions
# 变点核只作用在第一个维度上,其他两个维度上使用标准核
base_k1 = gpflow.kernels.Matern32(lengthscale=0.2, active_dims=[0])
base_k2 = gpflow.kernels.Matern32(lengthscale=2., active_dims=[0])
k1 = gpflow.kernels.ChangePoints(
    [base_k1, base_k2], [.4], steepness=5)

k2 = gpflow.kernels.Matern52(lengthscale=[1., 1.], active_dims=[1, 2])
k_all = k1 + k2
print_summary(k_all)

m1 = gpflow.models.GPR(data=(X, Y1), kernel=k_all, mean_function=None)
print_summary(m1)
opt = gpflow.optimizers.Scipy()

def objective_closure():
    return -m1.log_marginal_likelihood()

opt_logs = opt.minimize(objective_closure, m1.trainable_variables,
                        options=dict(maxiter=100))
英文:

I'm following the tutorial here for implementing a change point kernel in gpflow.
However, I have 3 inputs and 1 output and I would like the changepoint kernel to be on the first input dimension only and other standard kernels to be on the other two input dimensions. I'm getting the following error :

InvalidArgumentError: Incompatible shapes: [2000,3,1] vs. [3,2000,1] [Op:Mul] name: mul/

Below is a minimum working example. Could anyone please let me know where I'm going wrong?

gpflow version 2.0.0.rc1

import pandas as pd
import gpflow
from gpflow.utilities import print_summary


df_all = pd.read_csv(
    'https://raw.githubusercontent.com/ipan11/gp/master/dataset.csv')

# Training dataset in numpy format
X = df_all[['X1', 'X2', 'X3']].to_numpy()
Y1 = df_all['Y'].to_numpy().reshape(-1, 1)


# Changepoint kernel only on first dimension and standard kernels for the other two dimensions
base_k1 = gpflow.kernels.Matern32(lengthscale=0.2, active_dims=[0])
base_k2 = gpflow.kernels.Matern32(lengthscale=2., active_dims=[0])
k1 = gpflow.kernels.ChangePoints(
    [base_k1, base_k2], [.4], steepness=5)

k2 = gpflow.kernels.Matern52(lengthscale=[1., 1.], active_dims=[1, 2])
k_all = k1+k2
print_summary(k_all)

m1 = gpflow.models.GPR(data=(X, Y1), kernel=k_all, mean_function=None)
print_summary(m1)
opt = gpflow.optimizers.Scipy()


def objective_closure():
    return -m1.log_marginal_likelihood()


opt_logs = opt.minimize(objective_closure, m1.trainable_variables,
                        options=dict(maxiter=100))

答案1

得分: 1

正确的答案是将 active_dims=[0]base_k* 内核移动到 ChangePoints() 内核中,

k1 = gpflow.kernels.ChangePoints([base_k1, base_k2], [0.4], steepness=5, active_dims=[0])

但是目前 GPflow 2 不支持这个,这是一个 bug。我已经在 GitHub 上开了一个问题,一旦修复了,我会更新这个答案(如果你有兴趣尝试修复这个 bug,欢迎提交拉取请求,我们随时欢迎帮助!)。

英文:

The correct answer would be to move the active_dims=[0] from the base_k* kernels to the ChangePoints() kernel,

k1 = gpflow.kernels.ChangePoints([base_k1, base_k2], [0.4], steepness=5, active_dims=[0])

but this is currently not supported in GPflow 2, which is a bug. I've opened an issue on github, and will update this answer once it's fixed (if you feel up to having a go at fixing this bug, feel free to open a pull request, help always welcome!).

huangapple
  • 本文由 发表于 2020年1月6日 22:17:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613675.html
  • gpflow
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定