Barabasi-Albert 模型的度分布
Degree distribution of Barabasi-Albert model
我已经能够 运行 运行 这个:
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
,其中 returns 网络中度数的频率列表,其中度值是列表中的相应索引。
通常在绘制度数分布时取 x
和 y
轴的对数,这有助于判断 networkx 是否为 scale-free (a network whose degree distribution follows a power law) which is the case with the Barabási–Albert model, we can use 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')
我已经能够 运行 运行 这个:
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
,其中 returns 网络中度数的频率列表,其中度值是列表中的相应索引。
通常在绘制度数分布时取 x
和 y
轴的对数,这有助于判断 networkx 是否为 scale-free (a network whose degree distribution follows a power law) which is the case with the Barabási–Albert model, we can use 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')