dgl.node_homophily๏ƒ

dgl.node_homophily(graph, y)[source]๏ƒ

Homophily measure from Geom-GCN: Geometric Graph Convolutional Networks

We follow the practice of a later paper Large Scale Learning on Non-Homophilous Graphs: New Benchmarks and Strong Simple Methods to call it node homophily.

Mathematically it is defined as follows:

1|V|โˆ‘vโˆˆV|{uโˆˆN(v):yv=yu}||N(v)|,

where V is the set of nodes, N(v) is the predecessors of node v, and yv is the class of node v.

Parameters:
  • graph (DGLGraph) โ€“ The graph.

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

Returns:

The node homophily value.

Return type:

float

Examples

>>> import dgl
>>> import torch
>>> graph = dgl.graph(([1, 2, 0, 4], [0, 1, 2, 3]))
>>> y = torch.tensor([0, 0, 0, 0, 1])
>>> dgl.node_homophily(graph, y)
0.6000000238418579