阿尔伯特模型的度分布

2024-04-28 22:30:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经能够运行此运行:

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模型的分布度,或者更确切地说,幂律分布度


Tags: importnumpynetworkxmatplotlibasnppltgraph
1条回答
网友
1楼 · 发布于 2024-04-28 22:30:25

我们可以使用^{},它返回网络中度的频率列表,其中度值是列表中相应的索引

通常,在绘制度分布时,取xy轴的对数,这有助于确定如果网络x是scale-free(度分布遵循幂律的网络),这是Barabási–Albert model的情况,我们可以使用^{}

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

相关问题 更多 >