mindspore_gl.nn.CFConv

class mindspore_gl.nn.CFConv(node_feat_size: int, edge_feat_size: int, hidden_size: int, out_size: int)[source]

CFConv in SchNet. From the paper SchNet: A continuous-filter convolutional neural network for modeling quantum interactions .

It combines node and edge features in messaging and updates node representations.

\[h_i^{(l+1)} = \sum_{j\in \mathcal{N}(i)} h_j^{l} \circ W^{(l)}e_ij\]

Where \(SPP\) represents:

\[\text{SSP}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x)) - \log(\text{shift})\]
Parameters
  • node_feat_size (int) – Node feature size.

  • edge_feat_size (int) – Edge feature size.

  • hidden_size (int) – Hidden layer size.

  • out_size (int) – Output classes size.

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_feats (Tensor): The input edge features. The shape is \((M,*)\) where \(M\) is the number of edges, and \(*\) could be of any shape.

  • g (Graph): The input graph.

Outputs:
  • Tensor, output node features. The shape is \((N, out\_size)\).

Raises
  • TypeError – If ‘node_feat_size’ is not a positive int.

  • TypeError – If ‘edge_feat_size’ is not a positive int.

  • TypeError – If ‘hidden_size’ is not a positive int.

  • TypeError – If ‘out_size’ is not a positive int.

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore as ms
>>> from mindspore_gl.nn import CFConv
>>> 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_feat = ones((n_edges, feat_size), ms.float32)
>>> graph_field = GraphField(src_idx, dst_idx, n_nodes, n_edges)
>>> hidden_size = 8
>>> out_size = 4
>>> conv = CFConv(feat_size, feat_size, hidden_size, out_size)
>>> ret = conv(nodes_feat, edges_feat, *graph_field.get_graph())
>>> print(ret.shape)
(4, 4)