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

eijl+1=Dlhil+Elhjl+Cleijlnormij=ฮฃjโˆˆNiฯƒ(eijl+1)+ฮตe^ijl+1=ฯƒ(eijl+1)/normijhil+1=Alhil+ฮฃjโˆˆNie^ijl+1โŠ™Blhjl

where hil is node i feature of layer l, eijl is edge ij feature of layer l, ฯƒ is sigmoid function, ฮต is a small fixed constant for numerical stability, Al,Bl,Cl,Dl,El are linear layers.

Parameters:
  • input_feats (int) โ€“ Input feature size; i.e, the number of dimensions of hil.

  • edge_feats (int) โ€“ Edge feature size; i.e., the number of dimensions of eijl.

  • output_feats (int) โ€“ Output feature size; i.e., the number of dimensions of hil+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,Din) where N is the number of nodes of the graph and Din is the input feature size.

type feat:

torch.Tensor

param edge_feat:

The input edge feature of shape (E,Dedge), where E is the number of edges and Dedge is the size of the edge features.

type edge_feat:

torch.Tensor

returns:
  • torch.Tensor โ€“ The output node feature of shape (N,Dout) where Dout is the output feature size.

  • torch.Tensor โ€“ The output edge feature of shape (E,Dout) where Dout is the output feature size.