mindspore_gl.nn.GINConv
- class mindspore_gl.nn.GINConv(activation, init_eps=0.0, learn_eps=False, aggregation_type='sum')[source]
Graph isomorphic network layer. From the paper 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)\]If weights are provided on each edge, the weighted graph convolution is defined as:
\[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)\]- Parameters
- Inputs:
x (Tensor): The input node features. The shape is \((N,*)\) where \(N\) is the number of nodes, and \(*\) could be of any shape.
edge_weight (Tensor): The input edge weights. The shape is \((M,*)\) where \(M\) is the number of nodes, and \(*\) could be of any shape.
g (Graph): The input graph.
- Outputs:
Tensor, output node features. The shape is \((N, out\_feat\_size)\).
- Raises
TypeError – If activation is not a mindspore.nn.Cell.
TypeError – If init_eps is not a float.
TypeError – If learn_eps is not a bool.
SyntaxError – Raised when the aggregation_type not in
'sum'
,'max'
and'avg'
.
- Supported Platforms:
Ascend
GPU
Examples
>>> 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)