geometric_kernels.kernels.matern_kernel_hamming_graph

This module provides the MaternKernelHammingGraph kernel, a subclass of MaternKarhunenLoeveKernel for HammingGraph and HypercubeGraph spaces implementing the closed-form formula for the heat kernel when \(\nu = \infty\).

Module Contents

class geometric_kernels.kernels.matern_kernel_hamming_graph.MaternKernelHammingGraph(space, num_levels, normalize=True, eigenvalues_laplacian=None, eigenfunctions=None)[source]

Bases: geometric_kernels.kernels.karhunen_loeve.MaternKarhunenLoeveKernel

For \(\nu = \infty\), there exists a closed-form formula for the heat kernel on hamming graphs HammingGraph (including the binary hypercube case HypercubeGraph). This class extends MaternKarhunenLoeveKernel to implement this formula in the case of \(\nu = \infty\) for efficiency.

Note

We only use the closed form expression if num_levels is d + 1 which corresponds to exact computation. When truncated to fewer levels, we must use the parent class implementation to ensure consistency with feature map approximations.

Parameters:
K(params, X, X2=None, **kwargs)[source]

Compute the cross-covariance matrix between two batches of vectors of inputs, or batches of matrices of inputs, depending on the space.

Parameters:
  • params (beartype.typing.Dict[str, lab.Numeric]) –

    A dict of kernel parameters, typically containing two keys: “lengthscale” for length scale and “nu” for smoothness.

    The types of values in the params dict determine the output type and the backend used for the internal computations, see the warning below for more details.

    Note

    The values params[“lengthscale”] and params[“nu”] are typically (1,)-shaped arrays of the suitable backend. This serves to point at the backend to be used for internal computations.

    In some cases, for example, when the kernel is ProductGeometricKernel, the values of params may be (s,)-shaped arrays instead, where s is the number of factors.

    Note

    Finite values of params[“nu”] typically correspond to the generalized (geometric) Matérn kernels.

    Infinite params[“nu”] typically corresponds to the heat kernel (a.k.a. diffusion kernel, generalized squared exponential kernel, generalized Gaussian kernel, generalized RBF kernel). Although it is often considered to be a separate entity, we treat the heat kernel as a member of the Matérn family, with smoothness parameter equal to infinity.

  • X (lab.Numeric) – A batch of N inputs, each of which is a vector or a matrix, depending on how the elements of the self.space are represented.

  • X2 (beartype.typing.Optional[lab.Numeric]) –

    A batch of M inputs, each of which is a vector or a matrix, depending on how the elements of the self.space are represented.

    X2=None sets X2=X1.

    Defaults to None.

Returns:

The N x M cross-covariance matrix.

Return type:

lab.Numeric

Warning

The types of values in the params dict determine the backend used for internal computations and the output type.

Even if, say, geometric_kernels.jax is imported but the values in the params dict are NumPy arrays, the output type will be a NumPy array, and NumPy will be used for internal computations. To get a JAX array as an output and use JAX for internal computations, all the values in the params dict must be JAX arrays.

K_diag(params, X, **kwargs)[source]

Returns the diagonal of the covariance matrix self.K(params, X, X), typically in a more efficient way than actually computing the full covariance matrix with self.K(params, X, X) and then extracting its diagonal.

Parameters:
  • params (beartype.typing.Dict[str, lab.Numeric]) – Same as for K().

  • X (lab.Numeric) – A batch of N inputs, each of which is a vector or a matrix, depending on how the elements of the self.space are represented.

Returns:

The N-dimensional vector representing the diagonal of the covariance matrix self.K(params, X, X).

Return type:

lab.Numeric