Skip to content

Kernels

Kernels specific to state-space GPs (e.g. TruncatedPeriodic) and the to_sde dispatcher.

TruncatedPeriodic

TruncatedPeriodic(
    *,
    active_dims=None,
    lengthscale=1.0,
    variance=1.0,
    period=1.0,
    truncation_order=6,
    n_dims=None,
    compute_engine=None,
)

Bases: StationaryKernel

Truncated-Fourier approximation of the periodic kernel.

See Solin & Särkkä (2014). The kernel is the truncated cosine series

k(τ) = σ² · (Ĩ_0(c) + 2 Σ_{k=1}^{K} Ĩ_k(c) cos(2π k τ / period))

where Ĩ_k(c) = e^{-c} I_k(c) is the scaled modified Bessel function and c = 1/(4ℓ²). Acceptance of a 1-D temporal input is enforced by _validate_temporal_kernel at to_sde time, not here.

Example:

    >>> from gpjax.state_space import TruncatedPeriodic
    >>> kernel = TruncatedPeriodic(
    ...     lengthscale=1.0, variance=1.0, period=1.0, truncation_order=6,
    ... )
    >>> kernel.truncation_order
    6

spectral_density property

spectral_density: Normal | StudentT

The spectral density of the kernel.

Returns:

  • Normal | StudentT

    Callable[[Float[Array, "D"]], Float[Array, "D"]]: The spectral density function.

cross_covariance

cross_covariance(
    x: Num[Array, "N D"], y: Num[Array, "M D"]
) -> Float[Array, "N M"]

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: Num[Array, 'N D']) -> lx.AbstractLinearOperator

Compute the gram matrix of the kernel.

Parameters:

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

    the input matrix of shape (N, D).

Returns:

  • AbstractLinearOperator

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

diagonal

diagonal(x: Num[Array, 'N D']) -> lx.AbstractLinearOperator

Compute the diagonal of the gram matrix of the kernel.

Parameters:

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

    the input matrix of shape (N, D).

Returns:

  • AbstractLinearOperator

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

slice_input

slice_input(
    x: Float[Array, "... D"],
) -> Float[Array, "... Q"]

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: Union[AbstractKernel, ScalarFloat],
) -> AbstractKernel

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: Union[AbstractKernel, ScalarFloat],
) -> AbstractKernel

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.

to_sde

to_sde(kernel) -> LinearSDE

Convert a kernel to its state-space (linear SDE) representation.

Default handler raises NotImplementedError listing supported kernels.

Example:

    >>> import gpjax as gpx
    >>> from gpjax.state_space import to_sde
    >>> sde = to_sde(gpx.kernels.Matern32(lengthscale=1.0, variance=1.0))
    >>> sde.__class__.__name__
    'Matern32SDE'