title: Stacked multi-layer network R, how to define tensor?
body: <p>I'm trying to fit a multiplex network similar to the example below using a package called &quot;muxviz&quot;. Everything is going well, but I don't understand what the line <code>LayerTensor &lt;- diagR(c(1,1), 3, 1) + diagR(c(1,1), 3, -1)</code> does, and how that applies to the network I'm building.</p>
  <p>The line builds a matrix which is then used in the function <code>BuildSupraAdjacencyMatrixFromEdgeColoredMatrices</code>, I don't really understand what this does or how to change the <code>LayerTensor</code> 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?</p>
  <p>I guess in theory I would change the line to <code>LayerTensor &lt;- diagR(c(1,1), 2, 1) + diagR(c(1,1), 2, -1)</code>?</p>
  <p>Any help in understanding what this does and how it relates to a simple stacked layer network would be appreciated.</p>
  <pre><code>library(&quot;muxViz&quot;)
  library(&quot;ggraph&quot;)
  
  
  #Or build by specifying layers
  Layers &lt;- 3
  Nodes &lt;- 100
  NodeTensor &lt;- list()
  
  #Generate an edge-colored network
  g &lt;- barabasi.game(Nodes, m=1, directed=F)
  g.list &lt;- list()
  for(l in 1:Layers){
      g.list[[l]] &lt;- delete_edges(g, sample( E(g), floor(0.2*length(E(g))) ) )
      NodeTensor[[l]] &lt;- get.adjacency( g.list[[l]] )
  }
  
  #Let's consider a chain of layers, aka an ordinal network of layers
  LayerTensor &lt;- diagR(c(1,1), 3, 1) + diagR(c(1,1), 3, -1)
  
  #Build the multilayer adjacency tensor
  M &lt;- BuildSupraAdjacencyMatrixFromEdgeColoredMatrices(NodeTensor, LayerTensor, Layers, Nodes)
  
  #Calculate PageRank and Degree versatility
  pr &lt;- GetMultiPageRankCentrality(M, Layers,Nodes)
  deg &lt;- GetMultiDegree(M, Layers,Nodes, isDirected=F)
  
  
  mypal &lt;- brewer.pal(Layers, &quot;Set1&quot;)
  
  #Generate the coordinates for layouting our networks.
  lay &lt;- layout_with_fr(graph_from_adjacency_matrix( GetAggregateMatrix(NodeTensor, Layers, Nodes) ))
  
  p &lt;- list()
  
  for(l in 1:length(NodeTensor)){
      layout &lt;- create_layout(g.list[[l]], layout = 'drl')
      layout$x &lt;- lay[,1]
      layout$y &lt;- lay[,2]
  
      V(g.list[[l]])$pr &lt;- pr
      V(g.list[[l]])$deg &lt;- deg
  
      p[[l]] &lt;- 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=&quot;bottom&quot;, plot.title=element_text(size=16, hjust=0.5, face=&quot;bold&quot;, colour=mypal[l], vjust=-1)) + 
                  ggtitle(paste(&quot;Layer&quot;, l)) +
                  guides(size=guide_legend(title=&quot;MuxPR&quot;), alpha=F)
  }
  
  png(&quot;mux_BA_3layers.png&quot;, width=1024, height=1024*0.5, res=120)
  multiplot(p[[1]], p[[2]], p[[3]], cols=3)
  dev.off()
  
  
  </code></pre>