def calculate_betweenness_centality(graph, k=CENTRALITY_SAMPLES):
"""Calculates the betweenness centrality over nodes in the graph. Tries to do it with a certain number of samples,
but then tries a complete approach if it fails.
:param pybel.BELGraph graph: A BEL graph
:param int k: The number of samples to use
:rtype: collections.Counter[tuple,float]
"""
try:
res = Counter(nx.betweenness_centrality(graph, k=k))
return res
except:
return Counter(nx.betweenness_centrality(graph))
评论列表
文章目录