sna_clustering.py 文件源码

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

项目:ocean 作者: worldoss 项目源码 文件源码
def centrality(self):

        with open('community_test.csv','rU') as csvfile:
            reader = csv.reader(csvfile)
            for row in reader:
                cluster = row[1:]
                edges = []
                print cluster
                for i in self.edges:
                    for j in cluster:
                        if i[0] == j:
                            for k in cluster:
                                if i[1] == k:
                                    edges.append(i)
                        if i[1] == j:
                            for k in cluster:
                                if i[0] == k:
                                    edges.append(i)

                C = nx.Graph()
                C.add_nodes_from(cluster)
                C.add_edges_from(edges)

                node_count=nx.number_of_nodes(C)
                edge_count=nx.number_of_edges(C)

                print node_count, edge_count

                cent = self.degree_centrality_custom(C)

                print cent

                with open('centrality_test.csv','a') as csvfile:
                    writer = csv.writer(csvfile)
                    writer.writerow(['Community '+row[0],'Node: '+str(node_count),'Edge: '+str(edge_count)])
                    for i,j in cent.items():
                        writer.writerow([i,j])
                print 'Finished Community '+row[0]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号