2021-11-19 16:29:15 +08:00
|
|
|
|
# -*- coding: UTF-8 -*-
|
2021-11-18 17:43:34 +08:00
|
|
|
|
import networkx as nx
|
|
|
|
|
import pdb
|
|
|
|
|
def betweeness(g):
|
|
|
|
|
#pdb.set_trace()
|
|
|
|
|
betweenness = nx.betweenness_centrality(g)
|
2021-11-19 16:29:15 +08:00
|
|
|
|
#print betweenness
|
|
|
|
|
return betweenness #list
|
2021-11-18 17:43:34 +08:00
|
|
|
|
|
|
|
|
|
def eigenvector(g):
|
|
|
|
|
centrality = nx.eigenvector_centrality(g)
|
|
|
|
|
return centrality
|
|
|
|
|
|
|
|
|
|
def closeness_centrality(g):
|
|
|
|
|
closeness = nx.closeness_centrality(g)
|
|
|
|
|
return closeness
|
|
|
|
|
|
2021-11-19 16:29:15 +08:00
|
|
|
|
def retrieveGP(g): #list,转化为float。将基本块级别的betweeness转化为函数级别的betweeness
|
2021-11-18 17:43:34 +08:00
|
|
|
|
bf = betweeness(g)
|
|
|
|
|
#close = closeness_centrality(g)
|
|
|
|
|
#bf_sim =
|
|
|
|
|
#close_sim =
|
|
|
|
|
x = sorted(bf.values())
|
|
|
|
|
value = sum(x)/len(x)
|
|
|
|
|
return round(value,5)
|
|
|
|
|
|