pytspl.simplicial_complex

Simplicial complex data structure and operations.

Submodules

Classes

SimplicialComplex

Data structure class for a simplicial complex.

Package Contents

class pytspl.simplicial_complex.SimplicialComplex(nodes: list = [], edges: list = [], triangles: list = [], node_features: dict = {}, edge_features: dict = {})[source]

Data structure class for a simplicial complex.

nodes
edges
triangles
node_features
edge_features
B1
B2
print_summary()[source]

Print the summary of the simplicial complex.

edges_to_B1(edges: list, num_nodes: int) numpy.ndarray[source]

Create the B1 matrix (node-edge) from the edges.

Args:

edges (list): List of edges. num_nodes (int): Number of nodes.

Returns:

np.ndarray: B1 matrix.

triangles_to_B2(triangles: list, edges: list) numpy.ndarray[source]

Create the B2 matrix (edge-triangle) from the triangles.

Args:

triangles (list): List of triangles. edges (list): List of edges.

Returns:

np.ndarray: B2 matrix.

generate_coordinates() dict[source]

Generate the coordinates of the nodes using spring layout if the coordinates of the sc don’t exist.

Returns:

dict: Coordinates of the nodes.

property shape: tuple

Return the shape of the simplicial complex.

property max_dim: int

Return the maximum dimension of the simplicial complex.

property simplices: list[tuple]

Get all the simplices of the simplicial complex.

This includes 0-simplices (nodes), 1-simplices (edges), 2-simplices.

Returns:

list[tuple]: List of simplices.

edge_feature_names() list[str][source]

Return the list of edge feature names.

get_node_features() list[dict][source]

Return the list of node features.

get_edge_features(name: str = None) list[dict][source]

Return the list of edge features.

get_faces(simplex: Iterable[Hashable]) set[tuple][source]

Return the faces of the simplex in order.

Args:

simplex (Iterable[Hashable]): Simplex for which to find the faces.

Returns:

set[tuple]: Set of faces of the simplex.

identity_matrix() numpy.ndarray[source]

Identity matrix of the simplicial complex.

tocsr(matrix: numpy.ndarray) scipy.sparse.csr_matrix[source]

Convert a numpy array to a csr_matrix.

Args:

matrix (np.ndarray): Numpy array to convert.

Returns:

csr_matrix: Compressed Sparse Row matrix.

incidence_matrix(rank: int) scipy.sparse.csr_matrix[source]

Compute the incidence matrix of the simplicial complex.

Args:

rank (int): Rank of the incidence matrix.

Returns:

csr_matrix: Incidence matrix of the simplicial complex.

adjacency_matrix() scipy.sparse.csr_matrix[source]

Compute the adjacency matrix of the simplicial complex.

Returns:

csr_matrix: Adjacency matrix of the simplicial complex.

laplacian_matrix() scipy.sparse.csr_matrix[source]

Compute the Laplacian matrix of the simplicial complex.

Returns:

csr_matrix: Laplacian matrix of the simplicial complex.

lower_laplacian_matrix(rank: int = 1) scipy.sparse.csr_matrix[source]

Compute the lower Laplacian matrix of the simplicial complex.

Args:

rank (int): Rank of the lower Laplacian matrix.

ValueError:

If the rank is not 1 or 2.

Returns:

csr_matrix: Lower Laplacian matrix of the simplicial complex.

upper_laplacian_matrix(rank: int = 1) scipy.sparse.csr_matrix[source]

Compute the upper Laplacian matrix of the simplicial complex.

Args:

rank (int): Rank of the upper Laplacian matrix.

ValueError:

If the rank is not 0 or 1.

Returns:

csr_matrix: Upper Laplacian matrix of the simplicial complex.

hodge_laplacian_matrix(rank: int = 1) scipy.sparse.csr_matrix[source]

Compute the Hodge Laplacian matrix of the simplicial complex.

Args:

rank (int): Rank of the Hodge Laplacian matrix.

ValueError:

If the rank is not 0, 1, or 2.

Returns:

csr_matrix: Hodge Laplacian matrix of the simplicial complex.

apply_lower_shifting(flow: numpy.ndarray, steps: int = 1) numpy.ndarray[source]

Apply the lower shifting operator to the simplicial complex.

Args:

flow (np.ndarray): Flow on the simplicial complex. steps (int): Number of times to apply the lower shifting operator. Defaults to 1.

Returns:

np.ndarray: Lower shifted simplicial complex.

apply_upper_shifting(flow: numpy.ndarray, steps: int = 1) numpy.ndarray[source]

Apply the upper shifting operator to the simplicial complex.

Args:

flow (np.ndarray): Flow on the simplicial complex. steps (int): Number of times to apply the upper shifting operator. Defaults to 1.

Returns:

np.ndarray: Upper shifted simplicial complex.

apply_k_step_shifting(flow: numpy.ndarray, steps: int = 2) numpy.ndarray[source]

Apply the k-step shifting operator to the simplicial complex.

Args:

flow (np.ndarray): Flow on the simplicial complex.

Returns:

np.ndarray: k-step shifted simplicial complex.

get_simplicial_embeddings(flow: numpy.ndarray) tuple[source]

Return the simplicial embeddings of the simplicial complex.

Args:

flow (np.ndarray): Flow on the simplicial complex.

Returns:

np.ndarray: Simplicial embeddings of the simplicial complex. Harmonic embedding, curl embedding, and gradient embedding.

get_component_eigenpair(component: str = FrequencyComponent.HARMONIC.value, tolerance: float = 0.001) tuple[source]

Return the eigendecomposition of the simplicial complex.

Args:

component (str, optional): Component of the eigendecomposition to return. Defaults to “harmonic”. tolerance (float, optional): Tolerance for eigenvalues to be considered zero. Defaults to 1e-3.

ValueError:

If the component is not one of ‘harmonic’, ‘curl’, or ‘gradient’.

Returns:

np.ndarray: Eigenvectors of the component. np.ndarray: Eigenvalues of the component.

get_total_variance() numpy.ndarray[source]

Get the total variance of the SC.

Returns:

np.ndarray: The total variance of the SC.

get_divergence(flow: numpy.ndarray) numpy.ndarray[source]

Get the divergence of the edge flow.

Args:

flow (np.ndarray): The edge flow defined over a SC.

Returns:

np.ndarray: The divergence of the edge flow.

get_curl(flow: numpy.ndarray) numpy.ndarray[source]

Get the curl of the edge flow.

Args:

flow (np.ndarray): The edge flow defined over a SC.

Returns:

np.ndarray: The curl of the edge flow.

get_component_flow(flow: numpy.ndarray, component: str = FrequencyComponent.GRADIENT.value, round_fig: bool = True, round_sig_fig: int = 2) numpy.ndarray[source]

Return the component flow of the simplicial complex using the Hodge decomposition.

Args:

flow (np.ndarray): Flow on the simplicial complex. component (str, optional): Component of the Hodge decomposition. Defaults to FrequencyComponent.GRADIENT.value. round_fig (bool, optional): Round the hodgedecomposition to the Default to True. round_sig_fig (int, optional): Round to significant figure. Defaults to 2.

Returns:

np.ndarray: Hodge decomposition of the edge flow.