Food Webs - 网络中度及集聚系数实现

矩阵常见统计

adjacency_matrix=[
                  [0,1,0,1],
                  [1,0,1,1],
                  [0,1,0,0],
                  [1,1,0,0]
                  ]
adjacency_matrix_directed = [
                  [0,1,0,1],
                  [0,0,1,0],
                  [0,0,0,1],
                  [0,0,0,0]
                  ]

数量统计

  • the number of species S, that in graph theory corresponds to the number of vertices n which is the measure of the graph.
  • the number of predations L, that in graph theory corresponds to the number of edges m, which is the size of the graph.
# 数量统计
num_species = len(adjacency_matrix_directed[0])

num_predations = 0
for i in range(num_species):
    for j in range(num_species):
        if adjacency_matrix_directed[i][j] != 0:
            num_predations = num_predations + 1
print('num_predations: '.format(), num_predations)   
# num_predations:  4  

行列统计

# 行,列统计
row_count = [0,0,0,0]
column_count = [0,0,0,0]
for i in range(num_species):
    for j in range(num_species):
        row_count[i] = row_count[i] + adjacency_matrix_directed[i][j]
        column_count[j] = column_count[j] + adjacency_matrix_directed[i][j]
print('row_count: '.format(), row_count)
print('column_count: '.format(), column_count)
# row_count:  [2, 1, 1, 0]
# column_count:  [0, 1, 1, 2]

基底、顶部、中间

The connectance C ≃ L / S 2 C \simeq L / S^{2} CL/S2 , corresponding to the density of the graph.

number_B = 0
number_T = 0
number_I = 0
for n in range(num_species):
    if row_count[n] == 0:
        number_T += 1
        continue
    elif column_count[n] == 0:
        number_B += 1
        continue
    else:
        number_I += 1
print('classes Basal, Top, Intermediate: ', number_B, number_T, number_I)    
print("connectance", float(num_predations)/float(num_species**2))
# classes Basal, Top, Intermediate:  1 1 2
# connectance 0.25

度-degree

度: k i = ∑ j = 1 , n a i j k_{i}=\sum_{j=1, n} a_{i j} ki=j=1,na

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值