Graph
- class Graph[source]
Bases:
object
numpy backed graph class with support for memmapped edge_index
- abstract __init__(edge_index, edge_attr=None, x=None, y=None, num_nodes=None, adj_index=None, ensure_sorted=False, undir=None, nodes=None)[source]
Initialise graph
- Parameters:
edge_index – edge index such that
edge_index[0]
lists the source andedge_index[1]
the target node for each edgeedge_attr – optionally provide edge weights
num_nodes – specify number of nodes (default:
max(edge_index)+1
)ensure_sorted – if
False
, assume that theedge_index
input is already sortedundir – boolean indicating if graph is directed. If not provided, the
edge_index
is checked to determine this value.
Methods
Initialise graph
list neighbours of node
list neighbours of node and corresponding edge weight :param node: source node
return nodes in breadth-first-search order
return connected component ids where ids are sorted in decreasing order by component size
iterator over edges
iterator over weighted edges where each edge is a tuple
(source, target, weight)
find the neighbourhood of a set of source nodes
Iterator over nodes in the largest connected component
find induced subgraph for a set of nodes
convert graph to NetworkX format
Attributes
device
nodes
num_edges
num_features
weighted
boolean indicating if graph is weighted
weights
degree
- adj_weighted(node: int)[source]
list neighbours of node and corresponding edge weight :param node: source node
- Returns:
neighbours, weights
- abstract edges_weighted()[source]
iterator over weighted edges where each edge is a tuple
(source, target, weight)
- abstract neighbourhood(nodes, hops: int = 1)[source]
find the neighbourhood of a set of source nodes
note that the neighbourhood includes the source nodes themselves
- Parameters:
nodes – indices of source nodes
hops – number of hops for neighbourhood
- Returns:
neighbourhood
- abstract subgraph(nodes: Iterable, relabel=False, keep_x=True, keep_y=True)[source]
find induced subgraph for a set of nodes
- Parameters:
nodes – node indeces
- Returns:
subgraph
- abstract connected_component_ids()[source]
return connected component ids where ids are sorted in decreasing order by component size
- Returns:
Sequence of node indeces