CFConv
- class dgl.nn.pytorch.conv.CFConv(node_in_feats, edge_in_feats, hidden_feats, out_feats)[source]
Bases:
Module
CFConv来自SchNet: 一种用于建模量子相互作用的连续滤波卷积神经网络
它在消息传递中结合了节点和边的特征,并更新节点表示。
\[h_i^{(l+1)} = \sum_{j\in \mathcal{N}(i)} h_j^{l} \circ W^{(l)}e_ij\]其中 \(\circ\) 表示元素乘法,对于 \(\text{SPP}\) :
\[\text{SSP}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x)) - \log(\text{shift})\]- Parameters:
示例
>>> 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
执行消息传递并更新节点表示。
- param g:
图表。
- type g:
DGLGraph
- param node_feats:
输入节点特征。如果给定的是torch.Tensor,它表示形状为\((N, D_{in})\)的输入节点特征,其中\(D_{in}\)是输入特征的大小,\(N\)是节点的数量。如果给定的是torch.Tensor对,这是二分图的情况,这对必须包含两个形状分别为\((N_{src}, D_{in_{src}})\)和\((N_{dst}, D_{in_{dst}})\)的张量,分别用于源节点和目标节点。
- type node_feats:
torch.Tensor 或一对 torch.Tensor
- param edge_feats:
输入边的特征形状为 \((E, edge_in_feats)\),其中 \(E\) 是边的数量。
- type edge_feats:
torch.Tensor
- returns:
输出节点特征的形状为 \((N_{out}, out_feats)\),其中 \(N_{out}\) 是目标节点的数量。
- rtype:
torch.Tensor