RandomWalkPE¶
-
class
dgl.transforms.
RandomWalkPE
(k, feat_name='PE', eweight_name=None)[source]¶ Bases:
dgl.transforms.module.BaseTransform
Random Walk Positional Encoding, as introduced in Graph Neural Networks with Learnable Structural and Positional Representations
This module only works for homogeneous graphs.
- Parameters
k (int) – Number of random walk steps. The paper found the best value to be 16 and 20 for two experiments.
feat_name (str, optional) – Name to store the computed positional encodings in ndata.
eweight_name (str, optional) – Name to retrieve the edge weights. Default: None, not using the edge weights.
Example
>>> import dgl >>> from dgl import RandomWalkPE
>>> transform = RandomWalkPE(k=2) >>> g = dgl.graph(([0, 1, 1], [1, 1, 0])) >>> g = transform(g) >>> print(g.ndata['PE']) tensor([[0.0000, 0.5000], [0.5000, 0.7500]])