【发布时间】:2016-03-25 21:27:10
【问题描述】:
我通过以下方式计算佛罗伦萨家庭图的中介中心性:
import networkx as nx
# build up a graph
G = nx.florentine_families_graph()
bw_centrality = nx.betweenness_centrality(G, normalized=False)
摘自networkx中betweenness_centrality(...)的描述,
节点v的中心性是通过v的所有对最短路径的分数之和:
因此,中介中心性应该小于1。但是,我得到了结果:(红色节点'Medici'的中介中心性是47.5)
我计算介数中心性的方法如下,
node_and_times = dict.fromkeys(G.nodes(), 0) # a dict of node : the number of shortest path passing through node
sum_paths = 0
for s, t in itertools.product(G.nodes(), repeat=2): # all pair of nodes <s, t>
paths = nx.all_shortest_paths(G, s, t) # generator of lists
for path in paths:
sum_paths += 1
# stats nodes passing through shortest path
for node in path[1:-1]: # intermediate nodes
node_and_times[node] += 1
bw_centrality = {k : v*1.0/sum_paths for k, v in node_and_times.items()}
我得到了以下结果,
我说的对吗?
正如回答者所说,删除normalized=False得到以下结果,这与我的计算不一致。
【问题讨论】:
-
'正如回答者所说,删除 normalized=False 得到以下结果,这与我的计算不一致。' - 那是因为你的计算是错误的,你没有计算中介中心性。
-
@TonyBabarino 你是对的。我误解了中介中心性的定义为
the number of shortest paths passing through v与the total number of shortest paths的比率。 -
是的,没错。我试图在我的答案中解释如何计算它,我希望你能理解我的解释。干杯!