dgl.node_homophily

dgl.node_homophily(graph, y)[source]

同质性测量来自 Geom-GCN: 几何图卷积网络

我们遵循后来一篇论文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\) 的类别。

Parameters:
  • graph (DGLGraph) – The graph.

  • y (torch.Tensor) – The node labels, which is a tensor of shape (|V|).

Returns:

节点同质性值。

Return type:

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