【发布时间】:2021-12-19 05:17:34
【问题描述】:
基于从此链接中提取的数据集:Brain and Cosmic Web samples,我正在尝试进行一些复杂网络分析。
论文The Quantitative Comparison Between the Neuronal Network and the Cosmic Web,声称使用了这个数据集,以及它的相邻矩阵
"Mij,即行/列等于检测到的节点数的矩阵,如果节点之间的距离为≤ llink,则值为Mij = 1,或Mij = 0否则”。
然后我对矩阵进行了探索,如下所示:
from astropy.io import fits
with fits.open('mind_dataset/matrix_CEREBELLUM_large.fits') as data:
matrix_cerebellum = pd.DataFrame(data[0].data)
它不打印稀疏矩阵,而是打印与节点之间的距离以像素表示的矩阵。
我了解到1像素和比例的对应关系是:
neuronal_web_pixel = 0.32 # micrometers
并想出了一种方法来将像素转换为微米:
def pixels_to_scale(df, mind=False, cosmos=False):
one_pixel_equals_parsec = cosmic_web_pixel
one_pixel_equals_micron = neuronal_web_pixel
if mind:
df = df/one_pixel_equals_micron
if cosmos:
df = df/one_pixel_equals_parsec
return df
那么,转换后的矩阵二值化的另一种方法:
def binarize_matrix(df, mind=False, cosmos=False):
if mind:
brain_Llink = 16.0 # microns
# distances less than 16 microns
brain_mask = (df<=brain_Llink)
# convert to 1
df = df.where(brain_mask, 1.0)
if cosmos:
cosmos_Llink = 1.2 # 1.2 mpc
brain_mask = (df<=cosmos_Llink)
df = df.where(brain_mask, 1.0)
return df
最后,用:
matrix_cerebellum = pixels_to_scale(matrix_cerebellum, mind=True)
matrix_cerebellum = binarize_matrix(matrix_cerebellum, mind=True)
matrix_cerebellum.head(5) 打印我的(大部分)0.0s 和 1.0s 的稀疏矩阵:
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.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 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
2 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 0.0 0.0 0.0 0.0 0.0
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
4 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 0.0 0.0 0.0 0.0 0.0 0.0
5 rows × 1858 columns
现在我想计算一下:
-
网络的
Degree Centrality,由公式给出:
Cd(j) = Kj / n-1
其中kj 是每个j-node 的(非定向)连接数,n 是整个网络中的节点总数。
-
聚类系数,它量化了节点局部附近的基础设施的存在,由公式给出:
C(j) = 2yi / Kj(Kj -1)
其中yj是j-node的相邻节点之间的链接数。
为了找到度中心性,我尝试过:
# 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
生成:
... K centrality
9.0 -0.995156
6.0 -0.996771
7.0 -0.996771
11.0 -0.996233
11.0 -0.994080
根据论文,我应该发现:
"对于我们测量的小脑切片
每个节点的平均连接数。
我还发现了负中心性。
有谁知道如何根据上面的数据框应用这些公式?
【问题讨论】:
-
您是否考虑联系作者询问他们如何计算
<k>?
标签: python pandas cluster-analysis adjacency-matrix node-centrality