dgl.edge_homophily
- dgl.edge_homophily(graph, y)[源码]
来自论文 Beyond Homophily in Graph Neural Networks: Current Limitations and Effective Designs 的同配性度量
其数学定义如下
\[\frac{| \{ (u,v) : (u,v) \in \mathcal{E} \wedge y_u = y_v \} | } {|\mathcal{E}|},\]其中 \(\mathcal{E}\) 是边的集合,\(y_u\) 是节点 \(u\) 的类别。
示例
>>> 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