介数就是指经过一个点的最短路径的比例,在计算复杂网络中节点重要性的时候会用到
https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.betweenness_centrality.html?highlight=betweenness_centrality#networkx.algorithms.centrality.betweenness_centrality
Compute the shortest-path betweenness centrality for nodes.
计算节点间最短路径的中心度。
Betweenness centrality of a node v is the sum of the fraction of all-pairs shortest paths that pass through v
节点v的介数中心性是通过v的所有最短路径对的分数之和
networkx.algorithms.centrality.betweenness_centrality
betweenness_centrality(G, k=None, normalized=True, weight=None, endpoints=False, seed=None)
求边介数并按照重要程度递增依次删除节点
def remove_unimportant_byBetweennessCentrality(n):
TempH=nx.Graph()
TempH.add_edges_from(H.edges())
print('G BetweennessCentrality',nx.betweenness_centrality(G),'\nH BetweennessCentrality',nx.betweenness_centrality(H))
listH_betweenness_centrality=list(nx.betweenness_centrality(H))
print('listH_betweenness_centrality=',listH_betweenness_centrality)
H_BetweennessCentrality_list=list(nx.betweenness_centrality(G).items())
print('H_BetweennessCentrality_list', H_BetweennessCentrality_list)
rank=sorted(((b,n) for n,b in H_BetweennessCentrality_list),reverse=False)
print('sequence', rank)
list_node_sequence=[n for (b,n)in rank]
print('list_node_sequence', list_node_sequence)
i=0
while (i<n):
rm_node=list_node_sequence[i]
if rm_node not in TempH.nodes:
i=i+1
continue
neighbor=list(TempH.neighbors(rm_node))
TempH.remove_node(rm_node)
print('removed node is', rm_node)
print('removed node’s neighbors are', neighbor)
if len(neighbor)>1:
node_0 = neighbor[0]
for j in neighbor[1:len(neighbor)]:
TempH.add_edges_from([(node_0, j)])
i = i + 1
return TempH