dgl.edge_homophily

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

来自论文 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\) 的类别。

参数:
  • 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.edge_homophily(graph, y)
0.75