Positional Encoding

Positional Encoding Methods

GeometricFlux.positional_encodeFunction
positional_encode(RandomWalkPE{K}, A)

Returns positional encoding (PE) of size (K, N) where N is node number. PE is generated by K-step random walk over given graph.

Arguments

  • K::Int: First dimension of PE.
  • A: Adjacency matrix of a graph.

See also RandomWalkPE for random walk method.

source
positional_encode(LaplacianPE{K}, A)

Returns positional encoding (PE) of size (K, N) where N is node number. PE is generated from eigenvectors of a graph Laplacian truncated by K.

Arguments

  • K::Int: First dimension of PE.
  • A: Adjacency matrix of a graph.

See also LaplacianPE for graph Laplacian method.

source

Positional Encoding Layers

$E(n)$-equivariant Positional Encoding Layer

It employs message-passing scheme and can be defined by following functions:

  • message function: $y_{ij}^l = (x_i^l - x_j^l)\phi_x(m_{ij})$
  • aggregate: $y_i^l = \frac{1}{M} \sum_{j \in \mathcal{N}(i)} y_{ij}^l$
  • update function: $x_i^{l+1} = x_i^l + y_i^l$

where $x_i^l$ and $x_j^l$ denote the positional feature for node $i$ and $j$, respectively, in $l$-th layer, $\phi_x$ is the neural network for positional encoding and $m_{ij}$ is the edge feature for edge $(i,j)$. $y_{ij}^l$ and $y_i^l$ represent the encoded positional feature and aggregated positional feature, respectively, and $M$ denotes number of neighbors of node $i$.

GeometricFlux.EEquivGraphPEType
EEquivGraphPE(in_dim=>out_dim; init=glorot_uniform, bias=true)

E(n)-equivariant positional encoding layer.

Arguments

  • in_dim::Int: dimension of input positional feature.
  • out_dim::Int: dimension of output positional feature.
  • init: neural network initialization function.
  • bias::Bool: dimension of edge feature.

Examples

julia> in_dim_edge, out_dim = 2, 5
(2, 5)

julia> l = EEquivGraphPE(in_dim_edge=>out_dim)
EEquivGraphPE(2 => 5)

See also EEquivGraphConv.

source

Reference: Victor Garcia Satorras, Emiel Hoogeboom, Max Welling (2021)


Learnable Structural Positional Encoding layer

(WIP)

GeometricFlux.LSPEType
LSPE(fg, f_h, f_e, f_p, k; pe_method=RandomWalkPE)

Learnable structural positional encoding layer. LSPE layer can be seen as a GNN layer warpped in WithGraph.

Arguments

  • fg::FeaturedGraph: A given graoh for positional encoding.
  • f_h::MessagePassing: Neural network layer for node update.
  • f_e: Neural network layer for edge update.
  • f_p: Neural network layer for positional encoding.
  • k::Int: Dimension of positional encoding.
  • pe_method: Initializer for positional encoding.
source

Reference: Vijay Prakash Dwivedi, Anh Tuan Luu, Thomas Laurent, Yoshua Bengio, Xavier Bresson (2021)