mindspore_gl.nn.SumPooling

查看源文件
class mindspore_gl.nn.SumPooling[源代码]

将求和池化应用于批处理图形中的节点。

\[r^{(i)} = \sum_{k=1}^{N_i} x^{(i)}_k\]
输入:
  • x (Tensor) - 要更新的输入节点特征。Shape为 \((N, D)\), 其中 \(N\) 是节点数, \(D\) 是节点的特征大小。

  • g (BatchedGraph) - 输入图。

输出:
  • x (Tensor) - 图形的输出表示。Shape为 \((2, D_{out})\) 其中 \(D_{out}\) 是节点的特征大小

支持平台:

Ascend GPU

样例:

>>> import numpy as np
>>> import mindspore as ms
>>> from mindspore_gl.nn import MaxPooling
>>> from mindspore_gl import BatchedGraphField
>>> n_nodes = 7
>>> n_edges = 8
>>> src_idx = ms.Tensor([0, 2, 2, 3, 4, 5, 5, 6], ms.int32)
>>> dst_idx = ms.Tensor([1, 0, 1, 5, 3, 4, 6, 4], ms.int32)
>>> ver_subgraph_idx = ms.Tensor([0, 0, 0, 1, 1, 1, 1], ms.int32)
>>> edge_subgraph_idx = ms.Tensor([0, 0, 0, 1, 1, 1, 1, 1], ms.int32)
>>> graph_mask = ms.Tensor([1, 1], ms.int32)
>>> batched_graph_field = BatchedGraphField(src_idx, dst_idx, n_nodes, n_edges, ver_subgraph_idx,
...                                         edge_subgraph_idx, graph_mask)
>>> node_feat = np.random.random((n_nodes, 4))
>>> node_feat = ms.Tensor(node_feat, ms.float32)
>>> net = MaxPooling()
>>> ret = net(node_feat, *batched_graph_field.get_batched_graph())
>>> print(ret.shape)
(2, 4)