mindspore_gl.nn.GCNConv
- class mindspore_gl.nn.GCNConv(in_feat_size: int, out_size: int, activation=None, dropout=0.5)[source]
Graph Convolution Network Layer. From the paper Semi-Supervised Classification with Graph Convolutional Networks .
\[h_i^{(l+1)} = \sigma(b^{(l)} + \sum_{j\in\mathcal{N}(i)}\frac{1}{c_{ji}}h_j^{(l)}W^{(l)})\]\(\mathcal{N}(i)\) represents the neighbour node of \(i\). \(c_{ji} = \sqrt{|\mathcal{N}(j)|}\sqrt{|\mathcal{N}(i)|}\).
\[h_i^{(l+1)} = \sigma(b^{(l)} + \sum_{j\in\mathcal{N}(i)}\frac{e_{ji}}{c_{ji}}h_j^{(l)}W^{(l)})\]- Parameters
in_feat_size (int) – Input node feature size.
out_size (int) – Output node feature size.
activation (Cell, optional) – Activation function. Default:
None
.dropout (float, optional) – The dropout rate, greater than 0 and less equal than 1. E.g. dropout=0.1, dropping out 10% of input units. Default:
0.5
.
- Inputs:
x (Tensor) - The input node features. The shape is \((N, D_{in})\) where \(N\) is the number of nodes, and \(D_{in}\) should be equal to in_feat_size in Args.
in_deg (Tensor) - In degree for nodes. The shape is \((N, )\) where \(N\) is the number of nodes.
out_deg (Tensor) - Out degree for nodes. The shape is \((N, )\) where \(N\) is the number of nodes.
g (Graph) - The input graph.
- Outputs:
Tensor, output node features with shape of \((N, D_{out})\), where \((D_{out})\) should be the same as out_size in Args.
- Raises
TypeError – If in_feat_size or out_size is not an int.
TypeError – If dropout is not a float.
TypeError – If activation is not a mindspore.nn.Cell.
ValueError – If dropout is not in range (0.0, 1.0]
- Supported Platforms:
Ascend
GPU
Examples
>>> import mindspore as ms >>> from mindspore_gl.nn import GCNConv >>> 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) >>> gcnconv = GCNConv(in_feat_size=4, out_size=2, activation=None, dropout=1.0) >>> res = gcnconv(feat, in_degree, out_degree, *graph_field.get_graph()) >>> print(res.shape) (4, 2)