gammagl.utils.k_hop_subgraph¶
- class k_hop_subgraph(node_idx, num_hops, edge_index, relabel_nodes=False, num_nodes=None, reverse=False)[source]¶
Computes the induced subgraph of
edge_indexaround all nodes innode_idxreachable within \(k\) hops. Theflowargument denotes the direction of edges for finding \(k\)-hop neighbors. If set to"source_to_target", then the method will find all neighbors that point to the initial set of seed nodes innode_idx.This mimics the natural flow of message passing in Graph Neural Networks. The method returns (1) the nodes involved in the subgraph, (2) the filterededge_indexconnectivity, (3) the mapping from node indices innode_idxto their new location, and (4) the edge mask indicating which edges were preserved.- Parameters:
node_idx (int, list, tuple, tensor) – The central seed node(s).
num_hops (int) – The number of hops \(k\).
edge_index (tensor) – The edge indices.
relabel_nodes (bool, optional) – If set to
True, the resultingedge_indexwill be relabeled to hold consecutive indices starting from zero. (default:False)num_nodes (int, optional) – The number of nodes, i.e.
max_val + 1ofedge_index. (default:None)reverse (bool, optional) – The flow direction of \(k\)-hop,
Falsefor “source to target” or vice versa.