APPNPConv
- class dgl.nn.pytorch.conv.APPNPConv(k, alpha, edge_drop=0.0)[source]
Bases:
Module
近似个性化神经预测传播层来自 预测然后传播:图神经网络与个性化PageRank的结合
\[ \begin{align}\begin{aligned}H^{0} &= X\\H^{l+1} &= (1-\alpha)\left(\tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2} H^{l}\right) + \alpha H^{0}\end{aligned}\end{align} \]其中 \(\tilde{A}\) 是 \(A\) + \(I\)。
- Parameters:
示例
>>> import dgl >>> import numpy as np >>> import torch as th >>> from dgl.nn import APPNPConv >>> >>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3])) >>> feat = th.ones(6, 10) >>> conv = APPNPConv(k=3, alpha=0.5) >>> res = conv(g, feat) >>> print(res) tensor([[0.8536, 0.8536, 0.8536, 0.8536, 0.8536, 0.8536, 0.8536, 0.8536, 0.8536, 0.8536], [0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268], [0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634], [0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268, 0.9268], [0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634, 0.9634], [0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, 0.5000]])
- forward(graph, feat, edge_weight=None)[source]
Description
计算APPNP层。
- param graph:
图表。
- type graph:
DGLGraph
- param feat:
输入特征的形状为 \((N, *)\)。\(N\) 是节点的数量,\(*\) 可以是任何形状。
- type feat:
torch.Tensor
- param edge_weight:
在消息传递过程中使用的edge_weight。这相当于在上述方程中使用加权邻接矩阵,并且 \(\tilde{D}^{-1/2}\tilde{A} \tilde{D}^{-1/2}\) 是基于
dgl.nn.pytorch.conv.graphconv.EdgeWeightNorm
。- type edge_weight:
torch.Tensor, 可选
- returns:
The output feature of shape \((N, *)\) where \(*\) should be the same as input shape.
- rtype:
torch.Tensor