TGraph
- class TGraph[source]
Bases:
GraphWrapper class for pytorch-geometric edge_index providing fast adjacency look-up.
- __init__(*args, ensure_sorted=False, **kwargs)[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_indexinput is already sortedundir – boolean indicating if graph is directed. If not provided, the
edge_indexis checked to determine this value.
Methods
Initialise graph
adjlist neighbours of node
adj_weightedlist neighbours of node and corresponding edge weight :param node: source node
return nodes in breadth-first-search order
Find the (weakly)-connected components.
return list of edges where each edge is a tuple
(source, target)return list of edges where each edge is a tuple
(source, target, weight)from_networkxfrom_tghas_node_labelslccfind the neighbourhood of a set of source nodes
List all nodes in the largest connected component
find induced subgraph for a set of nodes
Convert to different graph type or move to device
convert graph to NetworkX format
Attributes
devicedevice holding graph data
nodesnum_edgesnum_featuresweightedboolean indicating if graph is weighted
num_nodesnumber of nodes
degreetensor of node degrees
adj_indexadjacency index such that edges starting at node
iare given byedge_index[:, adj_index[i]:adj_index[i+1]]strengthtensor of node strength
weights- neighbourhood(nodes: Tensor, 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
- subgraph(nodes: Tensor, relabel=False, keep_x=True, keep_y=True)[source]
find induced subgraph for a set of nodes
- Parameters:
nodes – node indeces
- Returns:
subgraph
- connected_component_ids()[source]
Find the (weakly)-connected components. Component ids are sorted by size, such that id=0 corresponds to the largest connected component
- to(*args, graph_cls=None, **kwargs)[source]
Convert to different graph type or move to device
- Parameters:
graph_cls – convert to graph class
device – convert to device
Can only specify one argument. If positional, type of move is determined automatically.