mindspore_gl.nn.SGConv

class mindspore_gl.nn.SGConv(in_feat_size: int, out_feat_size: int, num_hops: int = 1, cached: bool = True, bias: bool = True, norm=None)[源代码]

简化的图卷积层。 来自论文 Simplifying Graph Convolutional Networks

\[H^{K} = (\tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2})^K X \Theta\]

其中 \(\tilde{A}=A+I\)

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

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

  • num_hops (int) - hop的数量。默认值:1。

  • cached (bool) - 是否使用缓存。默认值:True。

  • bias (bool) - 是否使用偏差。默认值:True。

  • norm (mindspore.nn.Cell) - 归一化函数Cell。默认值为None。

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

  • in_deg (Tensor) - 节点的入度。Shape为 \((N,)\) 是节点数。

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

  • g (Graph) - 输入图。

输出:
  • Tensor,Shape为 \((N,D_{out})\) 的输出节点特征,其中 \((D_{out})\) 应与 Args 中的 out_feat_size

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

  • TypeError - 如果 biascached 不是bool。

  • TypeError - 如果 norm 不是mindspore.nn.Cell。

支持平台:

Ascend GPU (PYNATIVE MODE ONLY)

样例:

>>> import mindspore as ms
>>> import mindspore.context as context
>>> from mindspore_gl.nn import SGConv
>>> from mindspore_gl import GraphField
>>> context.set_context(device_target="GPU", mode=context.PYNATIVE_MODE)
>>> n_nodes = 4
>>> n_edges = 8
>>> 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)
>>> in_deg = ms.Tensor([1, 2, 2, 3], ms.int32)
>>> out_deg = ms.Tensor([3, 3, 1, 1], ms.int32)
>>> feat_size = 4
>>> in_feat_size = feat_size
>>> nh = ms.ops.Ones()((n_nodes, feat_size), ms.float32)
>>> eh = ms.ops.Ones()((n_edges, feat_size), ms.float32)
>>> g = GraphField(src_idx, dst_idx, n_nodes, n_edges)
>>> in_deg = in_deg
>>> out_deg = out_deg
>>> sgconv = SGConv(in_feat_size, feat_size)
>>> res = sgconv(nh, in_deg, out_deg, *g.get_graph())
>>> print(res.shape)
(4, 4)