CFConv

class dgl.nn.pytorch.conv.CFConv(node_in_feats, edge_in_feats, hidden_feats, out_feats)[source]

Bases: Module

CFConv from SchNet: A continuous-filter convolutional neural network for modeling quantum interactions

It combines node and edge features in message passing and updates node representations.

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

where \(\circ\) represents element-wise multiplication and for \(\text{SPP}\) :

\[\text{SSP}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x)) - \log(\text{shift})\]
Parameters:
  • node_in_feats (int) – Size for the input node features \(h_j^{(l)}\).

  • edge_in_feats (int) – Size for the input edge features \(e_ij\).

  • hidden_feats (int) – Size for the hidden representations.

  • out_feats (int) – Size for the output representations \(h_j^{(l+1)}\).

Example

>>> import dgl
>>> import numpy as np
>>> import torch as th
>>> from dgl.nn import CFConv
>>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3]))
>>> nfeat = th.ones(6, 10)
>>> efeat = th.ones(6, 5)
>>> conv = CFConv(10, 5, 3, 2)
>>> res = conv(g, nfeat, efeat)
>>> res
tensor([[-0.1209, -0.2289],
        [-0.1209, -0.2289],
        [-0.1209, -0.2289],
        [-0.1135, -0.2338],
        [-0.1209, -0.2289],
        [-0.1283, -0.2240]], grad_fn=<SubBackward0>)
forward(g, node_feats, edge_feats)[source]

Description

Performs message passing and updates node representations.

param g:

The graph.

type g:

DGLGraph

param node_feats:

The input node features. If a torch.Tensor is given, it represents the input node feature of shape \((N, D_{in})\) where \(D_{in}\) is size of input feature, \(N\) is the number of nodes. If a pair of torch.Tensor is given, which is the case for bipartite graph, the pair must contain two tensors of shape \((N_{src}, D_{in_{src}})\) and \((N_{dst}, D_{in_{dst}})\) separately for the source and destination nodes.

type node_feats:

torch.Tensor or pair of torch.Tensor

param edge_feats:

The input edge feature of shape \((E, edge_in_feats)\) where \(E\) is the number of edges.

type edge_feats:

torch.Tensor

returns:

The output node feature of shape \((N_{out}, out_feats)\) where \(N_{out}\) is the number of destination nodes.

rtype:

torch.Tensor