这个介数计算正确吗? [英] is this betweenness calculation correct?

查看:69
本文介绍了这个介数计算正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试计算这个简单图中从 2 到 6 路径的所有节点的介数.

I try to calculate betweenness for all nodes for the path from 2 to 6 in this simple graph.

G=nx.Graph()
edge=[(1,5),(2,5),(3,5),(4,5),(4,6),(5,7),(7,6)]
G.add_edges_from(edge)
btw=nx.betweenness_centrality_subset(G,[2],[6])

然而结果是:

{1: 0.0, 5: 0.5, 2: 0.0, 3: 0.0, 4: 0.25, 6: 0.0, 7: 0.25}

我想知道为什么节点 5 的介数是 0.5 而它应该是 1,因为总最短路径的数量是 2 并且它们都包括 5,节点 4 和节点 7 应该是 0.5

I was wondering why the betweenness for node 5 is 0.5 while it should be 1 since the number of total shortest path is 2 and both of them include 5 and node 4 and 7 should be 0.5

推荐答案

它看起来像一个错误.

这是我的猜测.该错误似乎来自 > 功能.这里,如果图是间接的,则计算值乘以 0.5.

Here my guess. The bug seems coming from the _rescale function. Here, if the graph is indirected the computed values are multiplied by 0.5.

由于在一般 betweenness_centrality 中,节点被考虑两次(计算最短路径 对于图中的每个节点)对于betweenness_centrality_sub 这不是必需的,因为仅计算最短路径用于节点>.

Since in the general betweenness_centrality a node is considered twice (shortest paths are computed for each node in the graph) for the betweenness_centrality_sub this is not necessary since shortest paths are only computed for the sources nodes.

示例:

nx.betweenness_centrality_subset(G,[2,6],[2,6])
# {1: 0.0, 5: 1.0, 2: 0.0, 3: 0.0, 4: 0.5, 6: 0.0, 7: 0.5}

所以,如果我猜对了,你只需要将计算结果乘以 2.

So, if my guess is right, you just need to multiply by 2 the computed result.

这篇关于这个介数计算正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆