dgl.linkx_homophily
- dgl.linkx_homophily(graph, y)[source]
同质性度量来自非同质性图上的大规模学习:新基准和强大的简单方法
数学上定义如下:
\[\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}\) 是节点的集合。
- Parameters:
- Returns:
同质性值。
- Return type:
示例
>>> 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