GatedGraphConvΒΆ

class dgl.nn.mxnet.conv.GatedGraphConv(in_feats, out_feats, n_steps, n_etypes, bias=True)[source]ΒΆ

Bases: mxnet.gluon.block.Block

Gated Graph Convolution layer from Gated Graph Sequence Neural Networks

\[ \begin{align}\begin{aligned}h_{i}^{0} &= [ x_i \| \mathbf{0} ]\\a_{i}^{t} &= \sum_{j\in\mathcal{N}(i)} W_{e_{ij}} h_{j}^{t}\\h_{i}^{t+1} &= \mathrm{GRU}(a_{i}^{t}, h_{i}^{t})\end{aligned}\end{align} \]
Parameters
  • in_feats (int) – Input feature size; i.e, the number of dimensions of \(x_i\).

  • out_feats (int) – Output feature size; i.e., the number of dimensions of \(h_i^{(t+1)}\).

  • n_steps (int) – Number of recurrent steps; i.e, the \(t\) in the above formula.

  • n_etypes (int) – Number of edge types.

  • bias (bool) – If True, adds a learnable bias to the output. Default: True. Can only be set to True in MXNet.

Example

>>> import dgl
>>> import numpy as np
>>> import mxnet as mx
>>> from dgl.nn import GatedGraphConv
>>>
>>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3]))
>>> feat = mx.nd.ones((6, 10))
>>> conv = GatedGraphConv(10, 10, 2, 3)
>>> conv.initialize(ctx=mx.cpu(0))
>>> etype = mx.nd.array([0,1,2,0,1,2])
>>> res = conv(g, feat, etype)
>>> res
[[0.24378185 0.17402579 0.2644723  0.2740628  0.14041871 0.32523093
0.2703067  0.18234392 0.32777587 0.30957845]
[0.17872348 0.28878236 0.2509409  0.20139427 0.3355541  0.22643831
0.2690711  0.22341749 0.27995753 0.21575949]
[0.23911178 0.16696918 0.26120248 0.27397877 0.13745922 0.3223175
0.27561218 0.18071817 0.3251124  0.30608907]
[0.25242943 0.3098581  0.25249368 0.27968448 0.24624602 0.12270881
0.335147   0.31550157 0.19065917 0.21087633]
[0.17503153 0.29523152 0.2474858  0.20848347 0.3526433  0.23443702
0.24741334 0.21986549 0.28935105 0.21859099]
[0.2159364  0.26942077 0.23083271 0.28329757 0.24758333 0.24230732
0.23958017 0.23430146 0.26431587 0.27001363]]
<NDArray 6x10 @cpu(0)>
forward(graph, feat, etypes)[source]ΒΆ

Compute Gated Graph Convolution layer.

Parameters
  • graph (DGLGraph) – The graph.

  • feat (mxnet.NDArray) – 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.

  • etypes (torch.LongTensor) – The edge type tensor of shape \((E,)\) where \(E\) is the number of edges of the graph.

Returns

The output feature of shape \((N, D_{out})\) where \(D_{out}\) is the output feature size.

Return type

mxnet.NDArray