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

来自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} \]

其中 \(h_{i}^{l}\) 是第 \(l\) 层节点 \(i\) 的特征, \(e_{ij}^{l}\) 是第 \(l\) 层边 \(ij\) 的特征, \(\sigma\) 是 sigmoid 函数,\(\varepsilon\) 是一个小的固定常数 用于数值稳定性,\(A^l, B^l, C^l, D^l, E^l\) 是线性层。

Parameters:
  • input_feats (int) – 输入特征大小;即\(h_{i}^{l}\)的维度数。

  • edge_feats (int) – 边特征大小;即 \(e_{ij}^{l}\) 的维度数。

  • output_feats (int) – 输出特征大小;即 \(h_{i}^{l+1}\) 的维度数。

  • dropout (float, optional) – 节点和边特征的丢弃率。默认值:0

  • batch_norm (bool, optional) – 是否在节点和边特征上包含批量归一化。默认值:True

  • 残差 (bool, 可选) – 是否包含残差连接。默认值:True

  • activation (可调用的激活函数/层None, 可选) – 如果不为None,则对更新后的节点特征应用激活函数。 默认值:F.relu

示例

>>> 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

计算门控图卷积层。

param 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:

输入边的特征形状为 \((E, D_{edge})\), 其中 \(E\) 是边的数量,\(D_{edge}\) 是边特征的大小。

type edge_feat:

torch.Tensor

returns:
  • torch.Tensor – 输出节点特征的形状为 \((N, D_{out})\),其中 \(D_{out}\) 是输出特征的大小。

  • torch.Tensor – 输出边特征的形状为 \((E, D_{out})\),其中 \(D_{out}\) 是输出特征的大小。