HeatKernel(t=2.0, eweight_name='w', eps=None, avg_degree=5)[source]¶
Apply heat kernel to an input graph for diffusion, as introduced in Diffusion kernels on graphs and other discrete structures.
A sparsification will be applied to the weighted adjacency matrix after diffusion. Specifically, edges whose weight is below a threshold will be dropped.
This module only works for homogeneous graphs.
t (float, optional) – Diffusion time, which commonly lies in \([2, 10]\).
eweight_name (str, optional) –
edataname 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
epsis not given.
>>> import dgl >>> import torch >>> from dgl import HeatKernel
>>> transform = HeatKernel(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.1353, 0.1353, 0.1353, 0.0541, 0.0406, 0.1353, 0.1353, 0.0812, 0.1353, 0.1083, 0.0541, 0.1353])