dgl.linkx_homophilyΒΆ

dgl.linkx_homophily(graph, y)[source]ΒΆ

Homophily measure from Large Scale Learning on Non-Homophilous Graphs: New Benchmarks and Strong Simple Methods

Mathematically it is defined as follows:

1Cβˆ’1Cβˆ‘k=1max(0,βˆ‘v∈Ck|{u∈N(v):yv=yu}|βˆ‘v∈Ck|N(v)|βˆ’|Ck||V|),

where C is the number of node classes, Ck is the set of nodes that belong to class k, N(v) are the predecessors of node v, yv is the class of node v, and V is the set of nodes.

Parameters
  • graph (DGLGraph) – The graph.

  • y (torch.Tensor) – The node labels, which is a tensor of shape (|V|).

Returns

The homophily value.

Return type

float

Examples

>>> import dgl
>>> import torch
Copy to clipboard
>>> graph = dgl.graph(([0, 1, 2, 3], [1, 2, 0, 4]))
>>> y = torch.tensor([0, 0, 0, 0, 1])
>>> dgl.linkx_homophily(graph, y)
0.19999998807907104
Copy to clipboard