def graph_worker_oneshot(inputlist, queue, print_queue): for duty in inputlist: name = duty[0] G = duty[1] algo = duty[2] param = duty[3] A = nx.to_numpy_matrix(G) x, l = eg.eigen_centrality(A) eg.info("Setup completed") start_time = time.time() if algo == "spectre": m = float(param) n = nm.shape(A)[0] B = eg.sample_simm_matrix2(A, int(round(n * m))) H = None algo += str(m) elif algo == "traj": H = traj.random_graph(G) elif algo == "sah": dists = param.split(",") H = sah.random_graph(G, dists[0], dists[1]) elif algo == "modularity": m = float(param) n = nm.shape(A)[0] B = eg.modularity_clone_matrix(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) while nx.is_isomorphic(G, H): B = eg.modularity_clone_matrix(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) algo += str(m) elif algo == "25k": H = twok.gen_25k_graph(G) elif algo == "sbm": H = sbm.generate(G) eg.info("Graph Generated") gc.collect() stat = get_statistics1(G, H, time.time() - start_time, fraction=0.1) s = algo + "," + name + "," + str(len(G.nodes())) for el in stat: s += "," + str(el) print_queue.put(s) print_queue.put("\n") gc.collect()
def graph_worker_oneshot(inputlist, queue, print_queue): for duty in inputlist: name = duty[0] G = duty[1] algo = duty[2] param = duty[3] names = G.nodes() names.sort(key=int) A = nx.to_numpy_matrix(G, nodelist=names) eg.info("Setup completed") start_time = time.time() if algo == "modularity": m = float(param) n = nm.shape(A)[0] B = eg.modularity_clone_matrix(A, int(round(n*m))) H = gu.simm_matrix_2_graph(B, names) while nx.is_isomorphic(G, H): B = eg.modularity_clone_matrix(A, int(round(n*m))) H = gu.simm_matrix_2_graph(B, names) algo += str(m) elif algo == "traj": H = traj.random_graph(G) trnames = H.nodes() mapping = {trnames[i]: names[i] for i in range(len(names))} H = nx.relabel_nodes(H, mapping) elif algo == "25k": H = twok.gen_25k_graph(G, names) elif algo == "sbm": H = sbm.generate(G, names) eg.info("Graph Generated " + name) gc.collect() stat = get_statistics(G, H, time.time()-start_time, fraction=0.1) s = name + "," + str(len(G.nodes())) + "," + algo for el in stat: s += "," + str(el) print_queue.put(s) print_queue.put("\n") gc.collect()
def modgraph(G, level): A = nx.to_numpy_matrix(G) n = nm.shape(A)[0] B = eg.modularity_clone_matrix(A, level) H = gu.simm_matrix_2_graph(B) # while nx.is_isomorphic(G, H): # B = eg.modularity_clone_matrix(A, level) # H = gu.simm_matrix_2_graph(B) return H
def graph_worker_oneshot(inputlist, queue, print_queue): for duty in inputlist: name = duty[0] G = duty[1] algo = duty[2] param = duty[3] A = nx.to_numpy_matrix(G) # x, l = eg.eigen_centrality(A) eg.info("Setup completed") start_time = time.time() if algo == "1k": H = nx.random_degree_sequence_graph((nx.degree(G).values())) # B = nx.to_numpy_matrix(H) elif algo == "2k": joint_degrees = nx.algorithms.mixing.degree_mixing_dict(G) H = joint_degree_graph(joint_degrees) # B = nx.to_numpy_matrix(H) elif algo == "eig": precision = float(param) # B = eg.build_matrix(x, l, precision) B = eg.generate_matrix(x, l * x, precision, gu.get_degrees(A)) H = None algo += str(precision) elif algo == "modeig": precision = float(param) B = eg.synthetic_modularity_matrix(A, precision) H = None algo += str(precision) elif algo == "spectre": m = float(param) n = nm.shape(A)[0] B = eg.sample_simm_matrix2(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) while nx.is_isomorphic(G, H): B = eg.sample_simm_matrix2(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) algo += str(m) elif algo == "laplacian": m = float(param) n = nm.shape(A)[0] B = eg.laplacian_clone_matrix(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) while nx.is_isomorphic(G, H): B = eg.sample_simm_matrix2(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) algo += str(m) elif algo == "modspec": m = float(param) n = nm.shape(A)[0] B = eg.modspec_clone_matrix(A, int(round(n * m))) H = None algo += str(m) elif algo == "franky": m = float(param) n = nm.shape(A)[0] B = eg.franky_clone_matrix(A, int(round(n * m))) H = None algo += str(m) elif algo == "modularity": m = float(param) n = nm.shape(A)[0] B = eg.modularity_clone_matrix(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) while nx.is_isomorphic(G, H): B = eg.modularity_clone_matrix(A, int(round(n * m))) H = gu.simm_matrix_2_graph(B) algo += str(m) elif algo == "25k": test25 = Estimation() gen25 = Generation() test25.load_graph("", graph=G) test25.calcfull_CCK() test25.calcfull_JDD() gen25.set_JDD(test25.get_JDD('full')) gen25.set_KTRI(test25.get_KTRI('full')) gen25.construct_triangles_2K() gen25.mcmc_improved_2_5_K(error_threshold=0.05) H = gen25.G # B = nx.to_numpy_matrix(H) eg.info("Graph Generated") stat = get_statistics1(G, H, time.time() - start_time) s = algo + "," + name + "," + str(len(G.nodes())) for el in stat: s += "," + str(el) print_queue.put(s) print_queue.put("\n") gc.collect()
def test_modularity_clone_matrix(): G = nx.read_weighted_edgelist("toy.edges") A = nx.to_numpy_matrix(G) B = modularity_clone_matrix(A, 6) assert(nm.array_equal(A, B))
count = 0 m_bg_result = [] c_a_bg_result = [] partiton_ratio = [] d_pcc = [] for i in range(10): count += 1 if count <= 10: #G = nx.read_weighted_edgelist("D:/software/python/spectral_graph_forge-master/spectral_graph_forge-master/toy.edges") #G = nx.read_weighted_edgelist("C:/Users/Administrator/Desktop/lee/ego-Facebook/facebook/3980.edges") #G = nx.read_weighted_edgelist("C:/Users/Administrator/Desktop/lee/ego-Facebook/facebook/348.edges") G = nx.karate_club_graph() #G=nx.generators.davis_southern_women_graph() #G = nx.generators.florentine_families_graph() A = nx.to_numpy_matrix(G) B_matrix = modularity_clone_matrix(A, 6) #B_matrix =entropy_analysis.truncated_mod_approx(A, 6) #B_1=entropy_analysis.sample_mod_matrix(B_matrix) B = simm_matrix_2_graph(B_matrix, None) print("***************%dth running result***************" % (i + 1)) print "***************now is the modularity of the original Graph B" m_b = kl_modularity.maximum_modularity(B)[0] print "***************now is the modularity of the original Graph G" m_g = kl_modularity.maximum_modularity(G)[0] print "***************this is the modularity ratio of the original Graph G and new graph B" print float(m_b / m_g) m_bg_result.append(float(m_b / m_g)) print "##########now is the clustering########## " c_g = graph_utils.clustering(A) c_b = graph_utils.clustering(B_matrix)