mindspore_gl.nn.GINConv

查看源文件
class mindspore_gl.nn.GINConv(activation, init_eps=0.0, learn_eps=False, aggregation_type='sum')[源代码]

图同构网络层。 从论文 How Powerful are Graph Neural Networks?

\[h_i^{(l+1)} = f_\Theta \left((1 + \epsilon) h_i^{l} + \mathrm{aggregate}\left(\left\{h_j^{l}, j\in\mathcal{N}(i) \right\}\right)\right)\]

如果提供了各个边权重,则加权图卷积定义为:

\[h_i^{(l+1)} = f_\Theta \left((1 + \epsilon) h_i^{l} + \mathrm{aggregate}\left(\left\{e_{ji} h_j^{l}, j\in\mathcal{N}(i) \right\}\right)\right)\]
参数:
  • activation (mindspore.nn.Cell) - 激活函数。

  • init_eps (float, 可选) - eps的初始化值。默认值:0.0

  • learn_eps (bool, 可选) - eps是否可学习。默认值:False

  • aggregation_type (str, 可选) - 聚合类型,应在 'sum''max''avg' 中。默认值:'sum'

输入:
  • x (Tensor) - 输入节点特征。Shape为 \((N,*)\) 其中 \(N\) 是节点数, \(*\) 可以是任何shape。

  • edge_weight (Tensor) - 输入边权重。Shape为 \((M,*)\) ,其中 \(M\) 是数字节点, \(*\) 可以是任何shape。

  • g (Graph) - 输入图。

输出:
  • Tensor,输出节点特征。Shape为 \((N, out\_feat\_size)\)

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

  • TypeError - 如果 init_eps 不是float。

  • TypeError - 如果 learn_eps 不是bool值。

  • SyntaxError - 当 aggregation_type 不在 'sum''max''avg' 中时引发。

支持平台:

Ascend GPU

样例:

>>> import mindspore as ms
>>> from mindspore_gl.nn import GINConv
>>> from mindspore_gl import GraphField
>>> n_nodes = 4
>>> n_edges = 8
>>> feat_size = 16
>>> src_idx = ms.Tensor([0, 0, 0, 1, 1, 1, 2, 3], ms.int32)
>>> dst_idx = ms.Tensor([0, 1, 3, 1, 2, 3, 3, 2], ms.int32)
>>> ones = ms.ops.Ones()
>>> nodes_feat = ones((n_nodes, feat_size), ms.float32)
>>> edges_weight = ones((n_edges, feat_size), ms.float32)
>>> graph_field = GraphField(src_idx, dst_idx, n_nodes, n_edges)
>>> conv = GINConv(activation=None, init_eps=0., learn_eps=False, aggregation_type="sum")
>>> ret = conv(nodes_feat, edges_weight, *graph_field.get_graph())
>>> print(ret.shape)
(4, 16)