Graphs and Graph Routines#

class sigmaepsilon.math.topology.graph.Graph(incoming_graph_data=None, **attr)[source]#

A subclass of networkx.Graph, extending its capabilities. See the documentation of networkx for the details on how to define graphs.

Note

If networkx is not installed, the class is NoneType, but the functionality it implements is still available, you just have to manage graph creation by yourself.

Examples

A basic example with networkx:

>>> from sigmaepsilon.math.topology import Graph
>>> import networkx as nx
>>> grid = nx.grid_2d_graph(5, 5)  # 5x5 grid
>>> G = Graph(grid)
adjacency_matrix(*args, to_csr: bool = False, **kwargs)[source]#

Returns the adjacency matrix of the graph.

Parameters:
  • to_csr (bool, Optional) – If True, the result of networkx.adjacency_matrix is returned as a csr_matrix.

  • *args (Tuple, Optional) – Forwarded to networkx.adjacency_matrix

  • **kwargs – Forwarded to networkx.adjacency_matrix

  • dict – Forwarded to networkx.adjacency_matrix

  • Optional – Forwarded to networkx.adjacency_matrix

Returns:

The adjacency representation of the graph.

Return type:

NumPy array, SciPy array or csr_matrix

Examples

>>> from sigmaepsilon.math.topology import Graph
>>> G = Graph([(1, 1)])
>>> A = G.adjacency_matrix()
>>> print(A.todense())
[[1]]
pseudo_peripheral_nodes()[source]#

Returns the indices of nodes that are possible candidates for being peripheral nodes of a graph.

rooted_level_structure(root=0)[source]#

Returns the rooted level structure (RLS) of the graph.

The call is forwarded to rooted_level_structure, go there to read about the possible arguments.

sigmaepsilon.math.topology.graph.pseudo_peripheral_nodes(adj: csr_matrix) ndarray[source]#

Returns the indices of nodes that are possible candidates for being peripheral nodes of a graph.

Parameters:

adj (csr_matrix) – Adjacency matrix in CSR format.

Returns:

Integer array of nodal indices.

Return type:

numpy.ndarray

sigmaepsilon.math.topology.graph.rooted_level_structure(adj: csr_matrix, root: int = 0) Dict[source]#

Turns a sparse adjacency matrix into a rooted level structure.

Parameters:
  • adj (csr_matrix) – Adjacency matrix in CSR format.

  • root (int, Optional) – Index of the root node. Default is 0.

Returns:

A numba dictionary <int[:] : int[:, :]>, where the keys refer to different levels, and the values are the indices of nodes on that level.

Return type:

dict