dgl.edge_homophily
- dgl.edge_homophily(graph, y)[source]
同质性测量来自 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\) 的类别。
- Parameters:
- Returns:
边缘同质性比率值。
- Return type:
示例
>>> 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