LaplacianPE

class dgl.transforms.LaplacianPE(k, feat_name='PE')[source]

Bases: dgl.transforms.module.BaseTransform

Laplacian Positional Encoding, as introduced in Benchmarking Graph Neural Networks

This module only works for homogeneous bidirected graphs.

Parameters
  • k (int) – Number of smallest non-trivial eigenvectors to use for positional encoding (smaller than the number of nodes).

  • feat_name (str, optional) – Name to store the computed positional encodings in ndata.

Example

>>> import dgl
>>> from dgl import LaplacianPE
>>> transform = LaplacianPE(k=3)
>>> g = dgl.rand_graph(5, 10)
>>> g = transform(g)
>>> print(g.ndata['PE'])
tensor([[ 0.0000, -0.3646,  0.3646],
        [ 0.0000,  0.2825, -0.2825],
        [ 1.0000, -0.6315,  0.6315],
        [ 0.0000,  0.3739, -0.3739],
        [ 0.0000, -0.1663,  0.1663]])