我已经能够运行这个:
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')
关于python - Barabasi-Albert模型的度分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62644665/