# How to combine different kernels for Gaussian process in GPyTorch?

I am trying to learn gaussian process by using GPyTorch to fit a Gaussian Process Regression model. However, I can't figure out a way to combine different kernels as shown in sklearn implementation of gaussian process. I am using GPyTorch as it is more flexible and have lot more kernels that one can play with compared to scikit-learn. Any help, particularly with code snippet would be very useful.

Thank you.

From official documentation: For example, to compose two kernels via addition, you can either add the kernel modules directly:

self.covar_module = ScaleKernel(RBFKernel() + WhiteNoiseKernel())


Or you can add the outputs of the kernel in the forward method:

covar_x = self.rbf_kernel_module(x) + self.white_noise_module(x)


The class for GPRegressionModel would then look like this:

class GPRegressionModel(gpytorch.models.ExactGP):
def __init__(self, train_x, train_y, likelihood):
super(GPRegressionModel, self).__init__(train_x, train_y, likelihood)

self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = ScaleKernel(RBFKernel() + WhiteNoiseKernel())

def forward(self, x):
mean_x = self.mean_module(x)
covar_x = self.covar_module(x)
return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)

• are there any applied article which talks about the effect of these kernels and how to set them to achieve desired effect? Thanks – user62198 May 20 '19 at 16:27
• Applied not, but you maybe want to start with cs.toronto.edu/~duvenaud/cookbook. There are also good suggestions on further reading. – tadejk May 21 '19 at 12:30
• Good suggestion. Rasmussen and Williams is very good but takes time to understand it and code them up. – user62198 May 21 '19 at 16:22