utils.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pybel-tools 作者: pybel 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号