graph_tools

class quantecon.graph_tools.DiGraph(adj_matrix, weighted=False, node_labels=None)[source]

Bases: object

Class for a directed graph. It stores useful information about the graph structure such as strong connectivity [1] and periodicity [2].

Parameters:
adj_matrixarray_like(ndim=2)

Adjacency matrix representing a directed graph. Must be of shape n x n.

weightedbool, optional(default=False)

Whether to treat adj_matrix as a weighted adjacency matrix.

node_labelsarray_like(default=None)

Array_like of length n containing the labels associated with the nodes, which must be homogeneous in type. If None, the labels default to integers 0 through n-1.

References

[2]

Aperiodic graph, Wikipedia.

Attributes:
csgraphscipy.sparse.csr_matrix

Compressed sparse representation of the digraph.

is_strongly_connectedbool

Indicate whether the digraph is strongly connected.

num_strongly_connected_componentsint

The number of the strongly connected components.

strongly_connected_components_indiceslist(ndarray(int))

List of numpy arrays containing the indices of the strongly connected components.

strongly_connected_componentslist(ndarray)

List of numpy arrays containing the strongly connected components, where the nodes are annotated with their labels (if node_labels is not None).

num_sink_strongly_connected_componentsint

The number of the sink strongly connected components.

sink_strongly_connected_components_indiceslist(ndarray(int))

List of numpy arrays containing the indices of the sink strongly connected components.

sink_strongly_connected_componentslist(ndarray)

List of numpy arrays containing the sink strongly connected components, where the nodes are annotated with their labels (if node_labels is not None).

is_aperiodicbool

Indicate whether the digraph is aperiodic.

periodint

The period of the digraph. Defined only for a strongly connected digraph.

cyclic_components_indiceslist(ndarray(int))

List of numpy arrays containing the indices of the cyclic components.

cyclic_componentslist(ndarray)

List of numpy arrays containing the cyclic components, where the nodes are annotated with their labels (if node_labels is not None).

Methods

subgraph(nodes)

Return the subgraph consisting of the given nodes and edges between thses nodes.

property cyclic_components
property cyclic_components_indices
property is_aperiodic
property is_strongly_connected
property node_labels
property num_sink_strongly_connected_components
property num_strongly_connected_components
property period
property scc_proj
property sink_scc_labels
property sink_strongly_connected_components
property sink_strongly_connected_components_indices
property strongly_connected_components
property strongly_connected_components_indices
subgraph(nodes)[source]

Return the subgraph consisting of the given nodes and edges between thses nodes.

Parameters:
nodesarray_like(int, ndim=1)

Array of node indices.

Returns:
DiGraph

A DiGraph representing the subgraph.

quantecon.graph_tools.annotate_nodes(func)[source]
quantecon.graph_tools.random_tournament_graph(n, random_state=None)[source]

Return a random tournament graph [1] with n nodes.

Parameters:
nscalar(int)

Number of nodes.

random_stateint or np.random.RandomState/Generator, optional

Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.

Returns:
DiGraph

A DiGraph representing the tournament graph.

References