python - Barabasi-Albert模型的度分布

标签 python ubuntu networkx

我已经能够运行这个:

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

n = 20
m = 3

G_barabasi = nx.barabasi_albert_graph(n,m)
plt.figure(figsize=(12,8))
nx.draw(G_barabasi, node_size=4)
plt.show()
上面的代码能够绘制节点和边。
但是,我需要获得 Barabasi-Albert 模型的分布度,或者更确切地说是幂律度分布。

最佳答案

我们可以使用 nx.degree_histogram ,它返回网络中度数的频率列表,其中度值是列表中的相应索引。
通常是 x 的对数和 y绘制度数分布时采用轴,这有助于查看网络 x 是否为 scale-free (度分布遵循幂律的网络)Barabási–Albert model 就是这种情况。 , 我们可以使用 plt.loglog 为了那个原因:

import networkx as nx
import matplotlib.pyplot as plt

n = 2000
m = 3
G_barabasi = nx.barabasi_albert_graph(n,m)

degree_freq = nx.degree_histogram(G_barabasi)
degrees = range(len(degree_freq))
plt.figure(figsize=(12, 8)) 
plt.loglog(degrees[m:], degree_freq[m:],'go-') 
plt.xlabel('Degree')
plt.ylabel('Frequency')
enter image description here

关于python - Barabasi-Albert模型的度分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62644665/

相关文章:

python - Pandas read_csv 仅第一个逗号

ubuntu - 在 Debian/Ubuntu 上运行 Jetty 7 作为服务……

ubuntu - 在 Ubuntu 12.04 LTS 上创建 debian 包

python - 使用networkx的最短路径的边属性

python - Networkx - 如何从 "all_pairs_shortest_path_length"函数中获取值(value)?

python - networkx:如何设置自定义成本函数?

python - 将元组分组到列表中

python - 按高度/方向对图像进行排序

ubuntu - 无法访问 Oracle 云实例上的开放端口

python - 如何使用while循环遍历字典中的项目?