GatedGCNConv

class dgl.nn.pytorch.conv.GatedGCNConv(input_feats, edge_feats, output_feats, dropout=0, batch_norm=True, residual=True, activation=<function relu>)[source]

Bases: Module

Gated graph convolutional layer from Benchmarking Graph Neural Networks

\[ \begin{align}\begin{aligned}e_{ij}^{l+1}=D^l h_{i}^{l}+E^l h_{j}^{l}+C^l e_{ij}^{l}\\norm_{ij}=\Sigma_{j\in N_{i}} \sigma\left(e_{ij}^{l+1}\right)+\varepsilon\\\hat{e}_{ij}^{l+1}=\sigma(e_{ij}^{l+1}) / norm_{ij}\\h_{i}^{l+1}=A^l h_{i}^{l}+\Sigma_{j \in N_{i}} \hat{e}_{ij}^{l+1} \odot B^l h_{j}^{l}\end{aligned}\end{align} \]

where \(h_{i}^{l}\) is node \(i\) feature of layer \(l\), \(e_{ij}^{l}\) is edge \(ij\) feature of layer \(l\), \(\sigma\) is sigmoid function, \(\varepsilon\) is a small fixed constant for numerical stability, \(A^l, B^l, C^l, D^l, E^l\) are linear layers.

Parameters:
  • input_feats (int) – Input feature size; i.e, the number of dimensions of \(h_{i}^{l}\).

  • edge_feats (int) – Edge feature size; i.e., the number of dimensions of \(e_{ij}^{l}\).

  • output_feats (int) – Output feature size; i.e., the number of dimensions of \(h_{i}^{l+1}\).

  • dropout (float, optional) – Dropout rate on node and edge feature. Default: 0.

  • batch_norm (bool, optional) – Whether to include batch normalization on node and edge feature. Default: True.

  • residual (bool, optional) – Whether to include residual connections. Default: True.

  • activation (callable activation function/layer or None, optional) – If not None, apply an activation function to the updated node features. Default: F.relu.

Example

>>> import dgl
>>> import torch as th
>>> import torch.nn.functional as F
>>> from dgl.nn import GatedGCNConv
>>> num_nodes, num_edges = 8, 30
>>> graph = dgl.rand_graph(num_nodes,num_edges)
>>> node_feats = th.rand(num_nodes, 20)
>>> edge_feats = th.rand(num_edges, 12)
>>> gatedGCN = GatedGCNConv(20, 12, 20)
>>> new_node_feats, new_edge_feats = gatedGCN(graph, node_feats, edge_feats)
>>> new_node_feats.shape, new_edge_feats.shape
(torch.Size([8, 20]), torch.Size([30, 20]))
forward(graph, feat, edge_feat)[source]

Description

Compute gated graph convolution layer.

param graph:

The graph.

type graph:

DGLGraph

param feat:

The input feature of shape \((N, D_{in})\) where \(N\) is the number of nodes of the graph and \(D_{in}\) is the input feature size.

type feat:

torch.Tensor

param edge_feat:

The input edge feature of shape \((E, D_{edge})\), where \(E\) is the number of edges and \(D_{edge}\) is the size of the edge features.

type edge_feat:

torch.Tensor

returns:
  • torch.Tensor – The output node feature of shape \((N, D_{out})\) where \(D_{out}\) is the output feature size.

  • torch.Tensor – The output edge feature of shape \((E, D_{out})\) where \(D_{out}\) is the output feature size.