r - plot bipartite graph created with Networkx using igraph -
i have trouble reading bipartite matrix in igraph. created bipartite graphs using networkx , exported them biadjacency matrix:
bipartite.biadjacency_matrix(graph[i],row_order=bipartite.sets(stockgraph[i])[0], column_order=bipartite.sets(stockgraph[i])[1],format='csr')
then import 10x10 matrix in r using igraph :
data <-readmat("graphtomatlab1.mat") data1 <- data$graphtomatlab[[1]][[1]] graph <- graph_from_adjacency_matrix(data1, mode="undirected")
here sparse matrix:
data1 10 x 10 sparse matrix of class "dgcmatrix"
[1,] 1 . . . . . . . . . [2,] . . . . 1 . . . . . [3,] . . 1 . . 1 . . . . [4,] . . . . 1 . 1 1 . . [5,] . . . . . . . . . 1 [6,] . . 1 1 . . 1 . 1 . [7,] . . 1 1 1 2 . . . . [8,] . . 1 . . 1 . . . . [9,] . . 1 1 . . . 1 . . [10,] . 2 . . . . . . . .
graph
igraph u--- 10 21 -- + edges: [1] 1-- 1 2-- 5 2--10 2--10 3-- 3 3-- 6 3-- 7 3-- 8 3-- 9 4-- 5 4-- 6 4-- 7 4-- 8 4-- 9 5-- 7 5--10 6-- 7 6-- 7 6-- 8 6-- 9 [21] 8-- 9
so wrong because not take account there 2 types of vertices (missing attributes section). think because of way exported graph (using bipartite.biadjacency matrix), there way bypass problem? either in way igraph reads matrices or how export in networkx ?
you want adjacency matrix representation of bipartite graph
in [1]: import networkx nx in [2]: g = nx.complete_bipartite_graph(5,3) in [3]: nx.adjacency_matrix(g,nodelist=range(8)).todense() out[3]: matrix([[0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 0]], dtype=int64)
the biadjacency format has 1 section of adjacency matrix
in [4]: networkx.algorithms.bipartite import biadjacency_matrix in [5]: biadjacency_matrix(g,range(5)).todense() out[5]: matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=int64)
Comments
Post a Comment