geometric_kernels.frontends.gpytorch

GPyTorch kernel wrapper.

A tutorial on how to use this wrapper to run Gaussian process regression on a geometric space is available in the frontends/GPyTorch.ipynb notebook.

Module Contents

class geometric_kernels.frontends.gpytorch.GPyTorchGeometricKernel(base_kernel, lengthscale=None, nu=None, trainable_nu=False, **kwargs)[source]

Bases: gpytorch.kernels.Kernel

GPyTorch wrapper for BaseGeometricKernel.

A tutorial on how to use this wrapper to run Gaussian process regression on a geometric space is available in the frontends/GPyTorch.ipynb notebook.

Note

Remember that the base_kernel itself does not store any of its hyperparameters (like lengthscale and nu). If you do not set them manually—when initializing the object or after, by setting the properties—this wrapper will use the values provided by base_kernel.init_params.

Note

As customary in GPyTorch, this wrapper does not maintain a variance (outputscale) parameter. To add it, use gpytorch.kernels.ScaleKernel(GPyTorchGeometricKernel(...)).

Parameters:
  • base_kernel (geometric_kernels.kernels.BaseGeometricKernel) – The kernel to wrap.

  • lengthscale (beartype.typing.Union[float, torch.Tensor, numpy.ndarray]) –

    Initial value of the length scale.

    If not given or set to None, uses the default value of the base_kernel, as provided by its init_params method.

  • nu (beartype.typing.Union[float, torch.Tensor, numpy.ndarray]) –

    Initial value of the smoothness parameter nu.

    If not given or set to None, uses the default value of the base_kernel, as provided by its init_params method.

  • trainable_nu (bool) –

    Whether or not the parameter nu is to be optimized over.

    Cannot be True if nu is equal to infinity. You cannot change this parameter after constructing the object. Defaults to False.

Raises:

ValueError – If trying to set nu = infinity together with trainable_nu = True.

property nu: torch.Tensor[source]

The smoothness parameter

Return type:

torch.Tensor

property space: beartype.typing.Union[geometric_kernels.spaces.Space, beartype.typing.List[geometric_kernels.spaces.Space]][source]

Alias to the base_kernels space property.

Return type:

beartype.typing.Union[geometric_kernels.spaces.Space, beartype.typing.List[geometric_kernels.spaces.Space]]

__init__(base_kernel, lengthscale=None, nu=None, trainable_nu=False, **kwargs)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
forward(x1, x2, diag=False, last_dim_is_batch=False, **kwargs)[source]

Evaluate the covariance matrix K(x1, x2).

Parameters:
  • x1 (torch.Tensor) – First batch of inputs.

  • x2 (torch.Tensor) – Second batch of inputs.

  • diag (bool) – If set to True, ignores x2 and returns the diagonal of K(x1, x1).

  • last_dim_is_batch (bool) – Ignored.

Returns:

The covariance matrix K(x1, x2) or, if diag=True, the diagonal of the covariance matrix K(x1, x1).

Return type:

torch.Tensor