muygps_layer

MuyGPs PyTorch implementation

class MuyGPyS.torch.muygps_layer.MuyGPs_layer(muygps_model, batch_indices, batch_nn_indices, batch_targets, batch_nn_targets)[source]

MuyGPs model written as a custom PyTorch layer using nn.Module.

Implements the MuyGPs algorithm as articulated in [muyskens2021muygps]. See documentation on MuyGPs class for more detail.

The MuyGPs_layer class only supports the Matern kernel currently. More kernels will be added to the torch module of MuyGPs in future releases.

PyTorch does not currently support the Bessel function required to compute the Matern kernel for non-special case smoothness values of \(\nu\), e.g. 1/2, 3/2, 5/2, and \(\infty\). The MuyGPs layer allows the lengthscale parameter \(\rho\) to be trained (provided an initial value by the user) as well as the homoscedastic \(\tau^2\) noise prior variance.

The MuyGPs layer returns the posterior mean, posterior variance, and a vector of \(\sigma^2\) indicating the scale parameter associated with the posterior variance of each dimension of the response.

Example

>>> from MuyGPyS.torch.muygps_layer import MuyGPs_layer
>>> muygps_model = MuyGPS(
...     Matern(
...         smoothness=ScalarParam(0.5),
...         deformation=Isotropy(
...             metric=l2,
...             length_scale=ScalarParam(1.0)
...         ),
...     ),
...     noise=HomoscedasticNoise(1e-5),
... )
>>> batch_indices = torch.arange(100,)
>>> batch_nn_indices = torch.arange(100,)
>>> batch_targets = torch.ones(100,)
>>> batch_nn_targets = torch.ones(100,)
>>> muygps_layer_object = MuyGPs_layer(
... muygps_model,
... batch_indices,
... batch_nn_indices,
... batch_targets,
... batch_nn_targets)
Parameters:
  • muygps_model (MuyGPS) – A MuyGPs object providing the Gaussian Process final layer.

  • batch_indices – A torch.Tensor of shape (batch_count,) containing the indices of the training data to be sampled for training.

  • batch_nn_indices – A torch.Tensor of shape (batch_count, nn_count) containing the indices of the k nearest neighbors of the batched training samples.

  • batch_targets – A torch.Tensor of shape (batch_count, response_count) containing the responses corresponding to each batched training sample.

  • batch_nn_targets – A torch.Tensor of shape (batch_count, nn_count, response_count) containing the responses corresponding to the nearest neighbors of each batched training sample.

  • kwargs – Addition parameters to be passed to the kernel, possibly including additional hyperparameter dicts and a metric keyword.

forward(x)[source]

Produce the output of a MuyGPs custom PyTorch layer.

Returns:

  • predictions – A torch.ndarray of shape (batch_count, response_count) whose rows are the predicted response for each of the given batch feature.

  • variances – A torch.ndarray of shape (batch_count,response_count) consisting of the diagonal elements of the posterior variance.