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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.