How to apply constraint on parameters in various GP libraries

Apply constraints in GPy, GPFlow, GPyTorch
Author

Zeel B Patel

Published

September 27, 2021

import numpy as np
import torch
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font', **{'size':18})

GPy

from paramz.transformations import Logexp
gpy_trans = Logexp()
x = torch.arange(-1000,10000).to(torch.float)
plt.plot(x, gpy_trans.f(x));
plt.xlabel('X')
plt.ylabel('f(X)');

GPyTorch

from gpytorch.constraints import Positive
gpytorch_trans = Positive()
plt.plot(x, gpytorch_trans.transform(x));
plt.xlabel('X')
plt.ylabel('f(X)');

GPFlow

from gpflow.utilities.bijectors import positive
gpflow_trans = positive()
plt.plot(x, gpflow_trans(x));
plt.xlabel('X')
plt.ylabel('f(X)');

np.allclose(gpy_trans.f(x), gpytorch_trans.transform(x))
True
np.allclose(gpy_trans.f(x), gpflow_trans(x))
True