average_neighbor_degree 方法如何在 networkX 中用于有向图?

How does average_neighbor_degree method works in networkX for directed graphs?

谁能解释一下来自 networkX 的方法 average_neighbor_degree 是如何工作的? 对于普通图(非定向),结果与我的直觉和我的手算相符,但我对有向图有疑问——我不明白它是如何计算的,我的手算给出了与这种方法不同的结果。 我的图表:

[有向图示例]

我已经 运行 average_neighbor_degree 与参数 source 和 [=25= 的所有可能组合]target 表示有向图的基本属性。这是我的代码和结果:

G = nx.DiGraph([(0, 3), (1, 3), (2, 4), (3, 5), (3, 6), (4, 6), (6, 5), (4, 3)])

print(f'in-in: {nx.average_neighbor_degree(G, source="in", target= "in")}')
print(f'in-out: {nx.average_neighbor_degree(G, source="in", target= "out")}')
print(f'out-in: {nx.average_neighbor_degree(G, source="out", target= "in")}')
print(f'out-out: {nx.average_neighbor_degree(G, source="out", target= "out")}')

in-in: {0: 3.0, 3: 1.3333333333333333, 1: 3.0, 2: 1.0, 4: 5.0, 5: 0.0, 6: 1.0}
in-out: {0: 2.0, 3: 0.3333333333333333, 1: 2.0, 2: 2.0, 4: 3.0, 5: 0.0, 6: 0.0}
out-in: {0: 3.0, 3: 2.0, 1: 3.0, 2: 1.0, 4: 2.5, 5: 0.0, 6: 2.0}
out-out: {0: 2.0, 3: 0.5, 1: 2.0, 2: 2.0, 4: 1.5, 5: 0.0, 6: 0.0}

看着这张图,我不明白这是如何计算的,也不知道这些结果是从哪里来的。有人可以解释一下吗?

环境: Python 3.8.8 NetworkX 2.5

我认为你 运行 进入这个 issue. The old code contained some weird normalisation (setting to 1 if respective degree is 0). This was changed in 2.6. The latest version, see code here 应该按预期工作。