dgl.linkx_homophily
- dgl.linkx_homophily(graph, y)[源码]
来自论文 Large Scale Learning on Non-Homophilous Graphs: New Benchmarks and Strong Simple Methods 的同配性度量。
数学定义如下:
\[\frac{1}{C-1} \sum_{k=1}^{C} \max \left(0, \frac{\sum_{v\in C_k}|\{u\in \mathcal{N}(v): y_v = y_u \}|}{\sum_{v\in C_k}|\mathcal{N}(v)|} - \frac{|\mathcal{C}_k|}{|\mathcal{V}|} \right),\]其中 \(C\) 是节点类别的数量,\(C_k\) 是属于类别 k 的节点集合,\(\mathcal{N}(v)\) 是节点 \(v\) 的前驱节点集合,\(y_v\) 是节点 \(v\) 的类别,\(\mathcal{V}\) 是节点集合。
示例
>>> import dgl >>> import torch
>>> 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