Skip to content

Kohcomputation

KOHKernelComputation

Bases: AbstractKernelComputation

Dense kernel computation class. Operations with the kernel assume a dense gram matrix structure.

cross_covariance(kernel, x, y)

Compute the cross-covariance matrix.

For a given kernel, compute the NxM covariance matrix on a pair of input matrices of shape \(NxD\) and \(MxD\).

Parameters:

  • kernel (Kernel) –

    the kernel function.

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

    The input matrix.

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

    The input matrix.

Returns
Float[Array, "N M"]: The computed cross-covariance.
Source code in .tox/docs/lib/python3.12/site-packages/kohgpjax/kernels/computations/kohcomputation.py
def cross_covariance(
    self,
    kernel: K,
    x,  #: Float[Array, "N D"],
    y,  #: Float[Array, "M D"]
):  # -> Float[Array, "N M"]:
    r"""Compute the cross-covariance matrix.

    For a given kernel, compute the NxM covariance matrix on a pair of input
    matrices of shape $`NxD`$ and $`MxD`$.

    Args:
        kernel (Kernel): the kernel function.
        x (Float[Array,"N D"]): The input matrix.
        y (Float[Array,"M D"]): The input matrix.

    Returns
    -------
        Float[Array, "N M"]: The computed cross-covariance.
    """
    a = kernel.num_field_obs
    b = kernel.num_sim_obs
    N = x.shape[0]

    # PART 1 & 2
    sigma_eta, sigma_delta, sigma_epsilon, sigma_epsilon_eta = (
        self._calc_sub_kernels(kernel, x, y)
    )

    # PART 3 - Construct the output array
    return sigma_eta + pad(
        block_diag(sigma_delta + sigma_epsilon, sigma_epsilon_eta),
        ((0, N - a - b), (0, N - a - b)),
    )