參考鏈接https://ask.csdn.net/questions/365756
今天一直在找關於冪律分布的驗證相關資料,很多都是只言片語,這個圖首先解釋了冪律分布的定義
2.然后,https://www.douban.com/group/topic/69712255/ 真正實踐去驗證的時候,先在python環境下安裝powerlaw包,然后這個鏈接內容告訴我們具體怎么應用這個包,對每行代碼的解釋真心很詳細!powerlaw.Fit擬合冪律分布
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib.pylab import plt
import powerlaw
#打開數據包------------------------------------------------------------
data=np.loadtxt('C:/Users/peterduus/degree.txt')
#用numpy的loadtxt()方法把文本數據讀入二維數組---------------------------
fit=powerlaw.Fit(data,discrete=True)
print 'xmin\t=',fit.xmin
print 'alpha\t=',fit.power_law.alpha
print 'sigma\t=',fit.power_law.sigma
print 'D\t=',fit.power_law.D
#擬合冪律,放到名為fit的對象中。網絡度是離散的,所以要用discrete=True。
#是不是離散型數據,可以用fit.power_law.discrete來查看。
#計算fit的最小界值。
#計算fit的alpha值。根據所遵循公式,alpha是冪指數,即P(x)是x的-alpha次方。 也就是我們想要的參數值了,參考文獻中講到是通過最大似然估計得到的。一般冪律分布的該參數范圍在2-3是很典型的值。
#sigma是alpha的標准差。
#注意看冪律區間如果占據總區間很小部分,那這種擬合是沒有意義的。
R1,p1=fit.distribution_compare('power_law','exponential')
R2,p2=fit.distribution_compare('power_law','lognormal')
R3,p3=fit.distribution_compare('power_law', 'stretched_exponential')
R4,p4=fit.distribution_compare('power_law', 'truncated_power_law')
R12,p12=fit2.distribution_compare('power_law','exponential')
R22,p22=fit2.distribution_compare('power_law','lognormal')
R32,p32=fit2.distribution_compare('power_law', 'stretched_exponential')
R42,p42=fit2.distribution_compare('power_law', 'truncated_power_law')
R52,p52=fit2.distribution_compare('exponential', 'truncated_power_law')
print 'power_law\tvs.\t','exponential\t',R1,p1
print 'power_law\tvs.\t','lognormal\t',R2,p2
print 'power_law\tvs.\t', 'stretched_exponential\t',R3,p3
print 'power_law\tvs.\t', 'truncated_power_law\t',R4,p4
print '\n'
print 'power_law\tvs.\t','exponential\t',R12,p12
print 'power_law\tvs.\t', 'truncated_power_law\t',R42,p42
print 'exponential\tvs.\t', 'truncated_power_law\t',R52,p52
#R是似然比,正值表示前者比后者更契合數據,
#p是兩模型的差異是否具有顯著性,即用R所做的比較結果是否有統計學意義
3.文章中還用到ks檢驗,暫時還沒明白如何用代碼進行檢驗,有待補充!