Daniel Alexsandrovich
Daniel Alexsandrovich

Reputation: 25

Create multi-layer (multiplex) network from adjacency matrices

I faced the following problem. I have several adjacency matrices that represent different types of connections for the same set of nodes. Let's say I have 3 types of connections. I am trying to build a multi-layer network and calculate a bunch of centralities for a generalized multi-layer network, not the aggregated one. The problem is that I was trying to find the opportunity to build a multi-layer network from adjacency matrices in different python libraries, but so far, I have not managed to do that. Could you please help me with that?

Adjacency matrix 1:

0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   1   1   0   0
0   0   0   0   1   1   0   0   0   1
0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0

Adjacency matrix 2:

0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   1   0   0   1
0   0   0   1   0   0   1   0   1   0
0   0   0   0   1   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0
0   0   0   0   1   0   0   0   0   0

Adjacency matrix 3:

0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   1   0   0   1   1
0   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   1   1   0   0

I was trying to use pymnet, I have read matrices as pd and then tried:

mnet = MultilayerNetwork(aspects=1)
matrix_1_g = nx.convert_matrix.from_pandas_adjacency(matrix_1)
matrix_2_g = nx.convert_matrix.from_pandas_adjacency(matrix_2)
mnet.add_layer(matrix_1_g)
mnet.add_layer(matrix_2_g)

But it seems it does not generate the multiplex matrix, so I can not draw or analyze it.

Upd: I managed to do it in R thou:

mat_1 <- read.csv("matrix_1.csv", header = F)
mat_1 <- as.matrix(mat_1)
mat_2 <- read.csv("matrix_2.csv", header = F)
mat_2 <- as.matrix(mat_2)
g <- graph.adjacency(t(mat_1), mode="undirected")
g_2 <- graph.adjacency(t(mat_2), mode="undirected")

n <- ml_empty()
V(g)$name <- c(1:203)
V(g2)$name <- c(1:203)
add_igraph_layer_ml(n, g, "layer_1")
add_igraph_layer_ml(n, g2, "layer_2")

However, it seems multinet does not allow me to calculate the generalized eigenvector centrality for multilayer network

Upvotes: 1

Views: 209

Answers (0)

Related Questions