def test_gn(self): g = get_string_graph() coms = algorithms.girvan_newman(g, 3) self.assertEqual(type(coms.communities), list) if len(coms.communities) > 0: self.assertEqual(type(coms.communities[0]), list) self.assertEqual(type(coms.communities[0][0]), str)
def girvan_newman(self): template = pd.read_csv("data/communities_template.node", " ", header='infer') saveTo = "Results/Communities/" + self.name + "_girvannewman_communities.node" G = nx.Graph(self.g) result = algorithms.girvan_newman(G, level=3) modularity = result.newman_girvan_modularity().score significance = result.significance().score communities = result.to_node_community_map() n_communities = list(communities.values())[-1][0] + 1 print("\nGirvan Newman: ") print("#Communities: ", n_communities) print("Modularity: ", modularity) print("Significance: ", significance) e = self.get_ordered_communities(communities) template['Girvan-Newman'] = e print("\n") template['Degree'] = [v for v in self.centrality] template['RegionName'] = self.region_names pd.DataFrame.to_csv(template, saveTo, " ", header=False, index=False) return e
def gn(n_coms) : return lambda G : algorithms.girvan_newman(G, n_coms) algos['gn'] = [gn(len(c)) for c in lfr_comms]
cs.erdos_renyi_modularity().score)) print("{0:>15s} | {1:.6f}".format( 'Robustness', cs.normalized_mutual_information(alg(G)).score)) print("{0:>15s} | {1:.1f} sec\n".format('Timing', time() - tic)) return cs # G = read('toy') G = read('karate') # G = read('women') # G = read('dolphins') # G = read('got-appearance') # G = read('diseasome') # G = read('wars') # G = read('transport') # G = read('java') # G = read('imdb') # G = read('wikileaks') info(G) clusters(G, lambda G: algorithms.girvan_newman(G, level=1)) clusters(G, lambda G: algorithms.label_propagation(G)) cs = clusters(G, lambda G: algorithms.louvain(G)) # clusters(G, lambda G: algorithms.leiden(G)) # clusters(G, lambda G: algorithms.sbm_dl(G)) viz.plot_network_clusters(G, cs, nx.spring_layout(G)) plt.show()