Graphs

Graph class for representing networks with node and edge attributes.

class Graph(adjs=None, channels=None, nodelist=None, edgelist=None, node_col=None, source_col=None, target_col=None, channel_col=None, orig_idxs=None)

An multigraph class with support for node and edge attributes.

Parameters:
  • adjs (list(spmatrix)) – Adjacency matrices counting edges in each channel.
  • channels (list(str), optional) – Types of edge, one per adjacency matrix.
  • nodelist (DataFrame, optional) – Attributes of each node.
  • edgelist (DataFrame, optional) – Attributes of each edge.
n_nodes

Number of nodes in the graph.

Type:int
n_channels

Number of types of edge in the graph.

Type:int
channels

Types of edge present in the graph.

Type:list(str)
adjs

Adjacency matrices corresponding to each channel.

Type:list(spmatrix)
ch_to_adj

Map from channels to their corresponding adjacency matrix

Type:dict(str, spmatrix)
nodes

A Series containing node identifiers. These are particularly useful for keeping track of nodes when taking subgraphs.

Type:Series
nodelist

A DataFrame containing node attribute information.

Type:DataFrame
edgelist

A DataFrame containing edge attribute information.

Type:DataFrame, optional
node_col

Column name for node identifiers in the nodelist.

Type:str
source_col

Column name for source node identifiers in the edgelist.

Type:str
target_col

Column name for target node identifiers in the edgelist.

Type:str
channel_col

Column name for edge type/channel identifiers in the edgelist.

Type:str
orig_idxs

Original indices of nodes when the graph was first created. Used to track node locations when subgraphs are taken.

Type:array
copy()

Returns a copy of the graph. :returns: A copy of the graph. :rtype: Graph

has_loops

Indicator of whether the graph has any self-edges.

Type:bool
composite_adj

Composite adjacency matrix of the graph.

Each entry of this matrix corresponds to the total number of edges of any type going from the node corresponding to the row to the node corresponding to the column.

Type:spmatrix
sym_composite_adj

Symmetrized composite adjacency matrix of the graph.

Each entry of this matrix corresponds to the total number of edges of any type between the pair of nodes indicated by the row and column indices, ignoring the direction of the edges.

Type:spmatrix
is_nbr

Boolean adjacency matrix of the graph.

Each entry of this matrix indicates whether the pair of nodes corresponding to the row and column indices are connected by an edge in either direction in any channel. The entry will be True if the nodes are connected by an edge in some channel and False otherwise.

Type:spmatrix
nbr_idx_pairs

A [N, 2] array of adjacent pairs of node indices.

A 2d array with 2 columns. Each row contains the indices of a pair of neighboring nodes in the graph. Each pair is only returned once, so only one of (i, j) and (j, i) can appear as rows.

Type:2darray
self_edges

An array of self-edge counts in each channel.

A 2darray of shape [n_nodes, n_channels]. Each entry provides the number of self edges of the node corresponding to the row in the channel corresponding to the channel.

Type:2darray
in_degrees

An array of in degrees in each channel.

A 2darray of shape [n_nodes, n_channels]. Each entry provides the in-degree of the node corresponding to the row in the channel corresponding to the channel.

Type:2darray
out_degrees

An array of out degrees in each channel.

A 2darray of shape [n_nodes, n_channels]. Each entry provides the out-degree of the node corresponding to the row in the channel corresponding to the channel.

Type:2darray
in_out_degrees

An array of in and out degrees in each channel.

A 2darray of shape [n_nodes, 2 * n_channels]. The first n_channels entries of each row are the in-degrees of the nodes corresponding to the row in each channel. The remaining n_channels entries of each row are the out-degrees.

Type:2darray
edge_src_idxs

Gets the node indices of the sources of each edge in the edgelist. :returns: The array of source node indices. :rtype: np.ndarray(uint16)

edge_dst_idxs

Gets the node indices of the destinations of each edge in the edgelist. :returns: The array of destination node indices. :rtype: np.ndarray(uint16)

loopless_subgraph()

Get a subgraph containing no self-edges.

Returns:A graph with the same nodes and edges as self, omitting self-edges.
Return type:Graph
node_subgraph(node_idxs, get_edge_is_cand=False)

Get the subgraph induced by the specified node indices.

TODO: Any of the composite adjacency matrices should be subgraphed if they have been computed.

Parameters:node_idxs (1darray) – The indices corresponding to the nodes in the desired subgraph.
Returns:The induced subgraph.
Return type:Graph
channel_subgraph(channels)

Get the subgraph induced by the specified channels.

Parameters:channels (1darray) – The desired channels to keep in the subgraph.
Returns:The induced subgraph.
Return type:Graph
node_cover()

Get the indices of nodes for a node cover, sorted by importance.

This function provides no warranty of the optimality of the node cover. The computed node cover may be far from the smallest possible.

Returns:The indices of a set of nodes in a node cover.
Return type:1darray