mindspore_gl.nn.EGConv

class mindspore_gl.nn.EGConv(in_feat_size: int, out_feat_size: int, aggregators: List[str], num_heads: int = 8, num_bases: int = 4, bias: bool = True)[source]

Efficient Graph Convolution. From the paper Adaptive Filters and Aggregator Fusion for Efficient Graph Convolutions .

\[h_i^{(l+1)} = {\LARGE ||}_{h=1}^{H} \sum_{\oplus \in \mathcal{A}} \sum_{b=1}^{B} w_{h,\oplus,b}^{(l)} \bigoplus_{j \in \mathcal{N(i)}} W_{b}^{(l)} h_{j}^{(l)}\]

\(\mathcal{N}(i)\) represents the neighbour node of \(i\), \(W_{b}^{(l)}\) represents a basis weight, \(\oplus\) represents an aggregator, \(w_{h,\oplus,b}^{(l)}\) represents per-vertex weighting coefficients across heads, aggregator and bases.

Parameters
  • in_feat_size (int) – Input node feature size.

  • out_feat_size (int) – Output node feature size.

  • aggregators (str, optional) – aggregators to be used. Supported aggregators are sum, mean, max, min, std, var, symnorm. Default: ‘symnorm’.

  • num_heads (int, optional) – Number of heads \(H\). Default: 8. Must have out_feat_size % num_heads == 0.

  • num_bases (int, optional) – Number of basis weight \(B\). Default: 4.

  • bias (bool, optional) – Whether the layer will learn an additive bias. Default: True.

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.

  • 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_feat_size in Args.

Raises
  • TypeError – If in_feat_size or out_feat_size or num_heads is not a positive int.

  • ValueError – If out_feat_size is not divisible by ‘num_heads’.

  • ValueError – If aggregators is not in [‘sum’, ‘mean’, ‘max’, ‘min’, ‘symnorm’, ‘var’, ‘std’].

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore as ms
>>> from mindspore_gl.nn import EGConv
>>> 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)
>>> conv = EGConv(in_feat_size=4, out_feat_size=6, aggregators=['sum'], num_heads=3, num_bases=3)
>>> res = conv(feat, *graph_field.get_graph())
>>> print(res.shape)
(4, 6)