GDC

class dgl.transforms.GDC(coefs, eweight_name='w', eps=None, avg_degree=5)[source]

Bases: BaseTransform

将图扩散卷积(GDC)应用于输入图,如扩散改进图学习中介绍的那样。

扩散后将应用于加权邻接矩阵的稀疏化。 具体来说,权重低于阈值的边将被删除。

该模块仅适用于同构图。

Parameters:
  • coefs (list[float], optional) – 系数列表。每个邻接矩阵幂的 \(\theta_k\)

  • 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 GDC
>>> transform = GDC([0.3, 0.2, 0.1], 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.3000, 0.3000, 0.0200, 0.3000, 0.0400, 0.3000, 0.1000, 0.0600, 0.3000,
        0.0800, 0.0200, 0.3000])