nlgm.searchspace Module#

nlgm.searchspace.adj_product_spaces(s1: list, s2: list) bool[source]#

Check whether two given manifold signatures are adjacent product spaces.

Args:

s1 (list): The first manifold signature. s2 (list): The second manifold signature.

Returns:

bool: True if the manifold signatures are adjacent, False otherwise.

Note:

Adjacency is defined as a difference of at most one manifold between signatures. We use an approximation of Levenshtein (edit) distance to compute this more efficiently.

nlgm.searchspace.compute_weight(manifold1: ProductManifold, manifold2: ProductManifold)[source]#

Deprecated: Compute the weight between two ProductManifold objects based on the Gromov-Hausdorff distances between their component manifolds using the Hungarian algorithm.

Args:

manifold1 (ProductManifold): The first ProductManifold object. manifold2 (ProductManifold): The second ProductManifold object.

Returns:

float: The inverse Gromov-Haustorff distance between manifold1 and manifold2. If the manifolds have mismatching dimensions, returns 0.

Note:

The weight computation is formulated as an optimal matching problem because we want to find the best alignment between the component manifolds of the two ProductManifold objects that minimizes the total distance. Each component manifold from manifold1 should be matched with exactly one component manifold from manifold2 in a way that minimizes the sum of the distances between the matched pairs.

The Hungarian algorithm is used to solve this optimal matching problem efficiently. It finds the minimum weight perfect matching in a bipartite graph, where the nodes represent the component manifolds and the edges represent the distances between them.

nlgm.searchspace.construct_graph_search_space(n_p: int = 7, curvature_choices: list = [-1, 0, 1], connectivity: bool = False)[source]#

Construct the graph search space for finding the optimal latent geometry.

Args:

n_p (int): The number of model spaces in each product manifold. curvature_choices (list): The possible curvatures to choose from (default: [-1, 0, 1]). connectivity (bool): Whether or not to return a connectivity graph instead of a weighted graph (default: False).

Returns:
  • adjacency_matrix: A 2D numpy array representing the adjacency matrix of the graph search space.

  • signatures: A list of product manifold curvatures. With model space dimension 2, this specifies the signature.

    The index of the tuple in the list corresponds to the index of the node in the adjacency matrix.

Note:
  • All model spaces have dimension 2.

  • Nodes in the graph represent different geometries (product manifolds).

  • Edges between nodes represent the distances between the corresponding product manifolds.

  • A distance of 0.0 means there is no edge between the nodes.

  • All product manifolds have up to n_p model spaces.

nlgm.searchspace.get_color(weight: float) str[source]#

Return a color based on the edge weight when visualizing the graph search space.

Args:

weight (float): The weight of the edge.

Returns:

str: The color corresponding to the edge weight.

nlgm.searchspace.manifold_to_curvature(manifold: str)[source]#

Convert a dimension 2 manifold type to an arbitrary curvature that matches.

Args:

manifold (str): The manifold type.

Returns:

int: The curvature that matches the manifold type.

nlgm.searchspace.manifold_type(manifold: BasicManifold)[source]#

Identify the type of a manifold based on its curvature. Assumes dimension 2.

Args:

manifold (BasicManifold): The manifold object.

Returns:

str: The type of the manifold based on its curvature.

Raises:

ValueError: If the dimension of the manifold is not 2.