Graphs¶
Generators¶
A collection of graph generators.
All the graph generators here create a networkx.Graph
instance with
integer node labels increasing from the center (the central node will have index
equal to 0).
-
er.graph.generator.
from_matfile
(filename, adj_key='C', nodes_key='nodes')¶ Generates a graph based on a Matlab file (.mat).
The Matlab file must contain the adjacency matrix (C) and a list of node coordinates (nodes).
- Args:
filename: The path to the .mat file. adj_key: The name of the cell containing the adjacency matrix. nodes_key: The name of the cell containing the nodes.
- Returns:
A networkx.Graph instance.
-
er.graph.generator.
hexagonal_lattice
(num_nodes, periodic=False)¶ Generates an hexagonal lattice graph with about num_nodes nodes.
- Args:
- num_nodes: The desired number of nodes. Note that the produced lattice
may not have the exact number of nodes specified.
- periodic: Whether the generated lattice should be periodic (the nodes on
the contour will be connected each other). False by default.
- Returns:
A networkx.Graph instance.
-
er.graph.generator.
random_regular
(num_nodes)¶ Generates a random 3-regular graph with num_nodes nodes.
- Args:
num_nodes: The desired number of nodes in the graph.
- Returns:
A networkx.Graph instance.
Trajectory¶
-
class
er.graph.
Trajectory
(nodes, times=None, id=None)¶ Trajectory represents a path on a graph.
-
append
(node, time=None)¶ Append a new node to the trajectory.
-
data
()¶ Provides a dict containing the main characteristics.
-
duration
()¶ Returns the trajectory time duration.
-
edges
()¶ Returns a list of edges on which the particle moved.
The list may contain self loops (e.g. 3 → 3) if the particle was trapped in a node.
-
end_node
()¶ Returns the ending node of the trajectory.
-
fpt
(target)¶ Returns the first passage time through target.
-
start_node
()¶ Returns the starting node of the trajectory.
-
time
()¶ Returns the current trajectory time.
-
to_dataframe
()¶ Represents the trajectory as DataFrame.
-
traps
()¶ Returns a list of nodes in which the particle got trapped.
The list may contain multiple occurrences of the same node, meaning that the trapping happened multiple times.
-
Utilities¶
Algorithms and utilities for graphs.
-
er.graph.utils.
k_cores
(graph: networkx.classes.graph.Graph, k: int, inplace=False)¶ Return the components of the k-core graph.
- Parameters
graph (networkx.Graph) – An undirected graph.
k (int) – The order of the core.
inplace (bool) – If True, the k-core graph will be built directly by modifying the instance graph.
- Returns
The core graph and a generator of its connected components.
- Return type
(core_graph, connected_components)