dgl.laplacian_pe

dgl.laplacian_pe(g, k)[source]

Laplacian Positional Encoding, as introduced in Benchmarking Graph Neural Networks

This function computes the laplacian positional encodings as the k smallest non-trivial eigenvectors (k << n). k and n are the positional encoding dimensions and the number of nodes in the given graph.

Parameters
  • g (DGLGraph) – The input graph. Must be homogeneous.

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

Returns

The laplacian positional encodings of shape \((N, k)\), where \(N\) is the number of nodes in the input graph.

Return type

Tensor

Example

>>> import dgl
>>> g = dgl.rand_graph(6, 12)
>>> dgl.laplacian_pe(g, 2)
tensor([[-0.8931, -0.7713],
        [-0.0000,  0.6198],
        [ 0.2704, -0.0138],
        [-0.0000,  0.0554],
        [ 0.3595, -0.0477],
        [-0.0000,  0.1240]])