pytspl.hogde_gp.forex.diffusion_non_hc

Classes

DiffusionNonHCKernelForex

Kernels in GPyTorch are implemented as a gpytorch.Module that, when called on two torch.Tensor

Module Contents

class pytspl.hogde_gp.forex.diffusion_non_hc.DiffusionNonHCKernelForex(eigenpairs: list[torch.tensor], kappa_bounds=(1e-05, 100000.0))[source]

Bases: gpytorch.kernels.Kernel

Kernels in GPyTorch are implemented as a gpytorch.Module that, when called on two torch.Tensor objects \(\mathbf x_1\) and \(\mathbf x_2\) returns either a torch.Tensor or a LinearOperator that represents the covariance matrix between \(\mathbf x_1\) and \(\mathbf x_2\).

In the typical use case, extend this class simply requires implementing a forward() method.

Note

The __call__() method does some additional internal work. In particular, all kernels are lazily evaluated so that we can index in to the kernel matrix before actually computing it. Furthermore, many built-in kernel modules return LinearOperators that allow for more efficient inference than if we explicitly computed the kernel matrix itself.

As a result, if you want to get an actual torch.tensor representing the covariance matrix, you may need to call the to_dense() method on the output.

This base Kernel class includes a lengthscale parameter \(\Theta\), which is used by many common kernel functions. There are a few options for the lengthscale:

  • Default: No lengthscale (i.e. \(\Theta\) is the identity matrix).

  • Single lengthscale: One lengthscale can be applied to all input dimensions/batches (i.e. \(\Theta\) is a constant diagonal matrix). This is controlled by setting the attribute has_lengthscale=True.

  • ARD: Each input dimension gets its own separate lengthscale (i.e. \(\Theta\) is a non-constant diagonal matrix). This is controlled by the ard_num_dims keyword argument (as well as has_lengthscale=True).

In batch mode (i.e. when \(\mathbf x_1\) and \(\mathbf x_2\) are batches of input matrices), each batch of data can have its own lengthscale parameter by setting the batch_shape keyword argument to the appropriate number of batches.

Note

You can set a prior on the lengthscale parameter using the lengthscale_prior argument.

Parameters:
  • ard_num_dims – Set this if you want a separate lengthscale for each input dimension. It should be D if \(\mathbf x\) is a … x N x D matrix. (Default: None.)

  • batch_shape – Set this if you want a separate lengthscale for each batch of input data. It should be \(B_1 \times \ldots \times B_k\) if \(\mathbf x_1\) is a \(B_1 \times \ldots \times B_k \times N \times D\) tensor.

  • active_dims – Set this if you want to compute the covariance of only a few input dimensions. The ints corresponds to the indices of the dimensions. (Default: None.)

  • lengthscale_prior – Set this if you want to apply a prior to the lengthscale parameter. (Default: None.)

  • lengthscale_constraint – Set this if you want to apply a constraint to the lengthscale parameter. (Default: Positive.)

  • eps – A small positive value added to the lengthscale to prevent divide by zero errors. (Default: 1e-6.)

Variables:
  • batch_shape (torch.Size) – The (minimum) number of batch dimensions supported by this kernel. Typically, this captures the batch shape of the lengthscale and other parameters, and is usually set by the batch_shape argument in the constructor.

  • dtype (torch.dtype) – The dtype supported by this kernel. Typically, this depends on the dtype of the lengthscale and other parameters.

  • is_stationary (bool) – Set to True if the Kernel represents a stationary function (one that depends only on \(\mathbf x_1 - \mathbf x_2\)).

  • lengthscale (torch.Tensor) – The lengthscale parameter. Size/shape of parameter depends on the ard_num_dims and batch_shape arguments.

Example:
>>> covar_module = gpytorch.kernels.LinearKernel()
>>> x1 = torch.randn(50, 3)
>>> lazy_covar_matrix = covar_module(x1) # Returns a RootLinearOperator
>>> tensor_covar_matrix = lazy_covar_matrix.to_dense() # Gets the actual tensor for this kernel matrix
property kappa_down
_set_kappa_down(value)[source]
property kappa_up
_set_kappa_up(value)[source]
property h
_set_h(value)[source]
property h_down
_set_h_down(value)[source]
property h_up
_set_h_up(value)[source]
_eval_covar_matrix()[source]
property covar_matrix
forward(x1, x2=None, diag: bool | None = False, **params)[source]

Computes the covariance between \(\mathbf x_1\) and \(\mathbf x_2\). This method should be implemented by all Kernel subclasses.

Parameters:
  • x1 – First set of data (… x N x D).

  • x2 – Second set of data (… x M x D).

  • diag – Should the Kernel compute the whole kernel, or just the diag? If True, it must be the case that x1 == x2. (Default: False.)

  • last_dim_is_batch – If True, treat the last dimension of x1 and x2 as another batch dimension. (Useful for additive structure over the dimensions). (Default: False.)

Returns:

The kernel matrix or vector. The shape depends on the kernel’s evaluation mode:

  • full_covar: … x N x M

  • full_covar with last_dim_is_batch=True: … x K x N x M

  • diag: … x N

  • diag with last_dim_is_batch=True: … x K x N