dgl.double_radius_node_labeling(g, src, dst)[source]

Double Radius Node Labeling, as introduced in Link Prediction Based on Graph Neural Networks.

This function computes the double radius node labeling for each node to mark nodes’ different roles in an enclosing subgraph, given a target link.

The node labels of source $$s$$ and destination $$t$$ are set to 1 and those of unreachable nodes from source or destination are set to 0. The labels of other nodes $$l$$ are defined according to the following hash function:

$$l = 1 + min(d_s, d_t) + (d//2)[(d//2) + (d%2) - 1]$$

where $$d_s$$ and $$d_t$$ denote the shortest distance to the source and the target, respectively. $$d = d_s + d_t$$.

Parameters
• g (DGLGraph) – The input graph.

• src (int) – The source node ID of the target link.

• dst (int) – The destination node ID of the target link.

Returns

Labels of all nodes. The tensor is of shape $$(N,)$$, where $$N$$ is the number of nodes in the input graph.

Return type

Tensor

Example

>>> import dgl

>>> g = dgl.graph(([0,0,0,0,1,1,2,4], [1,2,3,6,3,4,4,5]))
>>> dgl.double_radius_node_labeling(g, 0, 1)
tensor([1, 1, 3, 2, 3, 7, 0])