dgl.node_homophily

dgl.node_homophily(graph, y)[源码]

来自 Geom-GCN: Geometric Graph Convolutional Networks 的同质性度量。

我们沿用了后续论文 Large Scale Learning on Non-Homophilous Graphs: New Benchmarks and Strong Simple Methods 中的实践,将其称为节点同质性。

其数学定义如下:

\[\frac{1}{|\mathcal{V}|} \sum_{v \in \mathcal{V}} \frac{ | \{u \in \mathcal{N}(v): y_v = y_u \} | } { |\mathcal{N}(v)| },\]

其中,\(\mathcal{V}\) 是节点集合,\(\mathcal{N}(v)\) 是节点 \(v\) 的前驱节点,以及 \(y_v\) 是节点 \(v\) 的类别。

参数:
  • graph (DGLGraph) – 图。

  • y (torch.Tensor) – 节点标签,形状为 (|V|) 的张量。

返回:

节点同质性值。

返回类型:

float

示例

>>> import dgl
>>> import torch
>>> graph = dgl.graph(([1, 2, 0, 4], [0, 1, 2, 3]))
>>> y = torch.tensor([0, 0, 0, 0, 1])
>>> dgl.node_homophily(graph, y)
0.6000000238418579