Implements the Graph Isomorphism Network (GIN) layer:
$$\mathbf{h}_i^{(k)} = \text{MLP}^{(k)}\left((1 + \epsilon^{(k)}) \cdot \mathbf{h}_i^{(k-1)} + \sum_{j \in \mathcal{N}(i)} \mathbf{h}_j^{(k-1)}\right)$$
This layer:
Aggregates neighbor features via summation
Adds weighted self features using learnable epsilon
Applies MLP transformation
Parameters:
MLP: Multi-layer perceptron (typically 2 layers)
epsilon: Learnable or fixed weight for self features
Details
The MLP is constructed as a sequence of Linear-BatchNorm-ReLU-Linear layers. The epsilon parameter can be learned or fixed at 0.
Forward pass
layer(x, adj)
x: Tensorn_nodes x in_features. Node feature matrix.adj: Sparse COO tensorn_nodes x n_nodes. Adjacency matrix defining graph structure.
References
Xu, K., Hu, W., Leskovec, J., & Jegelka, S. (2019). How Powerful are Graph Neural Networks? International Conference on Learning Representations. doi:10.48550/arXiv.1810.00826
Examples
if (FALSE) { # torch::torch_is_installed()
adj <- adj_from_edgelist(from = c(1, 2, 3, 4), to = c(2, 3, 4, 1))
x <- torch::torch_randn(4, 8)
layer <- layer_gin(8, 4)
layer(x, adj)
# Learn the weight given to a node's own features
layer <- layer_gin(8, 4, learn_eps = TRUE)
layer(x, adj)
}