Skip to content

Base

AbstractKernel

AbstractKernel(active_dims=None, n_dims=None, compute_engine=DenseKernelComputation())

Bases: Module

Base kernel class.

This class is the base class for all kernels in GPJax. It provides the basic functionality for evaluating a kernel function on a pair of inputs, as well as the ability to combine kernels using addition and multiplication.

The class also provides a method for slicing the input matrix to select the relevant columns for the kernel's evaluation.

Parameters:

  • active_dims (Union[list[int], slice, None], default: None ) –

    the indices of the input dimensions that are active in the kernel's evaluation, represented by a list of integers or a slice object. Defaults to a full slice.

  • n_dims (Union[int, None], default: None ) –

    the number of input dimensions of the kernel.

  • compute_engine (AbstractKernelComputation, default: DenseKernelComputation() ) –

    the computation engine that is used to compute the kernel's cross-covariance and gram matrices. Defaults to DenseKernelComputation.

__call__ abstractmethod

__call__(x, y)

Evaluate the kernel on a pair of inputs.

Parameters:

  • x (Num[Array, ' D']) –

    the left hand input of the kernel function.

  • y (Num[Array, ' D']) –

    The right hand input of the kernel function.

Returns:

  • ScalarFloat –

    The evaluated kernel function at the supplied inputs.

cross_covariance

cross_covariance(x, y)

Compute the cross-covariance matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the first input matrix of shape (N, D).

  • y (Num[Array, 'M D']) –

    the second input matrix of shape (M, D).

Returns:

  • Float[Array, 'N M'] –

    The cross-covariance matrix of the kernel of shape (N, M).

gram

gram(x)

Compute the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • LinearOperator –

    The gram matrix of the kernel of shape (N, N).

diagonal

diagonal(x)

Compute the diagonal of the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • Float[Array, ' N'] –

    The diagonal of the gram matrix of the kernel of shape (N,).

slice_input

slice_input(x)

Slice out the relevant columns of the input matrix.

Select the relevant columns of the supplied matrix to be used within the kernel's evaluation.

Parameters:

  • x (Float[Array, '... D']) –

    the matrix or vector that is to be sliced.

Returns:

  • Float[Array, '... Q'] –

    The sliced form of the input matrix.

__add__

__add__(other)

Add two kernels together. Args: other (AbstractKernel): The kernel to be added to the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the sum of the two kernels.

__mul__

__mul__(other)

Multiply two kernels together.

Parameters:

  • other (AbstractKernel) –

    The kernel to be multiplied with the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the product of the two kernels.

Constant

Constant(active_dims=None, constant=jnp.array(0.0), compute_engine=DenseKernelComputation())

Bases: AbstractKernel

A constant kernel. This kernel evaluates to a constant for all inputs. The scalar value itself can be treated as a model hyperparameter and learned during training.

cross_covariance

cross_covariance(x, y)

Compute the cross-covariance matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the first input matrix of shape (N, D).

  • y (Num[Array, 'M D']) –

    the second input matrix of shape (M, D).

Returns:

  • Float[Array, 'N M'] –

    The cross-covariance matrix of the kernel of shape (N, M).

gram

gram(x)

Compute the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • LinearOperator –

    The gram matrix of the kernel of shape (N, N).

diagonal

diagonal(x)

Compute the diagonal of the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • Float[Array, ' N'] –

    The diagonal of the gram matrix of the kernel of shape (N,).

slice_input

slice_input(x)

Slice out the relevant columns of the input matrix.

Select the relevant columns of the supplied matrix to be used within the kernel's evaluation.

Parameters:

  • x (Float[Array, '... D']) –

    the matrix or vector that is to be sliced.

Returns:

  • Float[Array, '... Q'] –

    The sliced form of the input matrix.

__add__

__add__(other)

Add two kernels together. Args: other (AbstractKernel): The kernel to be added to the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the sum of the two kernels.

__mul__

__mul__(other)

Multiply two kernels together.

Parameters:

  • other (AbstractKernel) –

    The kernel to be multiplied with the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the product of the two kernels.

__call__

__call__(x, y)

Evaluate the kernel on a pair of inputs.

Parameters:

  • x (Float[Array, ' D']) –

    The left hand input of the kernel function.

  • y (Float[Array, ' D']) –

    The right hand input of the kernel function.

Returns:

  • ScalarFloat ( ScalarFloat ) –

    The evaluated kernel function at the supplied inputs.

CombinationKernel

CombinationKernel(kernels, operator, compute_engine=DenseKernelComputation())

Bases: AbstractKernel

A base class for products or sums of MeanFunctions.

cross_covariance

cross_covariance(x, y)

Compute the cross-covariance matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the first input matrix of shape (N, D).

  • y (Num[Array, 'M D']) –

    the second input matrix of shape (M, D).

Returns:

  • Float[Array, 'N M'] –

    The cross-covariance matrix of the kernel of shape (N, M).

gram

gram(x)

Compute the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • LinearOperator –

    The gram matrix of the kernel of shape (N, N).

diagonal

diagonal(x)

Compute the diagonal of the gram matrix of the kernel.

Parameters:

  • x (Num[Array, 'N D']) –

    the input matrix of shape (N, D).

Returns:

  • Float[Array, ' N'] –

    The diagonal of the gram matrix of the kernel of shape (N,).

slice_input

slice_input(x)

Slice out the relevant columns of the input matrix.

Select the relevant columns of the supplied matrix to be used within the kernel's evaluation.

Parameters:

  • x (Float[Array, '... D']) –

    the matrix or vector that is to be sliced.

Returns:

  • Float[Array, '... Q'] –

    The sliced form of the input matrix.

__add__

__add__(other)

Add two kernels together. Args: other (AbstractKernel): The kernel to be added to the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the sum of the two kernels.

__mul__

__mul__(other)

Multiply two kernels together.

Parameters:

  • other (AbstractKernel) –

    The kernel to be multiplied with the current kernel.

Returns:

  • AbstractKernel ( AbstractKernel ) –

    A new kernel that is the product of the two kernels.

__call__

__call__(x, y)

Evaluate the kernel on a pair of inputs.

Parameters:

  • x (Float[Array, ' D']) –

    The left hand input of the kernel function.

  • y (Float[Array, ' D']) –

    The right hand input of the kernel function.

Returns:

  • ScalarFloat ( ScalarFloat ) –

    The evaluated kernel function at the supplied inputs.