'Networkx - create a multilayer network from two adjacent matrices
I have two adjacent matrices that represent two brain structures (cerebellum and cortex):
Dataset:
import networkx as nx
from astropy.io import fits
# Cerebellum
with fits.open('matrix_CEREBELLUM_large.fits') as data:
matrix_cerebellum = pd.DataFrame(data[0].data.byteswap().newbyteorder())
# 1858 rows × 1858 columns
# Cortex
with fits.open('matrix_CORTEX_large.fits') as data:
matrix_cortex = pd.DataFrame(data[0].data.byteswap().newbyteorder())
#1464 rows × 1464 columns
Note: datasets can be downloaded here: brain datasets
Adjacent matrices
Adjacent matrices here are not weighted, and have the usual binary representation, with 1 value for connected nodes and 0 otherwise, like so:
0 1 0 1 0 0 0 0 0 0 0 ...
0 0 0 1 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 1 ...
I'm using the library Networkx
to look for community detection in the networks. I could try to do that for each network, individually.
Simulation
Let's say I need to simulate the real world networks, where a fraction of cortex nodes ( say, 0.01%) projects edges into cerebellum.
I'm wondering how I could implement this simulation considering my community detection goal.
Approaches
I initially though about creating a bipartite network, but decided instead to use a multilayer network (2 layers, actually) approach.
In this approach, cortex would be network layer 1, cerebellum would be network layer 2, each one with intra-connections already represented in each adjacent matrix.
Now I would add the cortex projections as inter-connections between the two layers.
Question
How do I create these projections and represent the new matrix, knowing that I need to:
- start from my adjacent matrices
- keep their intra-connectivity mappings
- add a new mapping for the intermediate layer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|