aepsych.kernels

Submodules

aepsych.kernels.rbf_partial_grad module

class aepsych.kernels.rbf_partial_grad.RBFKernelPartialObsGrad(ard_num_dims=None, batch_shape=None, active_dims=None, lengthscale_prior=None, lengthscale_constraint=None, eps=1e-06, **kwargs)[source]

Bases: RBFKernelGrad

An RBF kernel over observations of f, and partial/non-overlapping observations of the gradient of f.

gpytorch.kernels.rbf_kernel_grad assumes a block structure where every partial derivative is observed at the same set of points at which x is observed. This generalizes that by allowing f and any subset of the derivatives of f to be observed at different sets of points.

The final column of x1 and x2 needs to be an index that identifies what is observed at that point. It should be 0 if this observation is of f, and i if it is of df/dxi.

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

Parameters:
  • ard_num_dims (Optional[int]) –

  • batch_shape (Optional[torch.Size]) –

  • active_dims (Optional[Tuple[int, ...]]) –

  • lengthscale_prior (Optional[Prior]) –

  • lengthscale_constraint (Optional[Interval]) –

  • eps (float) –

forward(x1, x2, diag=False, **params)[source]

Computes the covariance matrix between x1 and x2 based on the RBF

Parameters:
  • x1 (torch.Tensor) – A b x n x d or n x d tensor, where d = 2k and k is the dimension of the latent space.

  • x2 (torch.Tensor) – A b x m x d or m x d tensor, where d = 2k and k is the dimension of the latent space.

  • diag (bool) – Should the Kernel compute the whole covariance matrix (False) or just the diagonal (True)? Defaults to False.

  • params (Any) –

Returns:

A b x n x m or n x m tensor representing the covariance matrix between x1 and x2. The exact size depends on the kernel’s evaluation mode: * full_covar: n x m or b x n x m * diag: n or b x n

Return type:

torch.Tensor

num_outputs_per_input(x1, x2)[source]

For most kernels, num_outputs_per_input = 1.

However, some kernels (e.g. multitask kernels or interdomain kernels) return a num_outputs_per_input x num_outputs_per_input matrix of covariance values for every pair of data points.

I.e. if x1 is size … x N x D and x2 is size … x M x D, then the size of the kernel will be … x (N * num_outputs_per_input) x (M * num_outputs_per_input).

Returns:

num_outputs_per_input (usually 1).

Parameters:
  • x1 (Tensor) –

  • x2 (Tensor) –

Return type:

int

Module contents

class aepsych.kernels.PairwiseKernel(latent_kernel, is_partial_obs=False, **kwargs)[source]

Bases: Kernel

Wrapper to convert a kernel K on R^k to a kernel K’ on R^{2k}, modeling functions of the form g(a, b) = f(a) - f(b), where f ~ GP(mu, K).

Since g is a linear combination of Gaussians, it follows that g ~ GP(0, K’) where K’((a,b), (c,d)) = K(a,c) - K(a, d) - K(b, c) + K(b, d).

Parameters:
  • latent_kernel (Kernel) – The underlying kernel used to compute the covariance for the GP.

  • is_partial_obs (bool) – If the kernel should handle partial observations. Defaults to False.

forward(x1, x2, diag=False, **params)[source]

TODO: make last_batch_dim work properly

d must be 2*k for integer k, k is the dimension of the latent space

Parameters:
  • x1 (torch.Tensor) – A b x n x d or n x d tensor, where d = 2k and k is the dimension of the latent space.

  • x2 (torch.Tensor) – A b x m x d or m x d tensor, where d = 2k and k is the dimension of the latent space.

  • diag (bool) – Should the Kernel compute the whole covariance matrix or just the diagonal? Defaults to False.

Returns:

A b x n x m or n x m tensor representing the covariance matrix between x1 and x2. The exact size depends on the kernel’s evaluation mode: * full_covar: n x m or b x n x m * diag: n or b x n

Return type:

torch.Tensor (or gpytorch.lazy.LazyTensor)

class aepsych.kernels.RBFKernelPartialObsGrad(ard_num_dims=None, batch_shape=None, active_dims=None, lengthscale_prior=None, lengthscale_constraint=None, eps=1e-06, **kwargs)[source]

Bases: RBFKernelGrad

An RBF kernel over observations of f, and partial/non-overlapping observations of the gradient of f.

gpytorch.kernels.rbf_kernel_grad assumes a block structure where every partial derivative is observed at the same set of points at which x is observed. This generalizes that by allowing f and any subset of the derivatives of f to be observed at different sets of points.

The final column of x1 and x2 needs to be an index that identifies what is observed at that point. It should be 0 if this observation is of f, and i if it is of df/dxi.

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

Parameters:
  • ard_num_dims (Optional[int]) –

  • batch_shape (Optional[torch.Size]) –

  • active_dims (Optional[Tuple[int, ...]]) –

  • lengthscale_prior (Optional[Prior]) –

  • lengthscale_constraint (Optional[Interval]) –

  • eps (float) –

forward(x1, x2, diag=False, **params)[source]

Computes the covariance matrix between x1 and x2 based on the RBF

Parameters:
  • x1 (torch.Tensor) – A b x n x d or n x d tensor, where d = 2k and k is the dimension of the latent space.

  • x2 (torch.Tensor) – A b x m x d or m x d tensor, where d = 2k and k is the dimension of the latent space.

  • diag (bool) – Should the Kernel compute the whole covariance matrix (False) or just the diagonal (True)? Defaults to False.

  • params (Any) –

Returns:

A b x n x m or n x m tensor representing the covariance matrix between x1 and x2. The exact size depends on the kernel’s evaluation mode: * full_covar: n x m or b x n x m * diag: n or b x n

Return type:

torch.Tensor

num_outputs_per_input(x1, x2)[source]

For most kernels, num_outputs_per_input = 1.

However, some kernels (e.g. multitask kernels or interdomain kernels) return a num_outputs_per_input x num_outputs_per_input matrix of covariance values for every pair of data points.

I.e. if x1 is size … x N x D and x2 is size … x M x D, then the size of the kernel will be … x (N * num_outputs_per_input) x (M * num_outputs_per_input).

Returns:

num_outputs_per_input (usually 1).

Parameters:
  • x1 (Tensor) –

  • x2 (Tensor) –

Return type:

int