APPNPConvΒΆ
-
class
dgl.nn.pytorch.conv.
APPNPConv
(k, alpha, edge_drop=0.0)[source]ΒΆ Bases:
torch.nn.modules.module.Module
Approximate Personalized Propagation of Neural Predictions layer from Predict then Propagate: Graph Neural Networks meet Personalized 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} \]where \(\tilde{A}\) is \(A\) + \(I\).
- Parameters
Example
>>> 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]ΒΆ Compute APPNP layer.
- Parameters
graph (DGLGraph) β The graph.
feat (torch.Tensor) β The input feature of shape \((N, *)\). \(N\) is the number of nodes, and \(*\) could be of any shape.
edge_weight (torch.Tensor, optional) β edge_weight to use in the message passing process. This is equivalent to using weighted adjacency matrix in the equation above, and \(\tilde{D}^{-1/2}\tilde{A} \tilde{D}^{-1/2}\) is based on
dgl.nn.pytorch.conv.graphconv.EdgeWeightNorm
.
- Returns
The output feature of shape \((N, *)\) where \(*\) should be the same as input shape.
- Return type
torch.Tensor