network statistics
print('* ' * 30)
print('network statistics')
print(nx.info(G))
print(nx.is_connected(G))
components = nx.connected_components(G)
print('num of connected_components:', nx.number_connected_components(G))
triadic_closure = nx.transitivity(G)
print("Triadic closure:", triadic_closure)
n = len(G.nodes)
sorted_degree, sorted_eigenvector, sorted_betweenness = nf.nx_statics(G)
1 degree distribution
# https://mp.weixin.qq.com/s/-41OzWUbELGO5zjFD0-TgA
mean_degree = np.sum([i[1] for i in sorted_degree]) / n
x = list(range(max([i[1] for i in sorted_degree]) + 1))
y = [i / n for i in nx.degree_histogram(G)]
plt.plot(x, y, 'ro-')
plt.xlabel("$k$")
plt.ylabel("$p_k$")
plt.show(block=True)
log_x, log_y = log_axis(x, y)
2 diameter_g
diameter_g = nx.diameter(G)
local_efficiency = nx.local_efficiency(G)
global_efficiency = nx.global_efficiency(G)
average_shortest_path_length = nx.average_shortest_path_length(G)
print('diameter: ', diameter_g, '\n',
'local_efficiency: ', local_efficiency, '\n',
'global_efficiency: ', global_efficiency, '\n',
'average_shortest_path_length: ', average_shortest_path_length, )
3 clustering efficient
# clustering = np.mean(list(nx.clustering(G).values()))
average_clustering = nx.average_clustering(G) # 平均集聚系数
transitivity = nx.transitivity(G) # 全局集聚系数, 网络效率
4 度-度相关性
# 基于Pearson相关系数的度-度相关性, Assortativity coefficient(同配系数)
degree_ac = nx.degree_assortativity_coefficient(G)
pearson_r = nx.degree_pearson_correlation_coefficient(G)
sorted_k, k_nn_k = average_nearest_neighbor_degree(G)