Monday, 8 November 2021

Find Degree centrality in a matrix

Based on a dataset extracted from this link: Brain and Cosmic Web samples, I'm trying to do some Complex Network analysis.


The paper The Quantitative Comparison Between the Neuronal Network and the Cosmic Web, claims to have used this dataset, as well as its adjacent matrixes

"Mij, i.e., a matrix with rows/columns equal to the number of detected nodes, with value Mij = 1 if the nodes are separated by a distance ≤ llink , or Mij = 0 otherwise".

I then probed into the matrix, like so:

from astropy.io import fits

with fits.open('mind_dataset/matrix_CEREBELLUM_large.fits') as data:
    matrix_cerebellum = pd.DataFrame(data[0].data)

matrix_cerebellum.head(5) prints

0   1   2   3   4   5   6   7   8   9   ... 1848    1849    1850    1851    1852    1853    1854    1855    1856    1857
0   0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.00000 ... 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 0.00000 0.0 0.0 0.0 0.00000 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2   0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 30.88689    ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3   0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 0.0 0.00000 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4   0.0 0.0 0.0 0.0 0.0 42.43819    0.0 0.0 0.0 0.00000 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
5 rows × 1858 columns

with 1858 nodes, and distances from each other.

However, I find no 1.0 values bellow the threshold for link value, but rather values other than 0.0 much higher than 1.0, which maybe represent the actual distance value, but I'm not sure.


Using the library networkx, I can see the network with:

G_cerebellum = nx.DiGraph(matrix_cerebellum.values)
# figure
plt.figure(1,figsize=(12,12)) 
nx.draw(G_cerebellum,node_size=10,font_size=8)
plt.show()

enter image description here


Now I would like to calculate:

  1. Degree Centrality of the network, given by the formula:

    Cd(j) = Kj / n-1

Where kj is the number of (undirected) connections to/from each j-node and n is the total number of nodes in the entire network.

  1. Clustering Coefficient, which quantifies the existence of infrastructure within the local vicinity of nodes, given by the formula:

    C(j) = 2yi / Kj(Kj -1)

in which yj is the number of links between neighbooring nodes of the j-node.


For finding Degree Centrality, I have tried:

# find connections by adding matrix row values
matrix_cerebellum['K'] = matrix_cerebellum.sum(axis=1)
# applying formula
matrix_cerebellum['centrality'] = matrix_cerebellum['K']/matrix_cerebellum.shape[0]-1

But this is not working.

According to the paper, I should be finding:

"For the cerebellum slices we measured 〈k〉 ∼ 1.9 − 3.7",

but i'm finding negative centralities.


Does anyone know how to apply any of these formulas based on the dataframe above?



from Find Degree centrality in a matrix

No comments:

Post a Comment