mindspore_gl.nn.TAGConv

查看源文件
class mindspore_gl.nn.TAGConv(in_feat_size: int, out_feat_size: int, num_hops: int = 2, bias: bool = True, activation=None)[源代码]

拓扑自适应图卷积层。 来自论文 Topology Adaptive Graph Convolutional Networks

\[H^{K} = {\sum}_{k=0}^K (D^{-1/2} A D^{-1/2})^{k} X {\Theta}_{k}\]

其中 \({\Theta}_{k}\) 表示线性权重加不同跳数的结果。

参数:
  • in_feat_size (int) - 输入节点特征大小。

  • out_feat_size (int) - 输出节点特征大小。

  • num_hops (int, 可选) - 跳数。默认值:2。

  • bias (bool, 可选) - 是否使用偏置。默认值:True。

  • activation (Cell, 可选) - 激活函数。默认值:None。

输入:
  • x (Tensor) - 输入节点功能。shape是 \((N, D_{in})\) ,其中 \(N\) 是节点数, 和 \(D_{in}\) 应等于参数中的 in_feat_size

  • in_deg (Tensor) - 节点的入读。shape为 \((N, )\) ,其中 \(N\) 是节点数。

  • out_deg (Tensor) - 节点的出度。shape是 \((N, )\) ,其中 \(N\) 是节点数。

  • g (Graph) - 输入图。

输出:
  • Tensor,shape为 \((N, D_{out})\) 的输出节点特征,其中 \((D_{out})\) 应与参数中的 out_feat_size 相等。

异常:
  • TypeError - 如果 in_feat_sizeout_feat_sizenum_hops 不是int。

  • TypeError - 如果 bias 不是bool。

  • TypeError - 如果 activation 不是 mindspore.nn.Cell

支持平台:

Ascend GPU

样例:

>>> import mindspore as ms
>>> from mindspore_gl.nn import TAGConv
>>> from mindspore_gl import GraphField
>>> n_nodes = 4
>>> n_edges = 7
>>> feat_size = 4
>>> src_idx = ms.Tensor([0, 1, 1, 2, 2, 3, 3], ms.int32)
>>> dst_idx = ms.Tensor([0, 0, 2, 1, 3, 0, 1], ms.int32)
>>> ones = ms.ops.Ones()
>>> feat = ones((n_nodes, feat_size), ms.float32)
>>> graph_field = GraphField(src_idx, dst_idx, n_nodes, n_edges)
>>> in_degree = ms.Tensor([3, 2, 1, 1], ms.int32)
>>> out_degree = ms.Tensor([1, 2, 1, 2], ms.int32)
>>> tagconv = TAGConv(in_feat_size=4, out_feat_size=2, activation=None, num_hops=3)
>>> res = tagconv(feat, in_degree, out_degree, *graph_field.get_graph())
>>> print(res.shape)
(4, 2)