文章目录
矩阵常见统计
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 themeasure
of the graph. - the number of predations
L
, that in graph theory corresponds to the number of edges m, which is thesize
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} C≃L/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