dgl.edge_homophily¶
-
dgl.
edge_homophily
(graph, y)[source]¶ Homophily measure from Beyond Homophily in Graph Neural Networks: Current Limitations and Effective Designs
Mathematically it is defined as follows:
\[\frac{| \{ (u,v) : (u,v) \in \mathcal{E} \wedge y_u = y_v \} | } {|\mathcal{E}|},\]where \(\mathcal{E}\) is the set of edges, and \(y_u\) is the class of node \(u\).
- Parameters
- Returns
The edge homophily ratio value.
- Return type
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.edge_homophily(graph, y) 0.75