无标度网络-幂律分布
參考鏈接https://ask.csdn.net/questions/365756
今天一直在找關(guān)于冪律分布的驗證相關(guān)資料,很多都是只言片語,這個圖首先解釋了冪律分布的定義
2.然后,https://www.douban.com/group/topic/69712255/ 真正實踐去驗證的時候,先在python環(huán)境下安裝powerlaw包,然后這個鏈接內(nèi)容告訴我們具體怎么應(yīng)用這個包,對每行代碼的解釋真心很詳細(xì)!powerlaw.Fit擬合冪律分布
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib.pylab import plt
import powerlaw
#打開數(shù)據(jù)包------------------------------------------------------------
data=np.loadtxt('C:/Users/peterduus/degree.txt')
#用numpy的loadtxt()方法把文本數(shù)據(jù)讀入二維數(shù)組---------------------------
fit=powerlaw.Fit(data,discrete=True)
print 'xmin =',fit.xmin
print 'alpha =',fit.power_law.alpha
print 'sigma =',fit.power_law.sigma
print 'D =',fit.power_law.D
#擬合冪律,放到名為fit的對象中。網(wǎng)絡(luò)度是離散的,所以要用discrete=True。
#是不是離散型數(shù)據(jù),可以用fit.power_law.discrete來查看。
#計算fit的最小界值。
#計算fit的alpha值。根據(jù)所遵循公式,alpha是冪指數(shù),即P(x)是x的-alpha次方。
也就是我們想要的參數(shù)值了,參考文獻中講到是通過最大似然估計得到的。一般冪律分布的該參數(shù)范圍在2-3是很典型的值。
#sigma是alpha的標(biāo)準(zhǔn)差。
#注意看冪律區(qū)間如果占據(jù)總區(qū)間很小部分,那這種擬合是沒有意義的。
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 vs. ','exponential ',R1,p1
print 'power_law vs. ','lognormal ',R2,p2
print 'power_law vs. ', 'stretched_exponential ',R3,p3
print 'power_law vs. ', 'truncated_power_law ',R4,p4
print '
'
print 'power_law vs. ','exponential ',R12,p12
print 'power_law vs. ', 'truncated_power_law ',R42,p42
print 'exponential vs. ', 'truncated_power_law ',R52,p52
#R是似然比,正值表示前者比后者更契合數(shù)據(jù),
#p是兩模型的差異是否具有顯著性,即用R所做的比較結(jié)果是否有統(tǒng)計學(xué)意義
3.文章中還用到ks檢驗,暫時還沒明白如何用代碼進行檢驗,有待補充!
總結(jié)
以上是生活随笔為你收集整理的无标度网络-幂律分布的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Centos 7】【Docker】 安
- 下一篇: 【maven】mvn -pl 指定模块