geometric_kernels.spaces.graph

This module provides the Graph space.

Module Contents

class geometric_kernels.spaces.graph.Graph(adjacency_matrix, normalize_laplacian=False)[source]

Bases: geometric_kernels.spaces.base.DiscreteSpectrumSpace

The GeometricKernels space representing the node set of any user-provided weighted undirected graph.

The elements of this space are represented by node indices, integer values from 0 to n-1, where n is the number of nodes in the user-provided graph.

Each individual eigenfunction constitutes a level.

Note

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

Parameters:
  • adjacency_matrix (lab.Numeric) –

    An n-dimensional square, symmetric matrix, where adjacency_matrix[i, j] is non-zero if there is an edge between nodes i and j. SciPy’s sparse matrices are supported.

    Warning

    Make sure that the type of the adjacency_matrix is of the backend (NumPy (or SciPy) / JAX / TensorFlow, PyTorch) that you wish to use for internal computations.

  • normalize_laplacian (bool) –

    If True, the graph Laplacian will be degree normalized (symmetrically): L_sym = D^-0.5 * L * D^-0.5.

    Defaults to False.

Citation

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

property dimension: int[source]
Returns:

Return type:

int

property element_shape[source]
Returns:

[1].

property num_vertices: int[source]

Number of vertices in the graph.

Return type:

int

get_eigenfunctions(num)[source]

Returns the EigenfunctionsFromEigenvectors object with num levels (i.e., in this case, num eigenpairs).

Parameters:

num (int) – Number of levels.

Return type:

geometric_kernels.spaces.eigenfunctions.Eigenfunctions

get_eigensystem(num)[source]

Returns the first num eigenvalues and eigenvectors of the graph Laplacian. Caches the solution to prevent re-computing the same values.

Note

If the adjacency_matrix was a sparse SciPy array, requesting all eigenpairs will lead to a conversion of the sparse matrix to a dense one due to scipy.sparse.linalg.eigsh limitations.

Parameters:

num – Number of eigenpairs to return. Performs the computation at the first call. Afterwards, fetches the result from cache.

Returns:

A tuple of eigenvectors [n, num], eigenvalues [num, 1].

get_eigenvalues(num)[source]
Parameters:

num (int) – Number of eigenvalues to return.

Returns:

Array of eigenvalues, with shape [num, 1].

Return type:

lab.Numeric

get_eigenvectors(num)[source]
Parameters:

num (int) – Number of eigenvectors to return.

Returns:

Array of eigenvectors, with shape [n, num].

Return type:

lab.Numeric

get_repeated_eigenvalues(num)[source]

Same as get_eigenvalues().

Parameters:

num (int) – Same as get_eigenvalues().

Return type:

lab.Numeric

random(key, number)[source]

Sample uniformly random points in the space.

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

  • number – Number of samples to draw.

Returns:

An array of number uniformly random samples on the space.