def test_nx2igraph_with_labels(nx_graph): ig_graph = pyintergraph.nx2igraph(nx_graph) nodemap = {v.index: v["name"] for v in ig_graph.vs()} assert list(nx_graph.nodes()) == [v["name"] for v in ig_graph.vs()] assert [e for e in nx_graph.edges()] == \ [(nodemap[e.tuple[0]], nodemap[e.tuple[1]]) for e in ig_graph.es()]
def test_round_robin_ig(ig_graph): graph_tool_graph = pyintergraph.igraph2gt(ig_graph, labelname="somelabelname") nx_graph = pyintergraph.gt2nx(graph_tool_graph, labelname="somelabelname") reversed_ig_graph = pyintergraph.nx2igraph(nx_graph) assert list(v.index for v in ig_graph.vs()) == list( v.index for v in reversed_ig_graph.vs()) assert list(e.tuple for e in ig_graph.es()) == list( e.tuple for e in reversed_ig_graph.es()) assert ig_graph.edge_attributes() == reversed_ig_graph.edge_attributes() assert set(ig_graph.vertex_attributes()).add("name") == set( reversed_ig_graph.vertex_attributes()).add("name") assert type(ig_graph) == type(reversed_ig_graph)
edge_labels = {} count = 0 for i, origin_state in enumerate(new_data): for j, destination_state in enumerate(origin_state): rate = new_data[i][j] if rate > 0: count = count + 1 try: G.add_edge(indices[i], indices[j], weight=rate) except: pdb.set_trace() print('ol') matrix = nx.to_scipy_sparse_matrix(G) for inflation in [i / 10 for i in range(15, 26)]: result = mc.run_mcl(matrix, inflation=inflation) clusters = mc.get_clusters(result) Q = mc.modularity(matrix=result, clusters=clusters) print("inflation:", inflation, "modularity:", Q) #communities_generator = community.girvan_newman(G) #top_level_communities = next(communities_generator) result = mc.run_mcl(matrix) # run MCL with default parameters clusters = mc.get_clusters(result) pdb.set_trace() GG = pyintergraph.nx2igraph(G, labelname="node_label") clusters = nx.clustering(G, weight='weight')
def communities(self, graph): return self.grouping( leiden.find_partition(pyintergraph.nx2igraph(graph), leiden.ModularityVertexPartition))
def test_nx2igraph_raises(wrong_input): with pytest.raises(TypeError): g = pyintergraph.nx2igraph(wrong_input)