gpt4 book ai didi

python - 简单的肥尾对数分箱

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:11 25 4
gpt4 key购买 nike

我试图从 Plotting log-binned network degree distributions 中简化日志分级输出显示原始分布和对数分箱分布。然而,后者并没有像预期的那样单调递减,与原来的偏差很大。这个问题的最佳解决方案是什么?

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

m = 3
N = 900

G = nx.barabasi_albert_graph(N, m)

degree_list=nx.degree(G).values()

kmin=min(degree_list)
kmax=max(degree_list)

bins=[float(k-0.5) for k in range(kmin,kmax+2,1)]
density, binedges = np.histogram(degree_list, bins=bins, density=True)
bins = np.delete(bins, -1)

logBins = np.logspace(np.log10(kmin), np.log10(kmax),num=20)
logBinDensity, binedges = np.histogram(degree_list, bins=logBins, density=True)
logBins = np.delete(logBins, -1)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xscale('log')
ax.set_yscale('log')

plt.plot(bins,density,'x',color='black')
plt.plot(logBins,logBinDensity,'x',color='blue')
plt.show()

最佳答案

噪声是由于 N 较小,而小值的偏移是由于 logbin 宽度小于 1。添加

for x in range(len(logBins)):
logBins[x] = mt.ceil(logBins[x])

关于python - 简单的肥尾对数分箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21921185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com