geometric_kernels.spaces.hypercube_graph

This module provides the HypercubeGraph space and the respective Eigenfunctions subclass WalshFunctions.

Module Contents

class geometric_kernels.spaces.hypercube_graph.HypercubeGraph(dim)[source]

Bases: geometric_kernels.spaces.base.DiscreteSpectrumSpace

The GeometricKernels space representing the d-dimensional hypercube graph \(C^d = \{0, 1\}^d\), the combinatorial space of binary vectors of length \(d\).

The elements of this space are represented by d-dimensional boolean vectors.

Levels are the whole eigenspaces.

Note

A tutorial on how to use this space is available in the HypercubeGraph.ipynb notebook.

Note

Since the degree matrix is a constant multiple of the identity, all types of the graph Laplacian coincide on the hypercube graph up to a constant, we choose the normalized Laplacian for numerical stability.

Parameters:

dim (int) – Dimension \(d\) of the hypercube graph \(C^d\), a positive integer.

Citation

If you use this GeometricKernels space in your research, please consider citing Borovitskiy et al. [2023].

get_eigenfunctions(num)[source]

Returns the WalshFunctions object with num levels.

Parameters:

num (int) – Number of levels.

Return type:

geometric_kernels.spaces.eigenfunctions.Eigenfunctions

get_eigenvalues(num)[source]

Eigenvalues of the Laplacian corresponding to the first num levels.

Parameters:

num (int) – Number of levels.

Returns:

(num, 1)-shaped array containing the eigenvalues.

Return type:

lab.Numeric

Note

The notion of levels is discussed in the documentation of the MaternKarhunenLoeveKernel.

get_repeated_eigenvalues(num)[source]

Eigenvalues of the Laplacian corresponding to the first num levels, repeated according to their multiplicity within levels.

Parameters:

num (int) – Number of levels.

Returns:

(J, 1)-shaped array containing the repeated eigenvalues, J is the resulting number of the repeated eigenvalues.

Return type:

lab.Numeric

Note

The notion of levels is discussed in the documentation of the MaternKarhunenLoeveKernel.

random(key, number)[source]

Sample uniformly random points on the hypercube graph \(C^d\).

Always returns [N, D] boolean array of the key’s backend.

Parameters:
  • key (lab.RandomState) – Either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (representing random state).

  • number (int) – Number N of samples to draw.

Returns:

An array of number uniformly random samples on the space.

Return type:

lab.Numeric

property dimension: int

Returns d, the dim parameter that was passed down to __init__.

Return type:

int

property element_shape
Returns:

[d].

class geometric_kernels.spaces.hypercube_graph.WalshFunctions(dim, num_levels)[source]

Bases: geometric_kernels.spaces.eigenfunctions.EigenfunctionsWithAdditionTheorem

Eigenfunctions of graph Laplacian on the hypercube graph \(C^d\) whose nodes are index by binary vectors in \(\{0, 1\}^d\) are the Walsh functions \(w_T: C^d \to \{-1, 1\}\) given by

\[w_T(x_0, .., x_{d-1}) = (-1)^{\sum_{i \in T} x_i},\]

enumerated by all possible subsets \(T\) of the set \(\{0, .., d-1\}\).

Levels are the whole eigenspaces, comprising all Walsh functions \(w_T\) with the same cardinality of \(T\). The addition theorem for these is based on certain discrete orthogonal polynomials called Kravchuk polynomials.

Parameters:
  • dim (int) – Dimension \(d\) of the hypercube graph.

  • num_levels (int) – Specifies the number of levels of the Walsh functions.

__call__(X, **kwargs)[source]

Evaluate the individual eigenfunctions at a batch of input locations.

Parameters:
  • X (lab.Bool) – Points to evaluate the eigenfunctions at, an array of shape [N, <axis>], where N is the number of points and <axis> is the shape of the arrays that represent the points in a given space.

  • **kwargs – Any additional parameters.

Returns:

An [N, J]-shaped array, where J is the number of eigenfunctions.

Return type:

lab.Float

weighted_outerproduct(weights, X, X2=None, **kwargs)[source]

Computes

\[\sum_{l=0}^{L-1} w_l \sum_{s=1}^{d_l} f_{l s}(x_1) f_{l s}(x_2).\]

for all \(x_1\) in X and all \(x_2\) in X2, where \(w_l\) are weights.

Parameters:
  • weights (lab.Numeric) – An array of shape [L, 1] where L is the number of levels.

  • X (lab.Numeric) – The first of the two batches of points to evaluate the weighted outer product at. An array of shape [N, <axis>], where N is the number of points and <axis> is the shape of the arrays that represent the points in a given space.

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

    The second of the two batches of points to evaluate the weighted outer product at. An array of shape [N2, <axis>], where N2 is the number of points and <axis> is the shape of the arrays that represent the points in a given space.

    Defaults to None, in which case X is used for X2.

  • **kwargs – Any additional parameters.

Returns:

An array of shape [N, N2].

Return type:

lab.Numeric

weighted_outerproduct_diag(weights, X, **kwargs)[source]

Computes the diagonal of the matrix weighted_outerproduct(weights, X, X, **kwargs).

Parameters:
Returns:

An array of shape [N,].

Return type:

lab.Numeric

property num_eigenfunctions: int

The number J of eigenfunctions.

Return type:

int

property num_eigenfunctions_per_level: beartype.typing.List[int]

The number of eigenfunctions per level: list of \(d_l\), \(0 \leq l < L\).

Return type:

beartype.typing.List[int]

property num_levels: int

The number L of levels.

Return type:

int