Esempio n. 1
0
    def run(self, data, seed=None):
        if (data.is_directed()) and False:
            raise Exception("only undirected is supported")
        if seed is not None:self.logger.info("seed ignored")        
        g = convert.to_igraph(data)
        timecost, ret = utils.timeit(lambda: g.community_infomap(edge_weights='weight' if data.is_weighted() else None))
        vc = ret
        clusters = {}
        for i, a in enumerate(vc):
            clusters[i] = a
            
        modularity = vc.modularity
        self.logger.info("Made %d clusters in %f seconds. modularity=%f " % (len(clusters), timecost, modularity))
        
        result = {}
        result['timecost'] = timecost
        result['modularity'] = modularity        
        result['runname'] = self.name
        result['dataname'] = data.name
        result['meta'] = self.get_meta()
        result['clusters'] = clusters 

        save_result(result)
        self.result = result 
        return self 
Esempio n. 2
0
 def testClustersProperties(self):
     g = self.graph_unweighted_undirect
     assert not g.is_weighted()
     p = GraphClusterMetrics(g, list(g.get_ground_truth().values())[0])
     self.assertEqual(p.num_edges * 2, p.sum_weight)
     self.assertEqual(np.sum(list(p.cluster_out_sum_weights.values())) + np.sum(list(p.cluster_sum_intra_weights.values())), p.sum_weight)
     print ('num_edges', p.num_edges)
     print ('num_vertices', p.num_vertices)
     print ('num_clusters', p.num_clusters)
     print ('cluster_sizes', p.cluster_sizes)
     print ('cluster_indexes', p.cluster_indexes)
     print ('cluster_edge_sizes', p.cluster_edge_sizes)
     print ('cluster_sum_intra_weights', p.cluster_sum_intra_weights)
     print ('unweighted_intra_cluster_densities', p.unweighted_intra_cluster_densities)
     print ('cluster_sum_weighted_degrees', p.cluster_sum_weighted_degrees)
     
     print ('intra_cluster_densities', p.intra_cluster_densities)
     print ('intra_cluster_density', p.intra_cluster_density)
     print ('inter_cluster_density', p.inter_cluster_density)
     print ('relative_cluster_densities', p.relative_cluster_densities)
     print ("modularity2", p.modularity2)
     print ("snap_modularities", p.snap_modularities())
     
     print ("cluster_expansions", p.cluster_expansions)
     print ("cluster_cut_ratios", p.cluster_cut_ratios)
     
     print ("conductance", p.conductance)  
     print ("normalized_cut", p.normalized_cut)
           
     print ("cluster_max_out_degree_fraction", p.cluster_max_out_degree_fraction)
     print ("cluster_avg_out_degree_fraction", p.cluster_avg_out_degree_fraction)
     print ("cluster_flake_out_degree_fraction", p.cluster_flake_out_degree_fraction)
     print ("separability", p.separability)
     
     print ("cluster_clustering_coefficient", p.cluster_clustering_coefficient)
     print ("cluster_local_clustering_coefficient", p.cluster_local_clustering_coefficient) 
     
     print ("AAA", convert.to_igraph(self.graph_unweighted_undirect).transitivity_local_undirected())       
     print ("AAA", convert.to_igraph(self.graph_unweighted_undirect).transitivity_undirected())       
 def to_graph_igraph(self):
     from gct.dataset import convert
     return convert.to_igraph(self)
 def testToIGraph(self):
     for data in self.graphs:
         g = convert.to_igraph(data)
         print (data.is_weighted(), g.is_weighted(), data.is_directed(), g.is_directed())