PNAConv
- class dgl.nn.pytorch.conv.PNAConv(in_size, out_size, aggregators, scalers, delta, dropout=0.0, num_towers=1, edge_feat_size=0, residual=True)[source]
Bases:
Module
来自图网络的主邻域聚合的主邻域聚合层
PNA层由多个PNA塔组成。每个塔接收输入特征的一部分,并按照以下方式计算消息传递。
\[h_i^(l+1) = U(h_i^l, \oplus_{(i,j)\in E}M(h_i^l, e_{i,j}, h_j^l))\]其中 \(h_i\) 和 \(e_{i,j}\) 分别是节点特征和边特征。 \(M\) 和 \(U\) 是MLPs,接收输入的连接以计算输出特征。 \(\oplus\) 表示各种聚合器和缩放器的组合。聚合器从邻居聚合消息,缩放器以不同方式缩放聚合的消息。 \(\oplus\) 连接每个组合的输出特征。
多个塔的输出被连接并输入到一个线性混合层以生成最终输出。
- Parameters:
in_size (int) – Input feature size; i.e. the size of \(h_i^l\).
out_size (int) – Output feature size; i.e. the size of \(h_i^{l+1}\).
聚合函数名称列表(每个聚合器指定了一种聚合邻居消息的方式),从以下选项中选择:
mean
: 邻居消息的平均值max
: 邻居消息的最大值min
: 邻居消息的最小值std
: 邻居消息的标准差var
: 邻居消息的方差sum
: 邻居消息的总和moment3
,moment4
,moment5
: 归一化矩聚合
\((E[(X-E[X])^n])^{1/n}\)
缩放函数名称列表,从以下选项中选择:
identity
: 不进行缩放amplification
: 将聚合的消息乘以 \(\log(d+1)/\delta\),
其中 \(d\) 是节点的度数。
attenuation
: 将聚合的消息乘以 \(\delta/\log(d+1)\)
delta (float) – 在训练集上计算的与度数相关的归一化因子,用于归一化的缩放器。 \(E[\log(d+1)]\),其中 \(d\) 是训练集中每个节点的度数。
dropout (float, optional) – 丢弃率。默认值:0.0。
num_towers (int, optional) – 使用的塔的数量。默认值:1。请注意,in_size 和 out_size 必须能被 num_towers 整除。
edge_feat_size (int, 可选) – 边的特征大小。默认值:0。
residual (bool, optional) – 布尔标志,用于确定是否为输出添加残差连接。默认值:True。如果PNA卷积层的in_size和out_size不相同,此标志将被强制设置为False。
示例
>>> import dgl >>> import torch as th >>> from dgl.nn import PNAConv >>> >>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3])) >>> feat = th.ones(6, 10) >>> conv = PNAConv(10, 10, ['mean', 'max', 'sum'], ['identity', 'amplification'], 2.5) >>> ret = conv(g, feat)
- forward(graph, node_feat, edge_feat=None)[source]
Description
计算PNA层。
- param graph:
图表。
- type graph:
DGLGraph
- param node_feat:
The input feature of shape \((N, h_n)\). \(N\) is the number of nodes, and \(h_n\) must be the same as in_size.
- type node_feat:
torch.Tensor
- param edge_feat:
The edge feature of shape \((M, h_e)\). \(M\) is the number of edges, and \(h_e\) must be the same as edge_feat_size.
- type edge_feat:
torch.Tensor, 可选的
- returns:
输出节点特征的形状为 \((N, h_n')\),其中 \(h_n'\) 应与 out_size 相同。
- rtype:
torch.Tensor