1

I'm trying to fit a multiplex network similar to the example below using a package called "muxviz". Everything is going well, but I don't understand what the line LayerTensor <- diagR(c(1,1), 3, 1) + diagR(c(1,1), 3, -1) does, and how that applies to the network I'm building.

The line builds a matrix which is then used in the function BuildSupraAdjacencyMatrixFromEdgeColoredMatrices, I don't really understand what this does or how to change the LayerTensor so it makes sense in my case. I want to build a simple 2 layer stacked network. I get that all it's doing is building the matrix but what does the matrix do?

I guess in theory I would change the line to LayerTensor <- diagR(c(1,1), 2, 1) + diagR(c(1,1), 2, -1)?

Any help in understanding what this does and how it relates to a simple stacked layer network would be appreciated.

library("muxViz")
library("ggraph")


#Or build by specifying layers
Layers <- 3
Nodes <- 100
NodeTensor <- list()

#Generate an edge-colored network
g <- barabasi.game(Nodes, m=1, directed=F)
g.list <- list()
for(l in 1:Layers){
    g.list[[l]] <- delete_edges(g, sample( E(g), floor(0.2*length(E(g))) ) )
    NodeTensor[[l]] <- get.adjacency( g.list[[l]] )
}

#Let's consider a chain of layers, aka an ordinal network of layers
LayerTensor <- diagR(c(1,1), 3, 1) + diagR(c(1,1), 3, -1)

#Build the multilayer adjacency tensor
M <- BuildSupraAdjacencyMatrixFromEdgeColoredMatrices(NodeTensor, LayerTensor, Layers, Nodes)

#Calculate PageRank and Degree versatility
pr <- GetMultiPageRankCentrality(M, Layers,Nodes)
deg <- GetMultiDegree(M, Layers,Nodes, isDirected=F)


mypal <- brewer.pal(Layers, "Set1")

#Generate the coordinates for layouting our networks.
lay <- layout_with_fr(graph_from_adjacency_matrix( GetAggregateMatrix(NodeTensor, Layers, Nodes) ))

p <- list()

for(l in 1:length(NodeTensor)){
    layout <- create_layout(g.list[[l]], layout = 'drl')
    layout$x <- lay[,1]
    layout$y <- lay[,2]

    V(g.list[[l]])$pr <- pr
    V(g.list[[l]])$deg <- deg

    p[[l]] <- ggraph(layout) + theme_void() +
                geom_edge_link(colour=mypal[l], show.legend = FALSE) + 
                geom_node_point(aes(size = pr, alpha=pr), color=mypal[l]) + 
                theme(legend.position="bottom", plot.title=element_text(size=16, hjust=0.5, face="bold", colour=mypal[l], vjust=-1)) + 
                ggtitle(paste("Layer", l)) +
                guides(size=guide_legend(title="MuxPR"), alpha=F)
}

png("mux_BA_3layers.png", width=1024, height=1024*0.5, res=120)
multiplot(p[[1]], p[[2]], p[[3]], cols=3)
dev.off()


zx8754
  • 52,746
  • 12
  • 114
  • 209
Dasr
  • 777
  • 6
  • 16

0 Answers0