PPR
- class dgl.transforms.PPR(alpha=0.15, eweight_name='w', eps=None, avg_degree=5)[source]
Bases:
BaseTransform
对输入图应用个性化PageRank(PPR)进行扩散,如The pagerank citation ranking: Bringing order to the web中介绍的那样。
扩散后将应用于加权邻接矩阵的稀疏化。 具体来说,权重低于阈值的边将被删除。
该模块仅适用于同构图。
- Parameters:
alpha (float, optional) – 重启概率,通常位于 \([0.05, 0.2]\) 之间。
eweight_name (str, optional) –
edata
name to retrieve and store edge weights. If it does not exist in an input graph, this module initializes a weight of 1 for all edges. The edge weights should be a tensor of shape \((E)\), where E is the number of edges.eps (float, optional) – The threshold to preserve edges in sparsification after diffusion. Edges of a weight smaller than eps will be dropped.
avg_degree (int, optional) – The desired average node degree of the result graph. This is the other way to control the sparsity of the result graph and will only be effective if
eps
is not given.
示例
>>> import dgl >>> import torch >>> from dgl import PPR
>>> transform = PPR(avg_degree=2) >>> g = dgl.graph(([0, 1, 2, 3, 4], [2, 3, 4, 5, 3])) >>> g.edata['w'] = torch.tensor([0.1, 0.2, 0.3, 0.4, 0.5]) >>> new_g = transform(g) >>> print(new_g.edata['w']) tensor([0.1500, 0.1500, 0.1500, 0.0255, 0.0163, 0.1500, 0.0638, 0.0383, 0.1500, 0.0510, 0.0217, 0.1500])