CommunityDetection.py 文件源码

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

项目:visa_free 作者: BBischof 项目源码 文件源码
def communities(self, nCommunities, weight=None):
        """
        Compute communities.

        Parameters
        ----------
        nCommunities - number of communities to be returned.
            This is added to simplify the process, the original GN algorithm doesn't 
            need predecided number of communities. 
            Other measures like a threshold on betweenness centrality can be used instead.

        weight (string) - If None, all edge weights are considered equal. 
            Otherwise holds the name of the edge attribute used as weight. 


        Returns
        --------
        A list of communities where each community is a list of the nodes in the community.  
        """
        gr = self.g
        n = nx.number_connected_components(gr)
        components = nx.connected_components(gr)

        while (n < nCommunities):
            gr = self.communitySplits(gr, weight=weight)
            components = nx.connected_components(gr)
            n = nx.number_connected_components(gr)
            if gr.number_of_edges() == 0:
                break
        return components
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号