APPNPConvο

class dgl.nn.pytorch.conv.APPNPConv(k, alpha, edge_drop=0.0)[source]ο

Bases: 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:
• k (int) β The number of iterations $$K$$.

• alpha (float) β The teleport probability $$\alpha$$.

• edge_drop (float, optional) β The dropout rate on edges that controls the messages received by each node. Default: 0.

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]ο

Descriptionο

Compute APPNP layer.

param graph:

The graph.

type graph:

DGLGraph

param feat:

The input feature of shape $$(N, *)$$. $$N$$ is the number of nodes, and $$*$$ could be of any shape.

type feat:

torch.Tensor

param edge_weight:

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.

type edge_weight:

torch.Tensor, optional

returns:

The output feature of shape $$(N, *)$$ where $$*$$ should be the same as input shape.

rtype:

torch.Tensor