PKisEDaLOOplfit-latest/searchindex.jsSearch.setIndex({envversion:42,terms:{all:1,code:[0,1],"149g":0,skip:1,abil:0,edu:[0,1],follow:0,hierarch:0,cython:[0,1],lognorm:1,depend:1,aaron:[0,1],matlab:[0,1],slowest:1,sourc:[0,1],fals:[0,1],mechan:0,gfortran:0,veri:[0,1],appar:0,exact:1,relev:0,cmf:0,list:1,iter:[0,1],"try":[0,1],vector:1,pleas:0,upper:1,slower:[0,1],direct:0,second:0,pass:1,carlo:[0,1],distcret:1,what:1,compar:1,section:1,brief:0,uniform:1,method:1,loglog:1,deriv:1,gener:[0,1],here:0,accur:1,address:0,along:[0,1],sinc:0,valu:[0,1],niter:1,search:0,slow:1,larger:1,discrete_alpha_ml:1,host:0,implement:[0,1],narrow:0,commonli:0,powerlaw:[0,1],appli:1,approxim:1,plot_lognormal_cdf:1,select:1,dnd:1,from:[0,1],describ:[0,1],useci:1,two:[0,1],websit:0,few:0,more:1,sort:1,clever:1,desir:0,finit:1,warn:1,flag:1,plexp:1,accept:0,given:1,none:1,setup:0,work:0,uniqu:1,minimum:1,can:[0,1],about:1,predict:1,smirnov:1,indic:1,high:0,fcompil:0,want:0,xmin:[0,1],end:0,far:1,nosmal:1,reject:1,answer:1,simpl:[0,1],wolfram:1,max:1,clone:0,mai:1,npt:1,law:[],data:[0,1],github:0,essenti:1,"2011apj":0,element:1,issu:0,move:0,becaus:[0,1],paper:0,through:1,suffer:1,paramet:1,fit:[],imf:0,chosen:1,"0x3e27e60":[],hobbl:0,"\u03b1":1,html:1,fig:1,therefor:1,non:1,good:0,"return":[0,1],greater:1,initi:0,newman:1,"0x23ad6e0":[],discrete_max_likelihood:1,didn:0,"0x32c7e60":[],autozoom:1,each:1,mean:[0,1],inplac:0,citat:0,multipl:1,continu:1,beyond:0,clauset:[0,1],"51m":0,setsiz:1,f2py:0,predefin:0,rel:1,print:[0,1],size:1,correct:[0,1],statist:[0,1],cplfit:[0,1],linear:0,parellel_map:1,alpha_:[0,1],reason:1,base:1,put:0,org:[0,1],likelihood:[0,1],vebos:1,could:1,perhap:0,origin:[0,1],rand:0,rang:1,directli:1,onc:1,qualiti:1,number:[0,1],wrapper:0,leastsquaresfittingpowerlaw:1,build_ext:0,xmarr:1,differ:1,"long":1,silent:1,exponenti:[0,1],unknown:1,messag:1,cumul:0,master:0,too:0,eqn:1,siam:1,conveni:0,cite:0,store:0,low:1,option:1,similarli:0,clauset2009_test:0,specifi:1,mathworld:1,part:[0,1],histcolor:1,attempt:0,kstest:1,than:1,std:1,keyword:1,mappabl:1,exampl:[0,1],bet:1,randomli:1,cleaner:0,comput:1,mypl:1,argument:1,packag:[0,1],seed:0,have:[0,1],deliv:1,need:[0,1],plotppf:1,"0x32c76e0":[],also:1,discret:1,"0x2f19e60":[],take:1,which:1,pyx:0,distribut:[],normal:[0,1],object:0,most:[0,1],pair:1,alpha:[0,1],rsc:0,"class":[0,1],dolog:1,fitter:[0,1],discrete_n_alpha:1,declar:0,determin:[0,1],test_pl:[0,1],axi:[0,1],someth:0,aaronc:1,cdf:1,luminos:0,verbos:1,xminvsk:1,empir:[0,1],hack:0,xminin:1,onli:[0,1],ksv:1,execut:[0,1],mydata:1,alphavsk:[0,1],discrete_ksd:1,usefortran:[0,1],diagnost:1,should:0,factor:1,local:[0,1],print_tim:1,get:1,pypi:0,piecewis:1,most_likely_alpha:1,fastest:[0,1],pointcolor:1,report:0,requir:[0,1],shalizi:1,bar:0,arxiv:1,median:1,"default":[0,1],bad:1,"0x32c16e0":[],contain:0,plot_lognormal_pdf:1,wiki:0,set:1,kolmogorov:1,see:[0,1],pointmark:1,result:[0,1],fail:1,close:[0,1],best:[0,1],review:1,tend:0,hist:1,figur:[0,1],drawn:1,n_alpha:1,numer:1,screen:0,harvard:0,kstest_:[0,1],distinguish:[0,1],doprint:1,quiet:1,against:1,mont:[0,1],instanc:0,equat:1,pdf:[0,1],com:[0,1],comment:0,minima:1,point:[0,1],within:1,suppdata:0,keflavich:0,respect:1,assum:1,backend:1,alpharang:1,invers:[0,1],been:0,plcolor:1,ani:1,drawstyl:1,"case":1,plotcdf:[0,1],ident:1,look:0,mle:1,kwarg:1,defin:1,pl_inv:[0,1],abov:[0,1],error:[0,1],real:1,invcdf:1,bias:1,test_fitt:[0,1],welcom:0,alphabet:0,make:0,complex:1,complet:0,http:[0,1],effect:0,user:1,typic:0,lower:1,off:0,inconsist:1,random:[0,1],well:[0,1],without:1,speedcompare_plfit:0,thi:[0,1],just:0,pylab:[0,1],rest:1,alpharangemult:1,discrete_best_alpha:1,speed:1,versu:1,"0x3df46e0":[],fortran:[0,1],"0x3df4e60":[],blob:0,input:1,hat:1,discrete_max_likelihood_arg:1,"0x32c1ed8":[],bin:0,around:1,bia:1,measur:1,tail:0,like:[0,1],zoom:1,"0x23ade60":[],output:[0,1],page:0,www:[0,1],often:0,plotpdf:[0,1],some:[0,1],maxim:1,intern:0,contin:1,sampl:1,agpi:0,scale:1,though:[0,1],estim:1,larg:0,adsab:0,"0x2f196e0":[],duplic:1,core:0,c0cc00366b:0,previou:0,run:[0,1],power:[],plot:[0,1],usag:0,broken:1,step:1,squeez:1,post:[0,1],comparison:1,plfit_test:0,actual:1,produc:1,cutoff:0,"float":1,automat:1,myplfit:0,ensur:0,"import":[0,1],discrete_likelihood_vector:1,your:[0,1],git:0,log:[0,1],wai:0,fast:0,start:0,nxarr:1,includ:0,fraction:1,suit:1,"function":[0,1],plexp_inv:[0,1],tupl:1,histogram:0,translat:0,"0x3416e60":1,santaf:1,"true":1,count:0,consist:[0,1],whether:[0,1],discrete_likelihood:1,maximum:1,troubl:0,below:1,limit:1,problem:1,similar:1,creat:[0,1],"int":1,doesn:0,novemb:0,file:0,nbin:1,doe:0,when:1,detail:1,"0x34166e0":1,other:0,bool:1,test:[0,1],you:[0,1],"0x3e276e0":[],nice:0,stat:1,intend:1,astronomi:0,docstr:1,fplfit:[0,1],consid:0,discrete_approx:1,plfit_lsq:1,directori:0,descript:[],mass:0,potenti:1,time:1},objtypes:{"0":"py:module","1":"py:method","2":"py:function","3":"py:class","4":"np:module","5":"np:method","6":"np:function","7":"np:class"},objnames:{"0":["py","module","Python module"],"1":["py","method","Python method"],"2":["py","function","Python function"],"3":["py","class","Python class"],"4":["np","module","Python module"],"5":["np","method","Python method"],"6":["np","function","Python function"],"7":["np","class","Python class"]},filenames:["index","apidoc","modules"],titles:["Power-law Distribution Fitting","API Documentation","."],objects:{"plfit.plfit.plfit":{plotcdf:[1,5,1,""],lognormal:[1,5,1,""],plotppf:[1,5,1,""],alphavsks:[1,5,1,""],xminvsks:[1,5,1,""],plot_lognormal_cdf:[1,5,1,""],plot_lognormal_pdf:[1,5,1,""],plfit:[1,5,1,""],alpha_:[1,5,1,""],discrete_best_alpha:[1,5,1,""],kstest_:[1,5,1,""],test_pl:[1,5,1,""],plotpdf:[1,5,1,""]},"plfit.plfit_py":{plexp_inv:[1,6,1,""],plfit:[1,7,1,""],test_fitter:[1,6,1,""],plexp:[1,6,1,""],pl_inv:[1,6,1,""]},plfit:{plfit:[1,4,0,"-"],plfit_py:[1,4,0,"-"]},"plfit.plfit":{plfit_lsq:[1,6,1,""],discrete_alpha_mle:[1,6,1,""],plexp_inv:[1,6,1,""],discrete_likelihood:[1,6,1,""],discrete_ksD:[1,6,1,""],plfit:[1,7,1,""],pl_inv:[1,6,1,""],discrete_max_likelihood:[1,6,1,""],test_fitter:[1,6,1,""],most_likely_alpha:[1,6,1,""],discrete_best_alpha:[1,6,1,""],plexp:[1,6,1,""],discrete_likelihood_vector:[1,6,1,""],discrete_max_likelihood_arg:[1,6,1,""]},"plfit.plfit_py.plfit":{plfit:[1,5,1,""],alpha_:[1,5,1,""],kstest_:[1,5,1,""]}},titleterms:{index:0,document:1,fit:0,power:0,api:1,python:1,numpi:1,modul:1,plfit:1,descript:0,matplotlib:1,content:0,version:1,plfit_pi:1,pure:1,tabl:0,instal:0,law:0,distribut:0}})PKesEDj"j"plfit-latest/py-modindex.html Python Module Index — plfit 1.0 documentation

Python Module Index

p
 
p
plfit
    plfit.plfit
    plfit.plfit_py
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKesEDaxk k plfit-latest/search.html Search — plfit 1.0 documentation

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKdsED 7plfit-latest/apidoc.html API Documentation — plfit 1.0 documentation

API Documentation

plfit Module

numpy/matplotlib version of plfit.py

A power-law distribution fitter based on code by Aaron Clauset. It can use fortran, cython, or numpy-based power-law fitting ‘backends’. Fortran’s fastest.

Requires pylab (matplotlib), which requires numpy

Example very simple use:

from plfit import plfit

MyPL = plfit(mydata)
MyPL.plotpdf(log=True)
plfit.plfit.discrete_alpha_mle(data, xmin)[source]

Equation B.17 of Clauset et al 2009

The Maximum Likelihood Estimator of the “scaling parameter” alpha in the discrete case is similar to that in the continuous case

plfit.plfit.discrete_best_alpha(data, alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True)[source]

Use the maximum L to determine the most likely value of alpha

alpharangemults [ 2-tuple ]
Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the “exact” alpha (by directly maximizing the likelihood function)
plfit.plfit.discrete_ksD(data, xmin, alpha)[source]

given a sorted data set, a minimum, and an alpha, returns the power law ks-test D value w/data

The returned value is the “D” parameter in the ks test

(this is implemented differently from the continuous version because there are potentially multiple identical points that need comparison to the power law)

plfit.plfit.discrete_likelihood(data, xmin, alpha)[source]

Equation B.8 in Clauset

Given a data set, an xmin value, and an alpha “scaling parameter”, computes the log-likelihood (the value to be maximized)

plfit.plfit.discrete_likelihood_vector(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)[source]

Compute the likelihood for all “scaling parameters” in the range (alpharange) for a given xmin. This is only part of the discrete value likelihood maximization problem as described in Clauset et al (Equation B.8)

alpharange [ 2-tuple ]
Two floats specifying the upper and lower limits of the power law alpha to test
plfit.plfit.discrete_max_likelihood(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)[source]

Returns the argument of the max of the likelihood of the data given an input xmin

plfit.plfit.discrete_max_likelihood_arg(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)[source]

Returns the argument of the max of the likelihood of the data given an input xmin

plfit.plfit.most_likely_alpha(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)[source]

Return the most likely alpha for the data given an xmin

plfit.plfit.pl_inv(P, xm, a)[source]

Inverse CDF for a pure power-law

plfit.plfit.plexp(x, xm=1, a=2.5)[source]

CDF(x) for the piecewise distribution exponential x<xmin, powerlaw x>=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.

plfit.plfit.plexp_inv(P, xm, a)[source]

Inverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.

class plfit.plfit.plfit(x, **kwargs)[source]

A Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_ from `http://www.santafe.edu/~aaronc/powerlaws/`_.

See A. Clauset, C.R. Shalizi, and M.E.J. Newman, “Power-law distributions in empirical data” SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)

The output “alpha” is defined such that p(x) \sim (x/xmin)^{-alpha}

alpha_(x)[source]

Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.

Docstring for the generated alpha function:

Given a sorted data set and a minimum, returns power law MLE fit
data is passed as a keyword parameter so that it can be vectorized

If there is only one element, return alpha=0
alphavsks(autozoom=True, **kwargs)[source]

Plot alpha versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the ‘best’ fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.

discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)[source]

Use the maximum L to determine the most likely value of alpha

alpharangemults [ 2-tuple ]
Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the “exact” alpha (by directly maximizing the likelihood function)
n_alpha [ int ]
Number of alpha values to use when measuring. Larger number is more accurate.
approximate [ bool ]
If False, try to “zoom-in” around the MLE alpha and get the exact best alpha value within some range around the approximate best

vebose [ bool ] finite [ bool ]

Correction for finite data?
kstest_(x)[source]

Create a mappable function kstest to apply to each xmin in a list of xmins.

Docstring for the generated kstest function:

Given a sorted data set and a minimum, returns power law MLE ks-test w/data
data is passed as a keyword parameter so that it can be vectorized

The returned value is the "D" parameter in the ks test.
lognormal(doprint=True)[source]

Use the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parameters

plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)[source]

A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/

See A. Clauset, C.R. Shalizi, and M.E.J. Newman, “Power-law distributions in empirical data” SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062

There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython) version is ~10% slower, and the python version is ~3x slower than the fortran version. Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknown reasons.

There is also a discrete version implemented in python - it is different from the continous version!

discrete [ bool | None ]
If discrete is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged “bad” data), the “automatic” determination will fail. If discrete is True or False, the distcrete or continuous fitter will be used, respectively.
xmin [ float / int ]
If you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha.
nosmall [ bool (True) ]
When on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the “powerlaw” python package
finite [ bool (False) ]
There is a ‘finite-size bias’ to the estimator. The “alpha” the code measures is “alpha-hat” s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / n
quiet [ bool (False) ]
If False, delivers messages about what fitter is used and the fit results
verbose [ bool (False) ]
Deliver descriptive messages about the fit parameters (only if *quiet*==False)
silent [ bool (False) ]
If True, will print NO messages
plot_lognormal_cdf(**kwargs)[source]

Plot the fitted lognormal distribution

plot_lognormal_pdf(**kwargs)[source]

Plot the fitted lognormal distribution

plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)[source]

Plots CDF and powerlaw

plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)[source]

Plots PDF and powerlaw.

kwargs is passed to pylab.hist and pylab.plot

plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)[source]

Plots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality.

test_pl(niter=1000.0, print_timing=False, **kwargs)[source]

Monte-Carlo test to determine whether distribution is consistent with a power law

Runs through niter iterations of a sample size identical to the input sample size.

Will randomly select values from the data < xmin. The number of values selected will be chosen from a uniform random distribution with p(<xmin) = n(<xmin)/n.

Once the sample is created, it is fit using above methods, then the best fit is used to compute a Kolmogorov-Smirnov statistic. The KS stat distribution is compared to the KS value for the fit to the actual data, and p = fraction of random ks values greater than the data ks value is computed. If p<.1, the data may be inconsistent with a powerlaw. A data set of n(>xmin)>100 is required to distinguish a PL from an exponential, and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL. For more details, see figure 4.1 and section

WARNING This can take a very long time to run! Execution time scales as niter * setsize

xminvsks(**kwargs)[source]

Plot xmin versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the ‘best’ fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.

plfit.plfit.plfit_lsq(x, y)[source]

Returns A and B in y=Ax^B http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html

plfit.plfit.test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=<function plexp_inv at 0x34166e0>)[source]

Tests the power-law fitter

Examples

Example (fig 3.4b in Clauset et al.):

xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]
xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)
loglog(xminin,xmarr.squeeze(),'x')

Example 2:

xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]
xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)
loglog(xminin,xmarr.mean(axis=0),'x')

Example 3:

xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)
hist(xmarr.squeeze());
# Test results:
# mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20
# mean(af) = 2.51 median(af) = 2.49  std(af)=0.14
# biased distribution; far from correct value of xmin but close to correct alpha

Example 4:

xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)
print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))
print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))
# mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35
# mean(af): 2.51 median(af): 2.50 std(af): 0.07

plfit_py Module

Duplicate of the above plfit module, but without using numpy (or matplotlib, therefore no plots)

Pure-Python version of plfit.py

A pure python power-law distribution fitter based on code by Aaron Clauset. This is the slowest implementation, but has no dependencies.

Example very simple use:

from plfit_py import plfit

MyPL = plfit(mydata)
MyPL.plotpdf(log=True)
plfit.plfit_py.pl_inv(P, xm, a)[source]

Inverse CDF for a pure power-law

plfit.plfit_py.plexp(x, xm=1, a=2.5)[source]

CDF(x) for the piecewise distribution exponential x<xmin, powerlaw x>=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.

plfit.plfit_py.plexp_inv(P, xm, a)[source]

Inverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.

class plfit.plfit_py.plfit(x, **kwargs)[source]

A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/

See A. Clauset, C.R. Shalizi, and M.E.J. Newman, “Power-law distributions in empirical data” SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062

The output “alpha” is defined such that p(x) \sim (x/xmin)^{-alpha}

alpha_(x)[source]

Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.

kstest_(x)[source]
plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)[source]

A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/

See A. Clauset, C.R. Shalizi, and M.E.J. Newman, “Power-law distributions in empirical data” SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062

nosmall is on by default; it rejects low s/n points can specify xmin to skip xmin estimation

This is only for continuous distributions; I have not implemented a pure-python discrete distribution fitter

plfit.plfit_py.test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=<function plexp_inv at 0x3416e60>, quiet=True, silent=True)[source]

Tests the power-law fitter

Examples

Example (fig 3.4b in Clauset et al.):

xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]
xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)
loglog(xminin,xmarr.squeeze(),'x')

Example 2:

xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]
xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)
loglog(xminin,xmarr.mean(axis=0),'x')

Example 3:

xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)
hist(xmarr.squeeze());
# Test results:
# mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20
# mean(af) = 2.51 median(af) = 2.49  std(af)=0.14
# biased distribution; far from correct value of xmin but close to correct alpha

Example 4:

xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)
print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))
print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))
# mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35
# mean(af): 2.51 median(af): 2.50 std(af): 0.07
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKisED wplfit-latest/.buildinfo# Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. config: e67f5b8f011e71761f1116b2625418c5 tags: efa25262f700e02b1777eb79ee109f5c PKesED4vj"j"plfit-latest/np-modindex.html Python Module Index — plfit 1.0 documentation

Python Module Index

p
 
p
plfit
    plfit.plfit
    plfit.plfit_py
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKdsED /'/'plfit-latest/modules.html . — plfit 1.0 documentation
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKesED66plfit-latest/genindex.html Index — plfit 1.0 documentation
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKisED}4wBqqplfit-latest/objects.inv# Sphinx inventory version 2 # Project: plfit # Version: 1.0 # The remainder of this file is compressed using zlib. xڥOo $U3waɒ}m#Vo?(Z^_(ͫXגm$1:,K3lD=]vD45E96{ghvmJ{VwLux#k4?Lvpd5o9'M`p⺷|וl'b-^ȪԚSSr0}v Op_# KuM=!Za@4_!F 0R]/$6%m&}WlK`L}e͙Ad ,Y:,H+ N9ȂY%eX̄JsPKdsEDH"/R/Rplfit-latest/index.html Power-law Distribution Fitting — plfit 1.0 documentation

Power-law Distribution Fitting

This is a python implementation of a power-law distribution fitter. The code here was originally hosted on agpy but was moved and re-packaged to make setup.py cleaner.

Installation

I’ve attempted to make the setup.py file work nicely, but it includes some hacks, so if you run into trouble, please report it:

git clone git@github.com:keflavich/plfit.git
cd plfit
python setup.py install

If python setup.py install doesn’t work, you can try the following:

To install the cython function, run: python setup.py build_ext --inplace

To install the fortran function:

cd plfit/plfit/
f2py -c fplfit.f -m fplfit --fcompiler=gfortran

Description

Aaron Clauset et al. address the issue of fitting power-laws to distributions on this website and in their paper, Power-law distributions in empirical data. I have created a python implementation of their code because I didn’t have matlab or R and wanted to do some power-law fitting.

Power-laws are very commonly used in astronomy and are typically used to describe the initial mass function (IMF), the core mass function (CMF), and often luminosity distributions. Most distributions in astronomy tend to be apparent power-laws because the source counts are too few or too narrow to distinguish powerlaws from log-normal and other distributions. But, to this end, I’ve included the testing mechanism to test for consistency with a power law as described in the above paper.

The python internal documentation is complete. A brief description of relevant functions is included here for convenience:

plfit is implemented as a class. This means that you import plfit, and declare an instance of the plfit class:

import plfit
X = rand(1000)
myplfit = plfit.plfit(X)

The results of the fit are printed to the screen (if desired) and are stored as part of the object.

alpha_ and kstest_ are functions used internally to determine the ks-statistic and alpha values as a function of xmin.

There are 3 predefined plotting functions:
  • alphavsks plots alpha on the y-axis vs. the ks statistic value on the x-axis with the ‘best-fit’ alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits.
  • plotcdf plots the cumulative distribution function along with the best-fit power law
  • plotpdf plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well.
Other useful functions:
  • test_pl uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a “p-value” that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!).
  • plexp_inv creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests.
  • pl_inv creates a pure cutoff power-law distribution
  • test_fitter uses the previous two functions to test the fitter’s ability to return the correct xmin and alpha values for large numbers of iterations

The powerlaw fitter is very effective at returning the correct value of alpha but not as good at returning the correct value of xmin.

There are 3 implementations of the code internals. fplfit.f is a fortran function, cplfit.pyx is a cython function, and plfit.py is the wrapper and includes a python-only implementation that requires numpy. FORTRAN is fastest, follow closely by cython. Python is ~3x slower.

As of November 21, 2011, there is a pure python (i.e., no numpy) implementation at <https://github.com/keflavich/plfit/blob/master/plfit/plfit_py.py> - you can just put this file in your local working directory and import it, since it contains no requirements beyond pure python. It’s slower and hobbled, but it works, and perhaps will run fast with pypy.

For usage examples, see

A very simple example:

import plfit
from numpy.random import rand,seed

# generate a power law using the "inverse" power-law generator code
X=plfit.plexp_inv(rand(1000),1,2.5)

# use the numpy version to fit (usefortran=False is only needed if you installed the fortran version)
myplfit=plfit.plfit(X,usefortran=False)
# output should look something like this:
# PYTHON plfit executed in 0.201362 seconds
# xmin: 0.621393 n(>xmin): 263 alpha: 2.39465 +/- 0.0859979   Log-Likelihood: -238.959   ks: 0.0278864 p(ks): 0.986695

# generate some plots
from pylab import *
figure(1)
myplfit.plotpdf()

figure(2)
myplfit.plotcdf()

If you use this code, please cite Clauset et al 2009 and consider posting a comment on the wiki page.

Direct citations to the source are welcome! The python translation has been cited in the following works (and perhaps others?):

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKesEDl) plfit-latest/_modules/index.html Overview: module code — plfit 1.0 documentation

All modules for which code is available

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKesEDѹTayay&plfit-latest/_modules/plfit/plfit.html plfit.plfit — plfit 1.0 documentation

Source code for plfit.plfit

# -*- coding: latin-1 -*-
# 
# intended to implement a power-law fitting routine as specified in.....
# http://www.santafe.edu/~aaronc/powerlaws/
#
# The MLE for the power-law alpha is very easy to derive given knowledge
# of the lowest value at which a power law holds, but that point is 
# difficult to derive and must be acquired iteratively.

"""
numpy/matplotlib version of plfit.py
====================================
A power-law distribution fitter based on code by Aaron Clauset.  It can use
fortran, cython, or numpy-based power-law fitting 'backends'.  Fortran's
fastest.

Requires pylab (matplotlib), which requires numpy

Example very simple use::

    from plfit import plfit

    MyPL = plfit(mydata)
    MyPL.plotpdf(log=True)

"""

import numpy 
import time
import pylab
try:
    import fplfit
    fortranOK = True
except:
    fortranOK = False
try:
    import cplfit
    cyOK = True
except:
    cyOK = False

import numpy.random as npr
from numpy import log,log10,sum,argmin,argmax,exp,min,max
try:
    import scipy.stats
    scipyOK = True
except ImportError:
    scipyOK = False
    print "scipy didn't import.  Can't compute certain basic statistics."

[docs]class plfit: """ A Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_ from `http://www.santafe.edu/~aaronc/powerlaws/`_. See `A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) <http://arxiv.org/abs/0706.1062>`_ The output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}` """ def __init__(self,x,**kwargs): """ Initializes and fits the power law. Can pass "quiet" to turn off output (except for warnings; "silent" turns off warnings) """ x = numpy.array(x) # make sure x is an array, otherwise the next step fails if (x<0).sum() > 0: print "Removed %i negative points" % ((x<0).sum()) x = x[x>0] self.data = x self.plfit(**kwargs)
[docs] def alpha_(self,x): """ Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users. Docstring for the generated alpha function:: Given a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized If there is only one element, return alpha=0 """ def alpha(xmin,x=x): gexmin = x>=xmin n = gexmin.sum() if n < 2: return 0 x = x[gexmin] a = 1 + float(n) / sum(log(x/xmin)) return a return alpha
[docs] def kstest_(self,x): """ Create a mappable function kstest to apply to each xmin in a list of xmins. Docstring for the generated kstest function:: Given a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test. """ def kstest(xmin,x=x): x = x[x>=xmin] n = float(len(x)) if n == 0: return numpy.inf a = float(n) / sum(log(x/xmin)) cx = numpy.arange(n,dtype='float')/float(n) cf = 1-(xmin/x)**a ks = max(abs(cf-cx)) return ks return kstest
[docs] def plfit(self, nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000): """ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/ See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062 There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython) version is ~10% slower, and the python version is ~3x slower than the fortran version. Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknown reasons. There is also a discrete version implemented in python - it is different from the continous version! *discrete* [ bool | None ] If *discrete* is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If *discrete* is True or False, the distcrete or continuous fitter will be used, respectively. *xmin* [ float / int ] If you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha. *nosmall* [ bool (True) ] When on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the "powerlaw" python package *finite* [ bool (False) ] There is a 'finite-size bias' to the estimator. The "alpha" the code measures is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / n *quiet* [ bool (False) ] If False, delivers messages about what fitter is used and the fit results *verbose* [ bool (False) ] Deliver descriptive messages about the fit parameters (only if *quiet*==False) *silent* [ bool (False) ] If True, will print NO messages """ x = self.data z = numpy.sort(x) t = time.time() xmins,argxmins = numpy.unique(z,return_index=True)#[:-1] self._nunique = len(xmins) if self._nunique == len(x) and discrete is None: if verbose: print "Using CONTINUOUS fitter" discrete = False elif self._nunique < len(x) and discrete is None: if verbose: print "Using DISCRETE fitter" discrete = True t = time.time() if xmin is None: if discrete: self.discrete_best_alpha(approximate=discrete_approx, n_alpha=discrete_n_alpha, verbose=verbose, finite=finite) return self._xmin,self._alpha elif usefortran and fortranOK: dat,av = fplfit.plfit(z,int(nosmall)) goodvals=dat>0 sigma = ((av-1)/numpy.sqrt(len(z)-numpy.arange(len(z))))[argxmins] dat = dat[goodvals] av = av[goodvals] if nosmall: # data, av a;ready treated for this. sigma, xmins not nmax = argmin(sigma<0.1) xmins = xmins[:nmax] sigma = sigma[:nmax] if not quiet: print "FORTRAN plfit executed in %f seconds" % (time.time()-t) elif usecy and cyOK: dat,av = cplfit.plfit_loop(z,nosmall=nosmall,zunique=xmins,argunique=argxmins) goodvals=dat>0 sigma = (av-1)/numpy.sqrt(len(z)-argxmins+1) dat = dat[goodvals] av = av[goodvals] if not quiet: print "CYTHON plfit executed in %f seconds" % (time.time()-t) else: av = numpy.asarray( map(self.alpha_(z),xmins) ,dtype='float') dat = numpy.asarray( map(self.kstest_(z),xmins),dtype='float') sigma = (av-1)/numpy.sqrt(len(z)-argxmins+1) if nosmall: # test to make sure the number of data points is high enough # to provide a reasonable s/n on the computed alpha goodvals = sigma<0.1 nmax = argmin(goodvals) if nmax > 0: dat = dat[:nmax] xmins = xmins[:nmax] av = av[:nmax] sigma = sigma[:nmax] else: if not silent: print "Not enough data left after flagging - using all positive data." if not quiet: print "PYTHON plfit executed in %f seconds" % (time.time()-t) if usefortran: print "fortran fplfit did not load" if usecy: print "cython cplfit did not load" self._av = av self._xmin_kstest = dat self._sigma = sigma # [:-1] to weed out the very last data point; it cannot be correct # (can't have a power law with 1 data point). # However, this should only be done if the ends have not previously # been excluded with nosmall if nosmall: xmin = xmins[argmin(dat)] else: xmin = xmins[argmin(dat[:-1])] z = z[z>=xmin] n = len(z) alpha = 1 + n / sum(log(z/xmin)) if finite: alpha = alpha*(n-1.)/n+1./n if n < 50 and not finite and not silent: print '(PLFIT) Warning: finite-size bias may be present. n=%i' % n ks = max(abs( numpy.arange(n)/float(n) - (1-(xmin/z)**(alpha-1)) )) # Parallels Eqn 3.5 in Clauset et al 2009, but zeta(alpha, xmin) = (alpha-1)/xmin. Really is Eqn B3 in paper. L = n*log((alpha-1)/xmin) - alpha*sum(log(z/xmin)) #requires another map... Larr = arange(len(unique(x))) * log((av-1)/unique(x)) - av*sum self._likelihood = L self._xmin = xmin self._xmins = xmins self._alpha= alpha self._alphaerr = (alpha-1)/numpy.sqrt(n) self._ks = ks # this ks statistic may not have the same value as min(dat) because of unique() if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(ks*numpy.sqrt(n)) self._ngtx = n if n == 1: if not silent: print "Failure: only 1 point kept. Probably not a power-law distribution." self._alpha = alpha = 0 self._alphaerr = 0 self._likelihood = L = 0 self._ks = 0 self._ks_prob = 0 self._xmin = xmin return xmin,0 if numpy.isnan(L) or numpy.isnan(xmin) or numpy.isnan(alpha): raise ValueError("plfit failed; returned a nan") if not quiet: if verbose: print "The lowest value included in the power-law fit, ", print "xmin: %g" % xmin, if verbose: print "\nThe number of values above xmin, ", print "n(>xmin): %i" % n, if verbose: print "\nThe derived power-law alpha (p(x)~x^-alpha) with MLE-derived error, ", print "alpha: %g +/- %g " % (alpha,self._alphaerr), if verbose: print "\nThe log of the Likelihood (the maximized parameter; you minimized the negative log likelihood), ", print "Log-Likelihood: %g " % L, if verbose: print "\nThe KS-test statistic between the best-fit power-law and the data, ", print "ks: %g" % (ks), if scipyOK: if verbose: print " occurs with probability ", print "p(ks): %g" % (self._ks_prob) else: print return xmin,alpha
[docs] def discrete_best_alpha(self, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True, finite=True): """ Use the maximum L to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function) *n_alpha* [ int ] Number of alpha values to use when measuring. Larger number is more accurate. *approximate* [ bool ] If False, try to "zoom-in" around the MLE alpha and get the exact best alpha value within some range around the approximate best *vebose* [ bool ] *finite* [ bool ] Correction for finite data? """ data = self.data self._xmins = xmins = numpy.unique(data) if approximate: alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] else: alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] alpharanges = [(0.9*a,1.1*a) for a in alpha_approx] alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha) for xmin,ar in zip(xmins,alpharanges) ] ksvalues = numpy.array([ discrete_ksD(data, xmin, alpha) for xmin,alpha in zip(xmins,alpha_of_xmin) ]) self._av = numpy.array(alpha_of_xmin) self._xmin_kstest = ksvalues ksvalues[numpy.isnan(ksvalues)] = numpy.inf best_index = argmin(ksvalues) self._alpha = best_alpha = alpha_of_xmin[best_index] self._xmin = best_xmin = xmins[best_index] self._ks = best_ks = ksvalues[best_index] self._likelihood = best_likelihood = discrete_likelihood(data, best_xmin, best_alpha) if finite: self._alpha = self._alpha*(n-1.)/n+1./n if verbose: print "alpha = %f xmin = %f ksD = %f L = %f (n<x) = %i (n>=x) = %i" % ( best_alpha, best_xmin, best_ks, best_likelihood, (data<best_xmin).sum(), (data>=best_xmin).sum()) self._ngtx = n = (self.data>=self._xmin).sum() self._alphaerr = (self._alpha-1.0)/numpy.sqrt(n) if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(self._ks*numpy.sqrt(n)) return best_alpha,best_xmin,best_ks,best_likelihood
[docs] def xminvsks(self, **kwargs): """ Plot xmin versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function. """ pylab.plot(self._xmins,self._xmin_kstest,'.') pylab.plot(self._xmin,self._ks,'s') #pylab.errorbar([self._ks],self._alpha,yerr=self._alphaerr,fmt='+') ax=pylab.gca() ax.set_ylabel("KS statistic") ax.set_xlabel("min(x)") pylab.draw() return ax
[docs] def alphavsks(self,autozoom=True,**kwargs): """ Plot alpha versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function. """ pylab.plot(1+self._av,self._xmin_kstest,'.') pylab.errorbar(self._alpha,[self._ks],xerr=self._alphaerr,fmt='+') ax=pylab.gca() if autozoom: ax.set_ylim(0.8*(self._ks),3*(self._ks)) ax.set_xlim((self._alpha)-5*self._alphaerr,(self._alpha)+5*self._alphaerr) ax.set_ylabel("KS statistic") ax.set_xlabel(r'$\alpha$') pylab.draw() return ax
[docs] def plotcdf(self, x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs): """ Plots CDF and powerlaw """ if x is None: x=self.data if xmin is None: xmin=self._xmin if alpha is None: alpha=self._alpha x=numpy.sort(x) n=len(x) xcdf = numpy.arange(n,0,-1,dtype='float')/float(n) q = x[x>=xmin] fcdf = (q/xmin)**(1-alpha) nc = xcdf[argmax(x>=xmin)] fcdf_norm = nc*fcdf D_location = argmax(xcdf[x>=xmin]-fcdf_norm) pylab.vlines(q[D_location],xcdf[x>=xmin][D_location],fcdf_norm[D_location],color='m',linewidth=2) #plotx = pylab.linspace(q.min(),q.max(),1000) #ploty = (plotx/xmin)**(1-alpha) * nc pylab.loglog(x,xcdf,marker=pointmarker,color=pointcolor,**kwargs) #pylab.loglog(plotx,ploty,'r',**kwargs) pylab.loglog(q,fcdf_norm,'r',**kwargs)
[docs] def plotpdf(self,x=None,xmin=None,alpha=None,nbins=50,dolog=True,dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs): """ Plots PDF and powerlaw. kwargs is passed to pylab.hist and pylab.plot """ if not(x): x=self.data if not(xmin): xmin=self._xmin if not(alpha): alpha=self._alpha x=numpy.sort(x) n=len(x) pylab.gca().set_xscale('log') pylab.gca().set_yscale('log') if dnds: hb = pylab.histogram(x,bins=numpy.logspace(log10(min(x)),log10(max(x)),nbins)) h = hb[0] b = hb[1] db = hb[1][1:]-hb[1][:-1] h = h/db pylab.plot(b[:-1],h,drawstyle=drawstyle,color=histcolor,**kwargs) #alpha -= 1 elif dolog: hb = pylab.hist(x,bins=numpy.logspace(log10(min(x)),log10(max(x)),nbins),log=True,fill=False,edgecolor=histcolor,**kwargs) alpha -= 1 h,b=hb[0],hb[1] else: hb = pylab.hist(x,bins=numpy.linspace((min(x)),(max(x)),nbins),fill=False,edgecolor=histcolor,**kwargs) h,b=hb[0],hb[1] # plotting points are at the center of each bin b = (b[1:]+b[:-1])/2.0 q = x[x>=xmin] px = (alpha-1)/xmin * (q/xmin)**(-alpha) # Normalize by the median ratio between the histogram and the power-law # The normalization is semi-arbitrary; an average is probably just as valid plotloc = (b>xmin)*(h>0) norm = numpy.median( h[plotloc] / ((alpha-1)/xmin * (b[plotloc]/xmin)**(-alpha)) ) px = px*norm plotx = pylab.linspace(q.min(),q.max(),1000) ploty = (alpha-1)/xmin * (plotx/xmin)**(-alpha) * norm #pylab.loglog(q,px,'r',**kwargs) pylab.loglog(plotx,ploty,color=plcolor,**kwargs) axlims = pylab.axis() pylab.vlines(xmin,axlims[2],max(px),colors=plcolor,linestyle='dashed') pylab.gca().set_xlim(min(x),max(x))
[docs] def plotppf(self,x=None,xmin=None,alpha=None,dolog=True,**kwargs): """ Plots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality. """ if not(xmin): xmin=self._xmin if not(alpha): alpha=self._alpha if not(x): x=numpy.sort(self.data[self.data>xmin]) else: x=numpy.sort(x[x>xmin]) # N = M^(-alpha+1) # M = N^(1/(-alpha+1)) m0 = min(x) N = (1.0+numpy.arange(len(x)))[::-1] xmodel = m0 * N**(1/(1-alpha)) / max(N)**(1/(1-alpha)) if dolog: pylab.loglog(x,xmodel,'.',**kwargs) pylab.gca().set_xlim(min(x),max(x)) pylab.gca().set_ylim(min(x),max(x)) else: pylab.plot(x,xmodel,'.',**kwargs) pylab.plot([min(x),max(x)],[min(x),max(x)],'k--') pylab.xlabel("Real Value") pylab.ylabel("Power-Law Model Value")
[docs] def test_pl(self,niter=1e3, print_timing=False, **kwargs): """ Monte-Carlo test to determine whether distribution is consistent with a power law Runs through niter iterations of a sample size identical to the input sample size. Will randomly select values from the data < xmin. The number of values selected will be chosen from a uniform random distribution with p(<xmin) = n(<xmin)/n. Once the sample is created, it is fit using above methods, then the best fit is used to compute a Kolmogorov-Smirnov statistic. The KS stat distribution is compared to the KS value for the fit to the actual data, and p = fraction of random ks values greater than the data ks value is computed. If p<.1, the data may be inconsistent with a powerlaw. A data set of n(>xmin)>100 is required to distinguish a PL from an exponential, and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL. For more details, see figure 4.1 and section **WARNING** This can take a very long time to run! Execution time scales as niter * setsize """ xmin = self._xmin alpha = self._alpha niter = int(niter) ntail = sum(self.data >= xmin) ntot = len(self.data) nnot = ntot-ntail # n(<xmin) pnot = nnot/float(ntot) # p(<xmin) nonpldata = self.data[self.data<xmin] nrandnot = sum( npr.rand(ntot) < pnot ) # randomly choose how many to sample from <xmin nrandtail = ntot - nrandnot # and the rest will be sampled from the powerlaw ksv = [] if print_timing: deltat = [] for i in xrange(niter): # first, randomly sample from power law # with caveat! nonplind = numpy.floor(npr.rand(nrandnot)*nnot).astype('int') fakenonpl = nonpldata[nonplind] randarr = npr.rand(nrandtail) fakepl = randarr**(1/(1-alpha)) * xmin fakedata = numpy.concatenate([fakenonpl,fakepl]) if print_timing: t0 = time.time() # second, fit to powerlaw # (add some silencing kwargs optionally) for k,v in {'quiet':True,'silent':True,'nosmall':True}.iteritems(): if k not in kwargs: kwargs[k] = v TEST = plfit(fakedata,**kwargs) ksv.append(TEST._ks) if print_timing: deltat.append( time.time() - t0 ) print "Iteration %i: %g seconds" % (i, deltat[-1]) ksv = numpy.array(ksv) p = (ksv>self._ks).sum() / float(niter) self._pval = p self._ks_rand = ksv print "p(%i) = %0.3f" % (niter,p) if print_timing: print "Iteration timing: %g +/- %g" % (numpy.mean(deltat),numpy.std(deltat)) return p,ksv
[docs] def lognormal(self,doprint=True): """ Use the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parameters """ # N = float(self.data.shape[0]) # mu = log(self.data).sum() / N # sigmasquared = ( ( log(self.data) - mu )**2 ).sum() / N # self.lognormal_mu = mu # self.lognormal_sigma = numpy.sqrt(sigmasquared) # self.lognormal_likelihood = -N/2. * log(numpy.pi*2) - N/2. * log(sigmasquared) - 1/(2*sigmasquared) * (( self.data - mu )**2).sum() # if doprint: # print "Best fit lognormal is exp( -(x-%g)^2 / (2*%g^2)" % (mu,numpy.sqrt(sigmasquared)) # print "Likelihood: %g" % (self.lognormal_likelihood) if scipyOK: fitpars = scipy.stats.lognorm.fit(self.data) self.lognormal_dist = scipy.stats.lognorm(*fitpars) self.lognormal_ksD,self.lognormal_ksP = scipy.stats.kstest(self.data,self.lognormal_dist.cdf) # nnlf = NEGATIVE log likelihood self.lognormal_likelihood = -1*scipy.stats.lognorm.nnlf(fitpars,self.data) # Is this the right likelihood ratio? # Definition of L from eqn. B3 of Clauset et al 2009: # L = log(p(x|alpha)) # _nnlf from scipy.stats.distributions: # -sum(log(self._pdf(x, *args)),axis=0) # Assuming the pdf and p(x|alpha) are both non-inverted, it looks # like the _nnlf and L have opposite signs, which would explain the # likelihood ratio I've used here: self.power_lognorm_likelihood = (self._likelihood + self.lognormal_likelihood) # a previous version had 2*(above). That is the correct form if you want the likelihood ratio # statistic "D": http://en.wikipedia.org/wiki/Likelihood-ratio_test # The above explanation makes sense, since nnlf is the *negative* log likelihood function: ## nnlf -- negative log likelihood function (to minimize) # # Assuming we want the ratio between the POSITIVE likelihoods, the D statistic is: # D = -2 log( L_power / L_lognormal ) self.likelihood_ratio_D = -2 * (log(self._likelihood/self.lognormal_likelihood)) if doprint: print "Lognormal KS D: %g p(D): %g" % (self.lognormal_ksD,self.lognormal_ksP), print " Likelihood Ratio Statistic (powerlaw/lognormal): %g" % self.likelihood_ratio_D print "At this point, have a look at Clauset et al 2009 Appendix C: determining sigma(likelihood_ratio)"
[docs] def plot_lognormal_pdf(self,**kwargs): """ Plot the fitted lognormal distribution """ if not hasattr(self,'lognormal_dist'): return normalized_pdf = self.lognormal_dist.pdf(self.data)/self.lognormal_dist.pdf(self.data).max() minY,maxY = pylab.gca().get_ylim() pylab.plot(self.data,normalized_pdf*maxY,'.',**kwargs)
[docs] def plot_lognormal_cdf(self,**kwargs): """ Plot the fitted lognormal distribution """ if not hasattr(self,'lognormal_dist'): return x=numpy.sort(self.data) n=len(x) xcdf = numpy.arange(n,0,-1,dtype='float')/float(n) lcdf = self.lognormal_dist.sf(x) D_location = argmax(xcdf-lcdf) pylab.vlines(x[D_location],xcdf[D_location],lcdf[D_location],color='m',linewidth=2) pylab.plot(x, lcdf,',',**kwargs)
[docs]def plfit_lsq(x,y): """ Returns A and B in y=Ax^B http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html """ n = len(x) btop = n * (log(x)*log(y)).sum() - (log(x)).sum()*(log(y)).sum() bbottom = n*(log(x)**2).sum() - (log(x).sum())**2 b = btop / bbottom a = ( log(y).sum() - b * log(x).sum() ) / n A = exp(a) return A,b
[docs]def plexp(x,xm=1,a=2.5): """ CDF(x) for the piecewise distribution exponential x<xmin, powerlaw x>=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + exp(a)*xm/a) Ppl = lambda(X): 1+C*(xm/(1-a)*(X/xm)**(1-a)) Pexp = lambda(X): C*xm/a*exp(a)-C*(xm/a)*exp(-a*(X/xm-1)) d=Ppl(x) d[x<xm]=Pexp(x) return d
[docs]def plexp_inv(P,xm,a): """ Inverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + exp(a)*xm/a) Pxm = 1+C*(xm/(1-a)) x = P*0 x[P>=Pxm] = xm*( (P[P>=Pxm]-1) * (1-a)/(C*xm) )**(1/(1-a)) # powerlaw x[P<Pxm] = (log( (C*xm/a*exp(a)-P[P<Pxm])/(C*xm/a) ) - a) * (-xm/a) # exp return x
[docs]def pl_inv(P,xm,a): """ Inverse CDF for a pure power-law """ x = (1-P)**(1/(1-a)) * xm return x
[docs]def test_fitter(xmin=1.0,alpha=2.5,niter=500,npts=1000,invcdf=plexp_inv): """ Tests the power-law fitter Examples ======== Example (fig 3.4b in Clauset et al.):: xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x') Example 2:: xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x') Example 3:: xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alpha Example 4:: xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07 """ xmin = numpy.array(xmin) if xmin.shape == (): xmin.shape = 1 lx = len(xmin) sz = [niter,lx] xmarr,alphaf_v,ksv,nxarr = numpy.zeros(sz),numpy.zeros(sz),numpy.zeros(sz),numpy.zeros(sz) for j in xrange(lx): for i in xrange(niter): randarr = npr.rand(npts) fakedata = invcdf(randarr,xmin[j],alpha) TEST = plfit(fakedata,quiet=True,silent=True,nosmall=True) alphaf_v[i,j] = TEST._alpha ksv[i,j] = TEST._ks nxarr[i,j] = TEST._ngtx xmarr[i,j] = TEST._xmin return xmarr,alphaf_v,ksv,nxarr
[docs]def discrete_likelihood(data, xmin, alpha): """ Equation B.8 in Clauset Given a data set, an xmin value, and an alpha "scaling parameter", computes the log-likelihood (the value to be maximized) """ if not scipyOK: raise ImportError("Can't import scipy. Need scipy for zeta function.") from scipy.special import zeta as zeta zz = data[data>=xmin] nn = len(zz) sum_log_data = numpy.log(zz).sum() zeta = zeta(alpha, xmin) L_of_alpha = -1*nn*log(zeta) - alpha * sum_log_data return L_of_alpha
[docs]def discrete_likelihood_vector(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Compute the likelihood for all "scaling parameters" in the range (alpharange) for a given xmin. This is only part of the discrete value likelihood maximization problem as described in Clauset et al (Equation B.8) *alpharange* [ 2-tuple ] Two floats specifying the upper and lower limits of the power law alpha to test """ from scipy.special import zeta as zeta zz = data[data>=xmin] nn = len(zz) alpha_vector = numpy.linspace(alpharange[0],alpharange[1],n_alpha) sum_log_data = numpy.log(zz).sum() # alpha_vector is a vector, xmin is a scalar zeta_vector = zeta(alpha_vector, xmin) #xminvec = numpy.arange(1.0,xmin) #xminalphasum = numpy.sum([xm**(-alpha_vector) for xm in xminvec]) #L = -1*alpha_vector*sum_log_data - nn*log(zeta_vector) - xminalphasum L_of_alpha = -1*nn*log(zeta_vector) - alpha_vector * sum_log_data return L_of_alpha
[docs]def discrete_max_likelihood_arg(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Returns the *argument* of the max of the likelihood of the data given an input xmin """ likelihoods = discrete_likelihood_vector(data, xmin, alpharange=alpharange, n_alpha=n_alpha) Largmax = numpy.argmax(likelihoods) return Largmax
[docs]def discrete_max_likelihood(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Returns the *argument* of the max of the likelihood of the data given an input xmin """ likelihoods = discrete_likelihood_vector(data, xmin, alpharange=alpharange, n_alpha=n_alpha) Lmax = numpy.max(likelihoods) return Lmax
[docs]def most_likely_alpha(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Return the most likely alpha for the data given an xmin """ alpha_vector = numpy.linspace(alpharange[0],alpharange[1],n_alpha) return alpha_vector[discrete_max_likelihood_arg(data, xmin, alpharange=alpharange, n_alpha=n_alpha)]
[docs]def discrete_alpha_mle(data, xmin): """ Equation B.17 of Clauset et al 2009 The Maximum Likelihood Estimator of the "scaling parameter" alpha in the discrete case is similar to that in the continuous case """ # boolean indices of positive data gexmin = (data>=xmin) nn = gexmin.sum() if nn < 2: return 0 xx = data[gexmin] alpha = 1.0 + float(nn) * ( sum(log(xx/(xmin-0.5))) )**-1 return alpha
[docs]def discrete_best_alpha(data, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True): """ Use the maximum L to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function) """ xmins = numpy.unique(data) if approximate: alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] else: alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] alpharanges = [(0.9*a,1.1*a) for a in alpha_approx] alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha) for xmin,ar in zip(xmins,alpharanges) ] ksvalues = [ discrete_ksD(data, xmin, alpha) for xmin,alpha in zip(xmins,alpha_of_xmin) ] best_index = argmin(ksvalues) best_alpha = alpha_of_xmin[best_index] best_xmin = xmins[best_index] best_ks = ksvalues[best_index] best_likelihood = discrete_likelihood(data, best_xmin, best_alpha) if verbose: print "alpha = %f xmin = %f ksD = %f L = %f (n<x) = %i (n>=x) = %i" % ( best_alpha, best_xmin, best_ks, best_likelihood, (data<best_xmin).sum(), (data>=best_xmin).sum()) return best_alpha,best_xmin,best_ks,best_likelihood
[docs]def discrete_ksD(data, xmin, alpha): """ given a sorted data set, a minimum, and an alpha, returns the power law ks-test D value w/data The returned value is the "D" parameter in the ks test (this is implemented differently from the continuous version because there are potentially multiple identical points that need comparison to the power law) """ zz = numpy.sort(data[data>=xmin]) nn = float(len(zz)) if nn < 2: return numpy.inf #cx = numpy.arange(nn,dtype='float')/float(nn) #cf = 1.0-(zz/xmin)**(1.0-alpha) model_cdf = 1.0-(zz/xmin)**(1.0-alpha) data_cdf = numpy.searchsorted(zz,zz,side='left')/(float(nn)) ks = max(abs(model_cdf-data_cdf)) return ks
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PKdsED?/.)plfit-latest/_modules/plfit/plfit_py.html plfit.plfit_py — plfit 1.0 documentation

Source code for plfit.plfit_py

# intended to implement a power-law fitting routine as specified in.....
# http://www.santafe.edu/~aaronc/powerlaws/
#
# The MLE for the power-law alpha is very easy to derive given knowledge
# of the lowest value at which a power law holds, but that point is 
# difficult to derive and must be acquired iteratively.

"""
Pure-Python version of plfit.py
===============================

A *pure* python power-law distribution fitter based on code by Aaron Clauset.
This is the slowest implementation, but has no dependencies.

Example very simple use::

    from plfit_py import plfit

    MyPL = plfit(mydata)
    MyPL.plotpdf(log=True)

"""

import time
import random
import math

[docs]class plfit: """ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/ See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062 The output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}` """ def __init__(self,x,**kwargs): """ Initializes and fits the power law. Can pass "quiet" to turn off output (except for warnings; "silent" turns off warnings) """ neg = [i<0 for i in x] if any(neg) > 0: print "Removed %i negative points" % (sum(neg)) x = [i for i in x if i > 0] self.data = x self.plfit(**kwargs)
[docs] def alpha_(self,x): """ Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.""" def alpha(xmin,x=x): """ given a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized """ x = [i for i in x if i>=xmin] n = sum(x) divsum = sum([math.log(i/xmin) for i in x]) if divsum == 0: return float('inf') # the "1+" here is unimportant because alpha_ is only used for minimization a = 1 + float(n) / divsum return a return alpha
[docs] def kstest_(self,x): def kstest(xmin,x=x): """ given a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test... """ x = [i for i in x if i>=xmin] n = len(x) if n == 0: return float('inf') divsum = sum([math.log(i/xmin) for i in x]) if divsum == 0: return float('inf') a = float(n) / divsum cx = [float(i)/float(n) for i in xrange(int(n))] cf = [1-(xmin/i)**a for i in x] ks = max([abs(a-b) for a,b in zip(cf,cx)]) return ks return kstest
[docs] def plfit(self,nosmall=True,finite=False,quiet=False,silent=False, xmin=None, verbose=False): """ A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/ See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062 nosmall is on by default; it rejects low s/n points can specify xmin to skip xmin estimation This is only for continuous distributions; I have not implemented a pure-python discrete distribution fitter """ x = self.data z = sorted(x) t = time.time() possible_xmins = sorted(set(z)) argxmins = [z.index(i) for i in possible_xmins] self._nunique = len(possible_xmins) if xmin is None: av = map(self.alpha_(z),possible_xmins) dat = map(self.kstest_(z),possible_xmins) sigma = [(a-1)/math.sqrt(len(z)-i+1) for a,i in zip(av,argxmins)] if nosmall: # test to make sure the number of data points is high enough # to provide a reasonable s/n on the computed alpha goodvals = [s<0.1 for s in sigma] if False in goodvals: nmax = goodvals.index(False) dat = dat[:nmax] possible_xmins = possible_xmins[:nmax] av = av[:nmax] else: print "Not enough data left after flagging - using all positive data." if not quiet: print "PYTHON plfit executed in %f seconds" % (time.time()-t) self._av = av self._xmin_kstest = dat self._sigma = sigma # [:-1] to weed out the very last data point; it cannot be correct # (can't have a power law with 1 data point). # However, this should only be done if the ends have not previously # been excluded with nosmall if nosmall: xmin = possible_xmins[dat.index(min(dat))] else: xmin = possible_xmins[dat.index(min(dat[:-1]))] z = [i for i in z if i >= xmin] n = len(z) alpha = 1 + n / sum([math.log(a/xmin) for a in z]) if finite: alpha = alpha*(n-1.)/n+1./n if n == 1 and not silent: print "Failure: only 1 point kept. Probably not a power-law distribution." self._alpha = 0 self._alphaerr = 0 self._likelihood = 0 self._ks = 0 self._ks_prob = 0 self._xmin = xmin return xmin,0 if n < 50 and not finite and not silent: print '(PLFIT) Warning: finite-size bias may be present. n=%i' % n # ks = max(abs( numpy.arange(n)/float(n) - (1-(xmin/z)**(alpha-1)) )) ks = max( [abs( i/float(n) - (1-(xmin/b)**(alpha-1))) for i,b in zip(xrange(n),z)] ) # Parallels Eqn 3.5 in Clauset et al 2009, but zeta(alpha, xmin) = (alpha-1)/xmin. Really is Eqn B3 in paper. #L = n*log((alpha-1)/xmin) - alpha*sum(log(z/xmin)) sl = sum([math.log(a/xmin) for a in z]) L = (n*math.log((alpha-1)/xmin) - alpha*sl) #requires another map... Larr = arange(len(unique(x))) * log((av-1)/unique(x)) - av*sum self._likelihood = L self._xmin = xmin self._xmins = possible_xmins self._alpha= alpha self._alphaerr = (alpha-1)/math.sqrt(n) self._ks = ks # this ks statistic may not have the same value as min(dat) because of unique() #if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(ks*numpy.sqrt(n)) self._ngtx = n if math.isnan(L) or math.isnan(xmin) or math.isnan(alpha): raise ValueError("plfit failed; returned a nan") if not quiet: if verbose: print "The lowest value included in the power-law fit, ", print "xmin: %g" % xmin, if verbose: print "\nThe number of values above xmin, ", print "n(>xmin): %i" % n, if verbose: print "\nThe derived power-law alpha (p(x)~x^-alpha) with MLE-derived error, ", print "alpha: %g +/- %g " % (alpha,self._alphaerr), if verbose: print "\nThe log of the Likelihood (the maximized parameter), ", print "Log-Likelihood: %g " % L, if verbose: print "\nThe KS-test statistic between the best-fit power-law and the data, ", print "ks: %g" % (ks) return xmin,alpha
[docs]def plexp(x,xm=1,a=2.5): """ CDF(x) for the piecewise distribution exponential x<xmin, powerlaw x>=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + math.exp(a)*xm/a) Ppl = lambda(X): 1+C*(xm/(1-a)*(X/xm)**(1-a)) Pexp = lambda(X): C*xm/a*math.exp(a)-C*(xm/a)*math.exp(-a*(X/xm-1)) d=Ppl(x) d[x<xm]=Pexp(x) return d
[docs]def plexp_inv(P,xm,a): """ Inverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + math.exp(a)*xm/a) Pxm = 1+C*(xm/(1-a)) pp = P x = xm*(pp-1)*(1-a)/(C*xm)**(1/(1-a)) if pp >= Pxm else (math.log( ((C*xm/a)*math.exp(a)-pp)/(C*xm/a)) - a) * (-xm/a) #x[P>=Pxm] = xm*( (P[P>=Pxm]-1) * (1-a)/(C*xm) )**(1/(1-a)) # powerlaw #x[P<Pxm] = (math.log( (C*xm/a*math.exp(a)-P[P<Pxm])/(C*xm/a) ) - a) * (-xm/a) # exp return x
[docs]def pl_inv(P,xm,a): """ Inverse CDF for a pure power-law """ x = (1-P)**(1/(1-a)) * xm return x
[docs]def test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=plexp_inv, quiet=True, silent=True): """ Tests the power-law fitter Examples ======== Example (fig 3.4b in Clauset et al.):: xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x') Example 2:: xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x') Example 3:: xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alpha Example 4:: xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07 """ sz = niter xmarr,alphaf_v,ksv,nxarr = ([0]*sz,)*4 for i in xrange(niter): randarr = [random.random() for k in xrange(npts)] fakedata = [invcdf(r,xmin,alpha) for r in randarr] TEST = plfit(fakedata,quiet=quiet,silent=silent,nosmall=True) alphaf_v[i] = TEST._alpha ksv[i] = TEST._ks nxarr[i] = TEST._ngtx xmarr[i] = TEST._xmin return xmarr,alphaf_v,ksv,nxarr
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
PK:~6CK  Fplfit-latest/_images/math/7a288cbb1905c82ff9b1e3d10170c388968e1046.pngPNG  IHDR0PLTEbbbttt@@@涶PPP000""" 8FIDAT8˭UMhAd7i͡i-z)(!,EzݢH% jT/ (" C= "۝Mv]ff,M[߷΢wS8\P/fwgReW,Z*x$k"_GKהK_ wkb.7^ kqk{n ydQljF\GL'̥\Zů:υQϨ }>pD&6~-fg_QBjtSB u*ZG" Iy/>g7hg՚ĸmIzMb㤝3\9S䱄0UFX ;,>O 8 Eh2I<$<7h=fl 9nXXoԑ(|7Htؔ, O Iw3cL1c+pVSaTv'r*gIcRAm -UfT/NMID[snmőayj s,bt,8tg,#ci D5+qBJZrRaA<&KA?CG.M^ak{i!ۖ5z~:!ɯIENDB`PKcsED ff)plfit-latest/.doctrees/environment.pickle(csphinx.environment BuildEnvironment qoq}q(Udlfilesqcsphinx.util FilenameUniqDict q)qc__builtin__ set q]RqbUintersphinx_named_inventoryq }Uappq NU _warnfuncq NUtitlesq }q (Xindexqcdocutils.nodes title q)q}q(U rawsourceqUU attributesq}q(Udupnamesq]Uclassesq]Ubackrefsq]Uidsq]Unamesq]uUchildrenq]qcdocutils.nodes Text qXPower-law Distribution Fittingqq}q(hXPower-law Distribution Fittingq Uparentq!hubaUtagnameq"Utitleq#ubXapidocq$h)q%}q&(hUh}q'(h]h]h]h]h]uh]q(hXAPI Documentationq)q*}q+(hXAPI Documentationq,h!h%ubah"h#ubXmodulesq-h)q.}q/(hUh}q0(h]h]h]h]h]uh]q1hX.q2}q3(hX.h!h.ubah"h#ubuU domaindataq4}q5(Ustdq6}q7(Uversionq8KU anonlabelsq9}q:(Umodindexq;U py-modindexUUgenindexq}q?(h;U py-modindexUcsphinx.locale _TranslationProxy q@csphinx.locale mygettext qAU Module IndexqBqChAhBqDbh 0: print "Removed %i negative points" % (sum(neg)) x = [i for i in x if i > 0] self.data = x self.plfit(**kwargs) def alpha_(self,x): """ Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.""" def alpha(xmin,x=x): """ given a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized """ x = [i for i in x if i>=xmin] n = sum(x) divsum = sum([math.log(i/xmin) for i in x]) if divsum == 0: return float('inf') # the "1+" here is unimportant because alpha_ is only used for minimization a = 1 + float(n) / divsum return a return alpha def kstest_(self,x): def kstest(xmin,x=x): """ given a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test... """ x = [i for i in x if i>=xmin] n = len(x) if n == 0: return float('inf') divsum = sum([math.log(i/xmin) for i in x]) if divsum == 0: return float('inf') a = float(n) / divsum cx = [float(i)/float(n) for i in xrange(int(n))] cf = [1-(xmin/i)**a for i in x] ks = max([abs(a-b) for a,b in zip(cf,cx)]) return ks return kstest def plfit(self,nosmall=True,finite=False,quiet=False,silent=False, xmin=None, verbose=False): """ A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/ See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062 nosmall is on by default; it rejects low s/n points can specify xmin to skip xmin estimation This is only for continuous distributions; I have not implemented a pure-python discrete distribution fitter """ x = self.data z = sorted(x) t = time.time() possible_xmins = sorted(set(z)) argxmins = [z.index(i) for i in possible_xmins] self._nunique = len(possible_xmins) if xmin is None: av = map(self.alpha_(z),possible_xmins) dat = map(self.kstest_(z),possible_xmins) sigma = [(a-1)/math.sqrt(len(z)-i+1) for a,i in zip(av,argxmins)] if nosmall: # test to make sure the number of data points is high enough # to provide a reasonable s/n on the computed alpha goodvals = [s<0.1 for s in sigma] if False in goodvals: nmax = goodvals.index(False) dat = dat[:nmax] possible_xmins = possible_xmins[:nmax] av = av[:nmax] else: print "Not enough data left after flagging - using all positive data." if not quiet: print "PYTHON plfit executed in %f seconds" % (time.time()-t) self._av = av self._xmin_kstest = dat self._sigma = sigma # [:-1] to weed out the very last data point; it cannot be correct # (can't have a power law with 1 data point). # However, this should only be done if the ends have not previously # been excluded with nosmall if nosmall: xmin = possible_xmins[dat.index(min(dat))] else: xmin = possible_xmins[dat.index(min(dat[:-1]))] z = [i for i in z if i >= xmin] n = len(z) alpha = 1 + n / sum([math.log(a/xmin) for a in z]) if finite: alpha = alpha*(n-1.)/n+1./n if n == 1 and not silent: print "Failure: only 1 point kept. Probably not a power-law distribution." self._alpha = 0 self._alphaerr = 0 self._likelihood = 0 self._ks = 0 self._ks_prob = 0 self._xmin = xmin return xmin,0 if n < 50 and not finite and not silent: print '(PLFIT) Warning: finite-size bias may be present. n=%i' % n # ks = max(abs( numpy.arange(n)/float(n) - (1-(xmin/z)**(alpha-1)) )) ks = max( [abs( i/float(n) - (1-(xmin/b)**(alpha-1))) for i,b in zip(xrange(n),z)] ) # Parallels Eqn 3.5 in Clauset et al 2009, but zeta(alpha, xmin) = (alpha-1)/xmin. Really is Eqn B3 in paper. #L = n*log((alpha-1)/xmin) - alpha*sum(log(z/xmin)) sl = sum([math.log(a/xmin) for a in z]) L = (n*math.log((alpha-1)/xmin) - alpha*sl) #requires another map... Larr = arange(len(unique(x))) * log((av-1)/unique(x)) - av*sum self._likelihood = L self._xmin = xmin self._xmins = possible_xmins self._alpha= alpha self._alphaerr = (alpha-1)/math.sqrt(n) self._ks = ks # this ks statistic may not have the same value as min(dat) because of unique() #if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(ks*numpy.sqrt(n)) self._ngtx = n if math.isnan(L) or math.isnan(xmin) or math.isnan(alpha): raise ValueError("plfit failed; returned a nan") if not quiet: if verbose: print "The lowest value included in the power-law fit, ", print "xmin: %g" % xmin, if verbose: print "\nThe number of values above xmin, ", print "n(>xmin): %i" % n, if verbose: print "\nThe derived power-law alpha (p(x)~x^-alpha) with MLE-derived error, ", print "alpha: %g +/- %g " % (alpha,self._alphaerr), if verbose: print "\nThe log of the Likelihood (the maximized parameter), ", print "Log-Likelihood: %g " % L, if verbose: print "\nThe KS-test statistic between the best-fit power-law and the data, ", print "ks: %g" % (ks) return xmin,alpha def plexp(x,xm=1,a=2.5): """ CDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + math.exp(a)*xm/a) Ppl = lambda(X): 1+C*(xm/(1-a)*(X/xm)**(1-a)) Pexp = lambda(X): C*xm/a*math.exp(a)-C*(xm/a)*math.exp(-a*(X/xm-1)) d=Ppl(x) d[x= Pxm else (math.log( ((C*xm/a)*math.exp(a)-pp)/(C*xm/a)) - a) * (-xm/a) #x[P>=Pxm] = xm*( (P[P>=Pxm]-1) * (1-a)/(C*xm) )**(1/(1-a)) # powerlaw #x[P`_ The output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}` """ def __init__(self,x,**kwargs): """ Initializes and fits the power law. Can pass "quiet" to turn off output (except for warnings; "silent" turns off warnings) """ x = numpy.array(x) # make sure x is an array, otherwise the next step fails if (x<0).sum() > 0: print "Removed %i negative points" % ((x<0).sum()) x = x[x>0] self.data = x self.plfit(**kwargs) def alpha_(self,x): """ Create a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users. Docstring for the generated alpha function:: Given a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized If there is only one element, return alpha=0 """ def alpha(xmin,x=x): gexmin = x>=xmin n = gexmin.sum() if n < 2: return 0 x = x[gexmin] a = 1 + float(n) / sum(log(x/xmin)) return a return alpha def kstest_(self,x): """ Create a mappable function kstest to apply to each xmin in a list of xmins. Docstring for the generated kstest function:: Given a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test. """ def kstest(xmin,x=x): x = x[x>=xmin] n = float(len(x)) if n == 0: return numpy.inf a = float(n) / sum(log(x/xmin)) cx = numpy.arange(n,dtype='float')/float(n) cf = 1-(xmin/x)**a ks = max(abs(cf-cx)) return ks return kstest def plfit(self, nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000): """ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/ See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062 There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython) version is ~10% slower, and the python version is ~3x slower than the fortran version. Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknown reasons. There is also a discrete version implemented in python - it is different from the continous version! *discrete* [ bool | None ] If *discrete* is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If *discrete* is True or False, the distcrete or continuous fitter will be used, respectively. *xmin* [ float / int ] If you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha. *nosmall* [ bool (True) ] When on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the "powerlaw" python package *finite* [ bool (False) ] There is a 'finite-size bias' to the estimator. The "alpha" the code measures is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / n *quiet* [ bool (False) ] If False, delivers messages about what fitter is used and the fit results *verbose* [ bool (False) ] Deliver descriptive messages about the fit parameters (only if *quiet*==False) *silent* [ bool (False) ] If True, will print NO messages """ x = self.data z = numpy.sort(x) t = time.time() xmins,argxmins = numpy.unique(z,return_index=True)#[:-1] self._nunique = len(xmins) if self._nunique == len(x) and discrete is None: if verbose: print "Using CONTINUOUS fitter" discrete = False elif self._nunique < len(x) and discrete is None: if verbose: print "Using DISCRETE fitter" discrete = True t = time.time() if xmin is None: if discrete: self.discrete_best_alpha(approximate=discrete_approx, n_alpha=discrete_n_alpha, verbose=verbose, finite=finite) return self._xmin,self._alpha elif usefortran and fortranOK: dat,av = fplfit.plfit(z,int(nosmall)) goodvals=dat>0 sigma = ((av-1)/numpy.sqrt(len(z)-numpy.arange(len(z))))[argxmins] dat = dat[goodvals] av = av[goodvals] if nosmall: # data, av a;ready treated for this. sigma, xmins not nmax = argmin(sigma<0.1) xmins = xmins[:nmax] sigma = sigma[:nmax] if not quiet: print "FORTRAN plfit executed in %f seconds" % (time.time()-t) elif usecy and cyOK: dat,av = cplfit.plfit_loop(z,nosmall=nosmall,zunique=xmins,argunique=argxmins) goodvals=dat>0 sigma = (av-1)/numpy.sqrt(len(z)-argxmins+1) dat = dat[goodvals] av = av[goodvals] if not quiet: print "CYTHON plfit executed in %f seconds" % (time.time()-t) else: av = numpy.asarray( map(self.alpha_(z),xmins) ,dtype='float') dat = numpy.asarray( map(self.kstest_(z),xmins),dtype='float') sigma = (av-1)/numpy.sqrt(len(z)-argxmins+1) if nosmall: # test to make sure the number of data points is high enough # to provide a reasonable s/n on the computed alpha goodvals = sigma<0.1 nmax = argmin(goodvals) if nmax > 0: dat = dat[:nmax] xmins = xmins[:nmax] av = av[:nmax] sigma = sigma[:nmax] else: if not silent: print "Not enough data left after flagging - using all positive data." if not quiet: print "PYTHON plfit executed in %f seconds" % (time.time()-t) if usefortran: print "fortran fplfit did not load" if usecy: print "cython cplfit did not load" self._av = av self._xmin_kstest = dat self._sigma = sigma # [:-1] to weed out the very last data point; it cannot be correct # (can't have a power law with 1 data point). # However, this should only be done if the ends have not previously # been excluded with nosmall if nosmall: xmin = xmins[argmin(dat)] else: xmin = xmins[argmin(dat[:-1])] z = z[z>=xmin] n = len(z) alpha = 1 + n / sum(log(z/xmin)) if finite: alpha = alpha*(n-1.)/n+1./n if n < 50 and not finite and not silent: print '(PLFIT) Warning: finite-size bias may be present. n=%i' % n ks = max(abs( numpy.arange(n)/float(n) - (1-(xmin/z)**(alpha-1)) )) # Parallels Eqn 3.5 in Clauset et al 2009, but zeta(alpha, xmin) = (alpha-1)/xmin. Really is Eqn B3 in paper. L = n*log((alpha-1)/xmin) - alpha*sum(log(z/xmin)) #requires another map... Larr = arange(len(unique(x))) * log((av-1)/unique(x)) - av*sum self._likelihood = L self._xmin = xmin self._xmins = xmins self._alpha= alpha self._alphaerr = (alpha-1)/numpy.sqrt(n) self._ks = ks # this ks statistic may not have the same value as min(dat) because of unique() if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(ks*numpy.sqrt(n)) self._ngtx = n if n == 1: if not silent: print "Failure: only 1 point kept. Probably not a power-law distribution." self._alpha = alpha = 0 self._alphaerr = 0 self._likelihood = L = 0 self._ks = 0 self._ks_prob = 0 self._xmin = xmin return xmin,0 if numpy.isnan(L) or numpy.isnan(xmin) or numpy.isnan(alpha): raise ValueError("plfit failed; returned a nan") if not quiet: if verbose: print "The lowest value included in the power-law fit, ", print "xmin: %g" % xmin, if verbose: print "\nThe number of values above xmin, ", print "n(>xmin): %i" % n, if verbose: print "\nThe derived power-law alpha (p(x)~x^-alpha) with MLE-derived error, ", print "alpha: %g +/- %g " % (alpha,self._alphaerr), if verbose: print "\nThe log of the Likelihood (the maximized parameter; you minimized the negative log likelihood), ", print "Log-Likelihood: %g " % L, if verbose: print "\nThe KS-test statistic between the best-fit power-law and the data, ", print "ks: %g" % (ks), if scipyOK: if verbose: print " occurs with probability ", print "p(ks): %g" % (self._ks_prob) else: print return xmin,alpha def discrete_best_alpha(self, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True, finite=True): """ Use the maximum L to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function) *n_alpha* [ int ] Number of alpha values to use when measuring. Larger number is more accurate. *approximate* [ bool ] If False, try to "zoom-in" around the MLE alpha and get the exact best alpha value within some range around the approximate best *vebose* [ bool ] *finite* [ bool ] Correction for finite data? """ data = self.data self._xmins = xmins = numpy.unique(data) if approximate: alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] else: alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] alpharanges = [(0.9*a,1.1*a) for a in alpha_approx] alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha) for xmin,ar in zip(xmins,alpharanges) ] ksvalues = numpy.array([ discrete_ksD(data, xmin, alpha) for xmin,alpha in zip(xmins,alpha_of_xmin) ]) self._av = numpy.array(alpha_of_xmin) self._xmin_kstest = ksvalues ksvalues[numpy.isnan(ksvalues)] = numpy.inf best_index = argmin(ksvalues) self._alpha = best_alpha = alpha_of_xmin[best_index] self._xmin = best_xmin = xmins[best_index] self._ks = best_ks = ksvalues[best_index] self._likelihood = best_likelihood = discrete_likelihood(data, best_xmin, best_alpha) if finite: self._alpha = self._alpha*(n-1.)/n+1./n if verbose: print "alpha = %f xmin = %f ksD = %f L = %f (n=x) = %i" % ( best_alpha, best_xmin, best_ks, best_likelihood, (data=best_xmin).sum()) self._ngtx = n = (self.data>=self._xmin).sum() self._alphaerr = (self._alpha-1.0)/numpy.sqrt(n) if scipyOK: self._ks_prob = scipy.stats.kstwobign.sf(self._ks*numpy.sqrt(n)) return best_alpha,best_xmin,best_ks,best_likelihood def xminvsks(self, **kwargs): """ Plot xmin versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function. """ pylab.plot(self._xmins,self._xmin_kstest,'.') pylab.plot(self._xmin,self._ks,'s') #pylab.errorbar([self._ks],self._alpha,yerr=self._alphaerr,fmt='+') ax=pylab.gca() ax.set_ylabel("KS statistic") ax.set_xlabel("min(x)") pylab.draw() return ax def alphavsks(self,autozoom=True,**kwargs): """ Plot alpha versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function. """ pylab.plot(1+self._av,self._xmin_kstest,'.') pylab.errorbar(self._alpha,[self._ks],xerr=self._alphaerr,fmt='+') ax=pylab.gca() if autozoom: ax.set_ylim(0.8*(self._ks),3*(self._ks)) ax.set_xlim((self._alpha)-5*self._alphaerr,(self._alpha)+5*self._alphaerr) ax.set_ylabel("KS statistic") ax.set_xlabel(r'$\alpha$') pylab.draw() return ax def plotcdf(self, x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs): """ Plots CDF and powerlaw """ if x is None: x=self.data if xmin is None: xmin=self._xmin if alpha is None: alpha=self._alpha x=numpy.sort(x) n=len(x) xcdf = numpy.arange(n,0,-1,dtype='float')/float(n) q = x[x>=xmin] fcdf = (q/xmin)**(1-alpha) nc = xcdf[argmax(x>=xmin)] fcdf_norm = nc*fcdf D_location = argmax(xcdf[x>=xmin]-fcdf_norm) pylab.vlines(q[D_location],xcdf[x>=xmin][D_location],fcdf_norm[D_location],color='m',linewidth=2) #plotx = pylab.linspace(q.min(),q.max(),1000) #ploty = (plotx/xmin)**(1-alpha) * nc pylab.loglog(x,xcdf,marker=pointmarker,color=pointcolor,**kwargs) #pylab.loglog(plotx,ploty,'r',**kwargs) pylab.loglog(q,fcdf_norm,'r',**kwargs) def plotpdf(self,x=None,xmin=None,alpha=None,nbins=50,dolog=True,dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs): """ Plots PDF and powerlaw. kwargs is passed to pylab.hist and pylab.plot """ if not(x): x=self.data if not(xmin): xmin=self._xmin if not(alpha): alpha=self._alpha x=numpy.sort(x) n=len(x) pylab.gca().set_xscale('log') pylab.gca().set_yscale('log') if dnds: hb = pylab.histogram(x,bins=numpy.logspace(log10(min(x)),log10(max(x)),nbins)) h = hb[0] b = hb[1] db = hb[1][1:]-hb[1][:-1] h = h/db pylab.plot(b[:-1],h,drawstyle=drawstyle,color=histcolor,**kwargs) #alpha -= 1 elif dolog: hb = pylab.hist(x,bins=numpy.logspace(log10(min(x)),log10(max(x)),nbins),log=True,fill=False,edgecolor=histcolor,**kwargs) alpha -= 1 h,b=hb[0],hb[1] else: hb = pylab.hist(x,bins=numpy.linspace((min(x)),(max(x)),nbins),fill=False,edgecolor=histcolor,**kwargs) h,b=hb[0],hb[1] # plotting points are at the center of each bin b = (b[1:]+b[:-1])/2.0 q = x[x>=xmin] px = (alpha-1)/xmin * (q/xmin)**(-alpha) # Normalize by the median ratio between the histogram and the power-law # The normalization is semi-arbitrary; an average is probably just as valid plotloc = (b>xmin)*(h>0) norm = numpy.median( h[plotloc] / ((alpha-1)/xmin * (b[plotloc]/xmin)**(-alpha)) ) px = px*norm plotx = pylab.linspace(q.min(),q.max(),1000) ploty = (alpha-1)/xmin * (plotx/xmin)**(-alpha) * norm #pylab.loglog(q,px,'r',**kwargs) pylab.loglog(plotx,ploty,color=plcolor,**kwargs) axlims = pylab.axis() pylab.vlines(xmin,axlims[2],max(px),colors=plcolor,linestyle='dashed') pylab.gca().set_xlim(min(x),max(x)) def plotppf(self,x=None,xmin=None,alpha=None,dolog=True,**kwargs): """ Plots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality. """ if not(xmin): xmin=self._xmin if not(alpha): alpha=self._alpha if not(x): x=numpy.sort(self.data[self.data>xmin]) else: x=numpy.sort(x[x>xmin]) # N = M^(-alpha+1) # M = N^(1/(-alpha+1)) m0 = min(x) N = (1.0+numpy.arange(len(x)))[::-1] xmodel = m0 * N**(1/(1-alpha)) / max(N)**(1/(1-alpha)) if dolog: pylab.loglog(x,xmodel,'.',**kwargs) pylab.gca().set_xlim(min(x),max(x)) pylab.gca().set_ylim(min(x),max(x)) else: pylab.plot(x,xmodel,'.',**kwargs) pylab.plot([min(x),max(x)],[min(x),max(x)],'k--') pylab.xlabel("Real Value") pylab.ylabel("Power-Law Model Value") def test_pl(self,niter=1e3, print_timing=False, **kwargs): """ Monte-Carlo test to determine whether distribution is consistent with a power law Runs through niter iterations of a sample size identical to the input sample size. Will randomly select values from the data < xmin. The number of values selected will be chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential, and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL. For more details, see figure 4.1 and section **WARNING** This can take a very long time to run! Execution time scales as niter * setsize """ xmin = self._xmin alpha = self._alpha niter = int(niter) ntail = sum(self.data >= xmin) ntot = len(self.data) nnot = ntot-ntail # n(self._ks).sum() / float(niter) self._pval = p self._ks_rand = ksv print "p(%i) = %0.3f" % (niter,p) if print_timing: print "Iteration timing: %g +/- %g" % (numpy.mean(deltat),numpy.std(deltat)) return p,ksv def lognormal(self,doprint=True): """ Use the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parameters """ # N = float(self.data.shape[0]) # mu = log(self.data).sum() / N # sigmasquared = ( ( log(self.data) - mu )**2 ).sum() / N # self.lognormal_mu = mu # self.lognormal_sigma = numpy.sqrt(sigmasquared) # self.lognormal_likelihood = -N/2. * log(numpy.pi*2) - N/2. * log(sigmasquared) - 1/(2*sigmasquared) * (( self.data - mu )**2).sum() # if doprint: # print "Best fit lognormal is exp( -(x-%g)^2 / (2*%g^2)" % (mu,numpy.sqrt(sigmasquared)) # print "Likelihood: %g" % (self.lognormal_likelihood) if scipyOK: fitpars = scipy.stats.lognorm.fit(self.data) self.lognormal_dist = scipy.stats.lognorm(*fitpars) self.lognormal_ksD,self.lognormal_ksP = scipy.stats.kstest(self.data,self.lognormal_dist.cdf) # nnlf = NEGATIVE log likelihood self.lognormal_likelihood = -1*scipy.stats.lognorm.nnlf(fitpars,self.data) # Is this the right likelihood ratio? # Definition of L from eqn. B3 of Clauset et al 2009: # L = log(p(x|alpha)) # _nnlf from scipy.stats.distributions: # -sum(log(self._pdf(x, *args)),axis=0) # Assuming the pdf and p(x|alpha) are both non-inverted, it looks # like the _nnlf and L have opposite signs, which would explain the # likelihood ratio I've used here: self.power_lognorm_likelihood = (self._likelihood + self.lognormal_likelihood) # a previous version had 2*(above). That is the correct form if you want the likelihood ratio # statistic "D": http://en.wikipedia.org/wiki/Likelihood-ratio_test # The above explanation makes sense, since nnlf is the *negative* log likelihood function: ## nnlf -- negative log likelihood function (to minimize) # # Assuming we want the ratio between the POSITIVE likelihoods, the D statistic is: # D = -2 log( L_power / L_lognormal ) self.likelihood_ratio_D = -2 * (log(self._likelihood/self.lognormal_likelihood)) if doprint: print "Lognormal KS D: %g p(D): %g" % (self.lognormal_ksD,self.lognormal_ksP), print " Likelihood Ratio Statistic (powerlaw/lognormal): %g" % self.likelihood_ratio_D print "At this point, have a look at Clauset et al 2009 Appendix C: determining sigma(likelihood_ratio)" def plot_lognormal_pdf(self,**kwargs): """ Plot the fitted lognormal distribution """ if not hasattr(self,'lognormal_dist'): return normalized_pdf = self.lognormal_dist.pdf(self.data)/self.lognormal_dist.pdf(self.data).max() minY,maxY = pylab.gca().get_ylim() pylab.plot(self.data,normalized_pdf*maxY,'.',**kwargs) def plot_lognormal_cdf(self,**kwargs): """ Plot the fitted lognormal distribution """ if not hasattr(self,'lognormal_dist'): return x=numpy.sort(self.data) n=len(x) xcdf = numpy.arange(n,0,-1,dtype='float')/float(n) lcdf = self.lognormal_dist.sf(x) D_location = argmax(xcdf-lcdf) pylab.vlines(x[D_location],xcdf[D_location],lcdf[D_location],color='m',linewidth=2) pylab.plot(x, lcdf,',',**kwargs) def plfit_lsq(x,y): """ Returns A and B in y=Ax^B http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html """ n = len(x) btop = n * (log(x)*log(y)).sum() - (log(x)).sum()*(log(y)).sum() bbottom = n*(log(x)**2).sum() - (log(x).sum())**2 b = btop / bbottom a = ( log(y).sum() - b * log(x).sum() ) / n A = exp(a) return A,b def plexp(x,xm=1,a=2.5): """ CDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al. """ C = 1/(-xm/(1 - a) - xm/a + exp(a)*xm/a) Ppl = lambda(X): 1+C*(xm/(1-a)*(X/xm)**(1-a)) Pexp = lambda(X): C*xm/a*exp(a)-C*(xm/a)*exp(-a*(X/xm-1)) d=Ppl(x) d[x=Pxm] = xm*( (P[P>=Pxm]-1) * (1-a)/(C*xm) )**(1/(1-a)) # powerlaw x[P=xmin] nn = len(zz) sum_log_data = numpy.log(zz).sum() zeta = zeta(alpha, xmin) L_of_alpha = -1*nn*log(zeta) - alpha * sum_log_data return L_of_alpha def discrete_likelihood_vector(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Compute the likelihood for all "scaling parameters" in the range (alpharange) for a given xmin. This is only part of the discrete value likelihood maximization problem as described in Clauset et al (Equation B.8) *alpharange* [ 2-tuple ] Two floats specifying the upper and lower limits of the power law alpha to test """ from scipy.special import zeta as zeta zz = data[data>=xmin] nn = len(zz) alpha_vector = numpy.linspace(alpharange[0],alpharange[1],n_alpha) sum_log_data = numpy.log(zz).sum() # alpha_vector is a vector, xmin is a scalar zeta_vector = zeta(alpha_vector, xmin) #xminvec = numpy.arange(1.0,xmin) #xminalphasum = numpy.sum([xm**(-alpha_vector) for xm in xminvec]) #L = -1*alpha_vector*sum_log_data - nn*log(zeta_vector) - xminalphasum L_of_alpha = -1*nn*log(zeta_vector) - alpha_vector * sum_log_data return L_of_alpha def discrete_max_likelihood_arg(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Returns the *argument* of the max of the likelihood of the data given an input xmin """ likelihoods = discrete_likelihood_vector(data, xmin, alpharange=alpharange, n_alpha=n_alpha) Largmax = numpy.argmax(likelihoods) return Largmax def discrete_max_likelihood(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Returns the *argument* of the max of the likelihood of the data given an input xmin """ likelihoods = discrete_likelihood_vector(data, xmin, alpharange=alpharange, n_alpha=n_alpha) Lmax = numpy.max(likelihoods) return Lmax def most_likely_alpha(data, xmin, alpharange=(1.5,3.5), n_alpha=201): """ Return the most likely alpha for the data given an xmin """ alpha_vector = numpy.linspace(alpharange[0],alpharange[1],n_alpha) return alpha_vector[discrete_max_likelihood_arg(data, xmin, alpharange=alpharange, n_alpha=n_alpha)] def discrete_alpha_mle(data, xmin): """ Equation B.17 of Clauset et al 2009 The Maximum Likelihood Estimator of the "scaling parameter" alpha in the discrete case is similar to that in the continuous case """ # boolean indices of positive data gexmin = (data>=xmin) nn = gexmin.sum() if nn < 2: return 0 xx = data[gexmin] alpha = 1.0 + float(nn) * ( sum(log(xx/(xmin-0.5))) )**-1 return alpha def discrete_best_alpha(data, alpharangemults=(0.9,1.1), n_alpha=201, approximate=True, verbose=True): """ Use the maximum L to determine the most likely value of alpha *alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function) """ xmins = numpy.unique(data) if approximate: alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] else: alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ] alpharanges = [(0.9*a,1.1*a) for a in alpha_approx] alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha) for xmin,ar in zip(xmins,alpharanges) ] ksvalues = [ discrete_ksD(data, xmin, alpha) for xmin,alpha in zip(xmins,alpha_of_xmin) ] best_index = argmin(ksvalues) best_alpha = alpha_of_xmin[best_index] best_xmin = xmins[best_index] best_ks = ksvalues[best_index] best_likelihood = discrete_likelihood(data, best_xmin, best_alpha) if verbose: print "alpha = %f xmin = %f ksD = %f L = %f (n=x) = %i" % ( best_alpha, best_xmin, best_ks, best_likelihood, (data=best_xmin).sum()) return best_alpha,best_xmin,best_ks,best_likelihood def discrete_ksD(data, xmin, alpha): """ given a sorted data set, a minimum, and an alpha, returns the power law ks-test D value w/data The returned value is the "D" parameter in the ks test (this is implemented differently from the continuous version because there are potentially multiple identical points that need comparison to the power law) """ zz = numpy.sort(data[data>=xmin]) nn = float(len(zz)) if nn < 2: return numpy.inf #cx = numpy.arange(nn,dtype='float')/float(nn) #cf = 1.0-(zz/xmin)**(1.0-alpha) model_cdf = 1.0-(zz/xmin)**(1.0-alpha) data_cdf = numpy.searchsorted(zz,zz,side='left')/(float(nn)) ks = max(abs(model_cdf-data_cdf)) return ks r>}r?(Xdiscrete_alpha_mler@XdefrAM1MAX discrete_ksDrBXdefrCMbMwX plfit.test_plXdefrDMM3Xdiscrete_best_alpharEXdefrFMAMbXplfit.plot_lognormal_cdfXdefrGMjM|X plfit.plotppfXdefrHMMXplfit.xminvsksXdefrIM[MnXdiscrete_likelihood_vectorrJXdefrKMMXplfit.alpha_.alphaXdefrLKXK`X plfit.plotpdfXdefrMMMX test_fitterrNXdefrOMMXplfit.alphavsksXdefrPMnMXdiscrete_max_likelihood_argrQXdefrRMM"X plexp_invrSXdefrTMMXplfit.kstest_.kstestXdefrUKmKvXplfit.lognormalXdefrVM3M_X plfit.kstest_XdefrWKbKyXplfit.plot_lognormal_pdfXdefrXM_MjXplexprYXdefrZMMX plfit.plotcdfXdefr[MMX plfit_lsqr\Xdefr]M|MX plfit.alpha_Xdefr^KLKbXdiscrete_max_likelihoodr_Xdefr`M"M*Xdiscrete_likelihoodraXdefrbMMXplfitrcXclassrdK3M|X plfit.plfitXdefreKyM&Xplfit.__init__XdefrfK?KLXpl_invrgXdefrhMMXmost_likely_alphariXdefrjM*M1Xplfit.discrete_best_alphaXdefrkM&M[u}rl(Xdiscrete_alpha_mlermh$X discrete_ksDrnh$X plfit.test_plroh$Xdiscrete_best_alpharph$Xplfit.plot_lognormal_cdfrqh$X plfit.plotppfrrh$Xplfit.xminvsksrsh$Xdiscrete_likelihood_vectorrth$X plfit.plotpdfruh$X test_fitterrvh$Xplfit.alphavsksrwh$Xdiscrete_max_likelihood_argrxh$X plexp_invryh$Xplfit.lognormalrzh$X plfit.kstest_r{h$Xplfit.plot_lognormal_pdfr|h$Xmost_likely_alphar}h$X plfit.plotcdfr~h$X plfit_lsqrh$X plfit.alpha_rh$Xdiscrete_max_likelihoodrh$Xdiscrete_likelihoodrh$Xplfitrh$X plfit.plfitrh$Xpl_invrh$Xplexprh$Xplfit.discrete_best_alpharh$uuUtoc_num_entriesr}r(hKh$Kh-KuUimagesrh)rh]RrbUnumbered_toctreesrh]RrU found_docsrh]r(hh$h-eRrU longtitlesr}r(hhh$h%h-h.uU dependenciesr}rh$h]r(U../plfit/plfit.pyrU../plfit/plfit_py.pyreRrsUtoctree_includesr}r(h]r(XindexrXapidocreh-]r(XindexrXapidocreuU temp_datar}Utocsr}r(hcdocutils.nodes bullet_list r)r}r(hUh}r(h]h]h]h]h]uh]r(cdocutils.nodes list_item r)r}r(hUh}r(h]h]h]h]h]uh!jh]r(csphinx.addnodes compact_paragraph r)r}r(hUh}r(h]h]h]h]h]uh!jh]rcdocutils.nodes reference r)r}r(hUh}r(U anchornameUUrefurihh]h]h]h]h]Uinternaluh!jh]rhXPower-law Distribution Fittingrr}r(hh h!jubah"U referencerubah"Ucompact_paragraphrubj)r}r(hUh}r(h]h]h]h]h]uh!jh]r(j)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r}r(hUh}r(U anchornameU #installationUrefurihh]h]h]h]h]Uinternaluh!jh]rhX Installationrr}r(hX Installationrh!jubah"jubah"jubah"U list_itemrubj)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r}r(hUh}r(U anchornameU #descriptionUrefurihh]h]h]h]h]Uinternaluh!jh]rhX Descriptionrr}r(hX Descriptionrh!jubah"jubah"jubah"jubeh"U bullet_listrubeh"jubj)r}r(hUh}r(h]h]h]h]h]uh!jh]r(j)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r}r(hUh}r(U anchornameU#index-and-table-of-contentsUrefurihh]h]h]h]h]Uinternaluh!jh]rhXIndex and Table of Contentsrr}r(hXIndex and Table of Contentsrh!jubah"jubah"jubj)r}r(hUh}r(h]h]h]h]h]uh!jh]rcsphinx.addnodes toctree r)r}r(hUh}r(UnumberedKUparenthU titlesonlyUglobh]h]h]h]h]Uentries]r(NjrNjreUhiddenUmaxdepthKU includefiles]r(jjeU includehiddenuh!jh]h"Utoctreerubah"jubeh"jubeh"jubh$j)r}r(hUh}r(h]h]h]h]h]uh]rj)r}r(hUh}r(h]h]h]h]h]uh!jh]r(j)r }r (hUh}r (h]h]h]h]h]uh!jh]r j)r }r(hUh}r(U anchornameUUrefurih$h]h]h]h]h]Uinternaluh!j h]rhXAPI Documentationrr}r(hh,h!j ubah"jubah"jubj)r}r(hUh}r(h]h]h]h]h]uh!jh]r(j)r}r(hUh}r(h]h]h]h]h]uh!jh]r(j)r}r(hUh}r(h]h]h]h]h]uh!jh]rj)r }r!(hUh}r"(U anchornameX#module-plfit.plfitUrefurih$h]h]h]h]h]Uinternaluh!jh]r#(cdocutils.nodes literal r$)r%}r&(hXplfith}r'(h]h]h]h]h]uh!j h]r(hXplfitr)r*}r+(hUh!j%ubah"Uliteralr,ubhX Moduler-r.}r/(hX Moduler0h!j ubeh"jubah"jubj)r1}r2(hUh}r3(h]h]h]h]h]uh!jh]r4j)r5}r6(hUh}r7(h]h]h]h]h]uh!j1h]r8j)r9}r:(hUh}r;(h]h]h]h]h]uh!j5h]r<j)r=}r>(hUh}r?(U anchornameU%#numpy-matplotlib-version-of-plfit-pyUrefurih$h]h]h]h]h]Uinternaluh!j9h]r@hX$numpy/matplotlib version of plfit.pyrArB}rC(hX$numpy/matplotlib version of plfit.pyrDh!j=ubah"jubah"jubah"jubah"jubeh"jubj)rE}rF(hUh}rG(h]h]h]h]h]uh!jh]rH(j)rI}rJ(hUh}rK(h]h]h]h]h]uh!jEh]rLj)rM}rN(hUh}rO(U anchornameU#plfit-py-moduleUrefurih$h]h]h]h]h]Uinternaluh!jIh]rP(j$)rQ}rR(hXplfit_pyh}rS(h]h]h]h]h]uh!jMh]rThXplfit_pyrUrV}rW(hUh!jQubah"j,ubhX ModulerXrY}rZ(hX Moduler[h!jMubeh"jubah"jubj)r\}r](hUh}r^(h]h]h]h]h]uh!jEh]r_j)r`}ra(hUh}rb(h]h]h]h]h]uh!j\h]rcj)rd}re(hUh}rf(h]h]h]h]h]uh!j`h]rgj)rh}ri(hUh}rj(U anchornameU #pure-python-version-of-plfit-pyUrefurih$h]h]h]h]h]Uinternaluh!jdh]rkhXPure-Python version of plfit.pyrlrm}rn(hXPure-Python version of plfit.pyroh!jhubah"jubah"jubah"jubah"jubeh"jubeh"jubeh"jubah"jubh-j)rp}rq(hUh}rr(h]h]h]h]h]uh]rsj)rt}ru(hUh}rv(h]h]h]h]h]uh!jph]rw(j)rx}ry(hUh}rz(h]h]h]h]h]uh!jth]r{j)r|}r}(hUh}r~(U anchornameUUrefurih-h]h]h]h]h]Uinternaluh!jxh]rhX.r}r(hX.h!j|ubah"jubah"jubj)r}r(hUh}r(h]h]h]h]h]uh!jth]rj)r}r(hUh}r(UnumberedKUparenth-U titlesonlyUglobh]h]h]h]h]Uentries]r(NjrNjreUhiddenUmaxdepthKU includefiles]r(jjeU includehiddenuh!jh]h"jubah"jubeh"jubah"jubuU indexentriesr}r(h]h$]r((UsinglerXplfit.plfit (module)Xmodule-plfit.plfitUtr(jX,discrete_alpha_mle() (in module plfit.plfit)h~Utr(jX-discrete_best_alpha() (in module plfit.plfit)hUtr(jX&discrete_ksD() (in module plfit.plfit)h`Utr(jX-discrete_likelihood() (in module plfit.plfit)h^Utr(jX4discrete_likelihood_vector() (in module plfit.plfit)hUtr(jX1discrete_max_likelihood() (in module plfit.plfit)hUtr(jX5discrete_max_likelihood_arg() (in module plfit.plfit)h\Utr(jX+most_likely_alpha() (in module plfit.plfit)hbUtr(jX pl_inv() (in module plfit.plfit)hrUtr(jXplexp() (in module plfit.plfit)hUtr(jX#plexp_inv() (in module plfit.plfit)hUtr(jXplfit (class in plfit.plfit)htUtr(jX#alpha_() (plfit.plfit.plfit method)hZUtr(jX&alphavsks() (plfit.plfit.plfit method)hTUtr(jX0discrete_best_alpha() (plfit.plfit.plfit method)hxUtr(jX$kstest_() (plfit.plfit.plfit method)hXUtr(jX&lognormal() (plfit.plfit.plfit method)hfUtr(jX"plfit() (plfit.plfit.plfit method)hUtr(jX/plot_lognormal_cdf() (plfit.plfit.plfit method)hUtr(jX/plot_lognormal_pdf() (plfit.plfit.plfit method)hhUtr(jX$plotcdf() (plfit.plfit.plfit method)hUtr(jX$plotpdf() (plfit.plfit.plfit method)hpUtr(jX$plotppf() (plfit.plfit.plfit method)hUtr(jX$test_pl() (plfit.plfit.plfit method)hdUtr(jX%xminvsks() (plfit.plfit.plfit method)hnUtr(jX#plfit_lsq() (in module plfit.plfit)hUtr(jX%test_fitter() (in module plfit.plfit)hVUtr(jXplfit.plfit_py (module)Xmodule-plfit.plfit_pyUtr(jX#pl_inv() (in module plfit.plfit_py)hUtr(jX"plexp() (in module plfit.plfit_py)hjUtr(jX&plexp_inv() (in module plfit.plfit_py)hUtr(jXplfit (class in plfit.plfit_py)hUtr(jX&alpha_() (plfit.plfit_py.plfit method)hzUtr(jX'kstest_() (plfit.plfit_py.plfit method)hvUtr(jX%plfit() (plfit.plfit_py.plfit method)hUtr(jX(test_fitter() (in module plfit.plfit_py)hlUtreh-]uUall_docsr}r(hGAԼ5h$GAԼ7h-GAԼDuUsettingsr}r(Ucloak_email_addressesrUtrim_footnote_reference_spacerU halt_levelrKUsectsubtitle_xformrUembed_stylesheetrU pep_base_urlrUhttp://www.python.org/dev/peps/rUdoctitle_xformrUwarning_streamrcsphinx.util.nodes WarningStream r)r}r(U_rercre _compile rU+\((DEBUG|INFO|WARNING|ERROR|SEVERE)/[0-4]\)rKRrUwarnfuncrNubUenvrhU rfc_base_urlrUhttp://tools.ietf.org/html/rUfile_insertion_enabledrUgettext_compactrUinput_encodingrU utf-8-sigruUfiles_to_rebuildr}r(jh]r(hh-eRrjh]r(hh-eRruUtoc_secnumbersr}U_nitpick_ignorerh]Rrub.PKcsED!Eտ$plfit-latest/.doctrees/index.doctreecdocutils.nodes document q)q}q(U nametypesq}q(XIhttps://github.com/keflavich/plfit/blob/master/plfit/tests/plfit_tests.pyqX installationqNX descriptionqNXagpyq XOhttps://github.com/keflavich/plfit/blob/master/plfit/tests/clauset2009_tests.pyq X wiki pageq X this websiteq Xindex and table of contentsq NX)power-law distributions in empirical dataqXPhttps://github.com/keflavich/plfit/blob/master/plfit/tests/speedcompare_plfit.pyqXpypyqXpower-law distribution fittingqNuUsubstitution_defsq}qUparse_messagesq]qUcurrent_sourceqNU decorationqNUautofootnote_startqKUnameidsq}q(hUGhttps-github-com-keflavich-plfit-blob-master-plfit-tests-plfit-tests-pyqhU installationqhU descriptionqh Uagpyqh UMhttps-github-com-keflavich-plfit-blob-master-plfit-tests-clauset2009-tests-pyqh U wiki-pageq h U this-websiteq!h Uindex-and-table-of-contentsq"hU)power-law-distributions-in-empirical-dataq#hUNhttps-github-com-keflavich-plfit-blob-master-plfit-tests-speedcompare-plfit-pyq$hUpypyq%hUpower-law-distribution-fittingq&uUchildrenq']q((cdocutils.nodes section q))q*}q+(U rawsourceq,UUparentq-hUsourceq.cdocutils.nodes reprunicode q/X;/var/build/user_builds/plfit/checkouts/latest/doc/index.rstq0q1}q2bUtagnameq3Usectionq4U attributesq5}q6(Udupnamesq7]Uclassesq8]Ubackrefsq9]Uidsq:]q;h&aUnamesq<]q=hauUlineq>KUdocumentq?hh']q@(cdocutils.nodes title qA)qB}qC(h,XPower-law Distribution FittingqDh-h*h.h1h3UtitleqEh5}qF(h7]h8]h9]h:]h<]uh>Kh?hh']qGcdocutils.nodes Text qHXPower-law Distribution FittingqIqJ}qK(h,hDh-hBubaubcdocutils.nodes paragraph qL)qM}qN(h,XThis is a python implementation of a power-law distribution fitter. The code here was originally hosted on `agpy `_ but was moved and re-packaged to make setup.py cleaner.h-h*h.h1h3U paragraphqOh5}qP(h7]h8]h9]h:]h<]uh>Kh?hh']qQ(hHXlThis is a python implementation of a power-law distribution fitter. The code here was originally hosted on qRqS}qT(h,XlThis is a python implementation of a power-law distribution fitter. The code here was originally hosted on h-hMubcdocutils.nodes reference qU)qV}qW(h,XH`agpy `_h5}qX(Unameh UrefuriqYX>http://code.google.com/p/agpy/source/browse/wiki/PowerLaw.wikiqZh:]h9]h7]h8]h<]uh-hMh']q[hHXagpyq\q]}q^(h,Uh-hVubah3U referenceq_ubcdocutils.nodes target q`)qa}qb(h,XA U referencedqcKh-hMh3Utargetqdh5}qe(UrefurihZh:]qfhah9]h7]h8]h<]qgh auh']ubhHX8 but was moved and re-packaged to make setup.py cleaner.qhqi}qj(h,X8 but was moved and re-packaged to make setup.py cleaner.h-hMubeubh))qk}ql(h,Uh-h*h.h1h3h4h5}qm(h7]h8]h9]h:]qnhah<]qohauh>K h?hh']qp(hA)qq}qr(h,X Installationqsh-hkh.h1h3hEh5}qt(h7]h8]h9]h:]h<]uh>K h?hh']quhHX Installationqvqw}qx(h,hsh-hqubaubhL)qy}qz(h,XI've attempted to make the setup.py file work nicely, but it includes some hacks, so if you run into trouble, please report it::h-hkh.h1h3hOh5}q{(h7]h8]h9]h:]h<]uh>K h?hh']q|hHXI've attempted to make the setup.py file work nicely, but it includes some hacks, so if you run into trouble, please report it:q}q~}q(h,XI've attempted to make the setup.py file work nicely, but it includes some hacks, so if you run into trouble, please report it:h-hyubaubcdocutils.nodes literal_block q)q}q(h,XMgit clone git@github.com:keflavich/plfit.git cd plfit python setup.py installh-hkh.h1h3U literal_blockqh5}q(U xml:spaceqUpreserveqh:]h9]h7]h8]h<]uh>Kh?hh']qhHXMgit clone git@github.com:keflavich/plfit.git cd plfit python setup.py installqq}q(h,Uh-hubaubhL)q}q(h,XI*If* ``python setup.py install`` doesn't work, you can try the following:qh-hkh.h1h3hOh5}q(h7]h8]h9]h:]h<]uh>Kh?hh']q(cdocutils.nodes emphasis q)q}q(h,X*If*h5}q(h7]h8]h9]h:]h<]uh-hh']qhHXIfqq}q(h,Uh-hubah3UemphasisqubhHX q}q(h,X h-hubcdocutils.nodes literal q)q}q(h,X``python setup.py install``h5}q(h7]h8]h9]h:]h<]uh-hh']qhHXpython setup.py installqq}q(h,Uh-hubah3UliteralqubhHX) doesn't work, you can try the following:qq}q(h,X) doesn't work, you can try the following:h-hubeubhL)q}q(h,XLTo install the cython function, run: ``python setup.py build_ext --inplace``h-hkh.h1h3hOh5}q(h7]h8]h9]h:]h<]uh>Kh?hh']q(hHX%To install the cython function, run: qq}q(h,X%To install the cython function, run: h-hubh)q}q(h,X'``python setup.py build_ext --inplace``h5}q(h7]h8]h9]h:]h<]uh-hh']qhHX#python setup.py build_ext --inplaceqq}q(h,Uh-hubah3hubeubhL)q}q(h,X!To install the fortran function::qh-hkh.h1h3hOh5}q(h7]h8]h9]h:]h<]uh>Kh?hh']qhHX To install the fortran function:qq}q(h,X To install the fortran function:h-hubaubh)q}q(h,X?cd plfit/plfit/ f2py -c fplfit.f -m fplfit --fcompiler=gfortranh-hkh.h1h3hh5}q(hhh:]h9]h7]h8]h<]uh>Kh?hh']qhHX?cd plfit/plfit/ f2py -c fplfit.f -m fplfit --fcompiler=gfortranqq}q(h,Uh-hubaubeubh))q}q(h,Uh-h*h.h1h3h4h5}q(h7]h8]h9]h:]qhah<]qhauh>Kh?hh']q(hA)q}q(h,X Descriptionqh-hh.h1h3hEh5}q(h7]h8]h9]h:]h<]uh>Kh?hh']qhHX Descriptionqυq}q(h,hh-hubaubhL)q}q(h,XAaron Clauset et al. address the issue of fitting power-laws to distributions on `this website `_ and in their paper, `Power-law distributions in empirical data `_. I have created a python implementation of their code because I didn't have matlab or R and wanted to do some power-law fitting.h-hh.h1h3hOh5}q(h7]h8]h9]h:]h<]uh>Kh?hh']q(hHXQAaron Clauset et al. address the issue of fitting power-laws to distributions on qօq}q(h,XQAaron Clauset et al. address the issue of fitting power-laws to distributions on h-hubhU)q}q(h,X;`this website `_h5}q(UnameX this websitehYX)http://www.santafe.edu/~aaronc/powerlaws/qh:]h9]h7]h8]h<]uh-hh']qhHX this websiteqޅq}q(h,Uh-hubah3h_ubh`)q}q(h,X, hcKh-hh3hdh5}q(Urefurihh:]qh!ah9]h7]h8]h<]qh auh']ubhHX and in their paper, q慁q}q(h,X and in their paper, h-hubhU)q}q(h,Xm`Power-law distributions in empirical data `_h5}q(UnameX)Power-law distributions in empirical datahYX>http://code.google.com/p/agpy/source/browse/wiki/PowerLaw.wikiqh:]h9]h7]h8]h<]uh-hh']qhHX)Power-law distributions in empirical dataqq}q(h,Uh-hubah3h_ubh`)q}q(h,XA hcKh-hh3hdh5}q(Urefurihh:]qh#ah9]h7]h8]h<]qhauh']ubhHX. I have created a python implementation of their code because I didn't have matlab or R and wanted to do some power-law fitting.qq}q(h,X. I have created a python implementation of their code because I didn't have matlab or R and wanted to do some power-law fitting.h-hubeubhL)q}q(h,XPower-laws are very commonly used in astronomy and are typically used to describe the initial mass function (IMF), the core mass function (CMF), and often luminosity distributions. Most distributions in astronomy tend to be apparent power-laws because the source counts are too few or too narrow to distinguish powerlaws from log-normal and other distributions. But, to this end, I've included the testing mechanism to test for consistency with a power law as described in the above paper.qh-hh.h1h3hOh5}q(h7]h8]h9]h:]h<]uh>K&h?hh']qhHXPower-laws are very commonly used in astronomy and are typically used to describe the initial mass function (IMF), the core mass function (CMF), and often luminosity distributions. Most distributions in astronomy tend to be apparent power-laws because the source counts are too few or too narrow to distinguish powerlaws from log-normal and other distributions. But, to this end, I've included the testing mechanism to test for consistency with a power law as described in the above paper.qq}r(h,hh-hubaubhL)r}r(h,X{The python internal documentation is complete. A brief description of relevant functions is included here for convenience:rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>K.h?hh']rhHX{The python internal documentation is complete. A brief description of relevant functions is included here for convenience:rr}r(h,jh-jubaubhL)r }r (h,Xpplfit is implemented as a class. This means that you import plfit, and declare an instance of the plfit class::r h-hh.h1h3hOh5}r (h7]h8]h9]h:]h<]uh>K0h?hh']r hHXoplfit is implemented as a class. This means that you import plfit, and declare an instance of the plfit class:rr}r(h,Xoplfit is implemented as a class. This means that you import plfit, and declare an instance of the plfit class:h-j ubaubh)r}r(h,X4import plfit X = rand(1000) myplfit = plfit.plfit(X)h-hh.h1h3hh5}r(hhh:]h9]h7]h8]h<]uh>K2h?hh']rhHX4import plfit X = rand(1000) myplfit = plfit.plfit(X)rr}r(h,Uh-jubaubhL)r}r(h,XcThe results of the fit are printed to the screen (if desired) and are stored as part of the object.rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>K6h?hh']rhHXcThe results of the fit are printed to the screen (if desired) and are stored as part of the object.rr}r(h,jh-jubaubhL)r }r!(h,X~``alpha_`` and ``kstest_`` are functions used internally to determine the ks-statistic and alpha values as a function of xmin.r"h-hh.h1h3hOh5}r#(h7]h8]h9]h:]h<]uh>K8h?hh']r$(h)r%}r&(h,X ``alpha_``h5}r'(h7]h8]h9]h:]h<]uh-j h']r(hHXalpha_r)r*}r+(h,Uh-j%ubah3hubhHX and r,r-}r.(h,X and h-j ubh)r/}r0(h,X ``kstest_``h5}r1(h7]h8]h9]h:]h<]uh-j h']r2hHXkstest_r3r4}r5(h,Uh-j/ubah3hubhHXd are functions used internally to determine the ks-statistic and alpha values as a function of xmin.r6r7}r8(h,Xd are functions used internally to determine the ks-statistic and alpha values as a function of xmin.h-j ubeubcdocutils.nodes definition_list r9)r:}r;(h,Uh-hh.Nh3Udefinition_listr<h5}r=(h7]h8]h9]h:]h<]uh>Nh?hh']r>(cdocutils.nodes definition_list_item r?)r@}rA(h,X*There are 3 predefined plotting functions: * ``alphavsks`` plots alpha on the y-axis vs. the ks statistic value on the x-axis with the 'best-fit' alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits. * ``plotcdf`` plots the cumulative distribution function along with the best-fit power law * ``plotpdf`` plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well. h-j:h.h1h3Udefinition_list_itemrBh5}rC(h7]h8]h9]h:]h<]uh>KCh']rD(cdocutils.nodes term rE)rF}rG(h,X*There are 3 predefined plotting functions:rHh-j@h.h1h3UtermrIh5}rJ(h7]h8]h9]h:]h<]uh>KCh']rKhHX*There are 3 predefined plotting functions:rLrM}rN(h,jHh-jFubaubcdocutils.nodes definition rO)rP}rQ(h,Uh5}rR(h7]h8]h9]h:]h<]uh-j@h']rScdocutils.nodes bullet_list rT)rU}rV(h,Uh5}rW(UbulletrXX*h:]h9]h7]h8]h<]uh-jPh']rY(cdocutils.nodes list_item rZ)r[}r\(h,X``alphavsks`` plots alpha on the y-axis vs. the ks statistic value on the x-axis with the 'best-fit' alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits.h5}r](h7]h8]h9]h:]h<]uh-jUh']r^hL)r_}r`(h,X``alphavsks`` plots alpha on the y-axis vs. the ks statistic value on the x-axis with the 'best-fit' alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits.h-j[h.h1h3hOh5}ra(h7]h8]h9]h:]h<]uh>K;h']rb(h)rc}rd(h,X ``alphavsks``h5}re(h7]h8]h9]h:]h<]uh-j_h']rfhHX alphavsksrgrh}ri(h,Uh-jcubah3hubhHX plots alpha on the y-axis vs. the ks statistic value on the x-axis with the 'best-fit' alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits.rjrk}rl(h,X plots alpha on the y-axis vs. the ks statistic value on the x-axis with the 'best-fit' alpha value plotted with error bars. These plots are a useful way to determine if other values of xmin are similarly good fits.h-j_ubeubah3U list_itemrmubjZ)rn}ro(h,XX``plotcdf`` plots the cumulative distribution function along with the best-fit power lawh5}rp(h7]h8]h9]h:]h<]uh-jUh']rqhL)rr}rs(h,XX``plotcdf`` plots the cumulative distribution function along with the best-fit power lawh-jnh.h1h3hOh5}rt(h7]h8]h9]h:]h<]uh>K?h']ru(h)rv}rw(h,X ``plotcdf``h5}rx(h7]h8]h9]h:]h<]uh-jrh']ryhHXplotcdfrzr{}r|(h,Uh-jvubah3hubhHXM plots the cumulative distribution function along with the best-fit power lawr}r~}r(h,XM plots the cumulative distribution function along with the best-fit power lawh-jrubeubah3jmubjZ)r}r(h,X``plotpdf`` plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well. h5}r(h7]h8]h9]h:]h<]uh-jUh']rhL)r}r(h,X``plotpdf`` plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well.h-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KAh']r(h)r}r(h,X ``plotpdf``h5}r(h7]h8]h9]h:]h<]uh-jh']rhHXplotpdfrr}r(h,Uh-jubah3hubhHX plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well.rr}r(h,X plots a histogram of the PDF with the best fit power law. It defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and linear binning as well.h-jubeubah3jmubeh3U bullet_listrubah3U definitionrubeubj?)r}r(h,XOther useful functions: * ``test_pl`` uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a "p-value" that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!). * ``plexp_inv`` creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests. * ``pl_inv`` creates a pure cutoff power-law distribution * ``test_fitter`` uses the previous two functions to test the fitter's ability to return the correct xmin and alpha values for large numbers of iterations h-j:h.h1h3jBh5}r(h7]h8]h9]h:]h<]uh>KPh?hh']r(jE)r}r(h,XOther useful functions:rh-jh.h1h3jIh5}r(h7]h8]h9]h:]h<]uh>KPh']rhHXOther useful functions:rr}r(h,jh-jubaubjO)r}r(h,Uh5}r(h7]h8]h9]h:]h<]uh-jh']rjT)r}r(h,Uh5}r(jXX*h:]h9]h7]h8]h<]uh-jh']r(jZ)r}r(h,X,``test_pl`` uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a "p-value" that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!). h5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,X+``test_pl`` uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a "p-value" that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!).h-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KFh']r(h)r}r(h,X ``test_pl``h5}r(h7]h8]h9]h:]h<]uh-jh']rhHXtest_plrr}r(h,Uh-jubah3hubhHX  uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a "p-value" that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!).rr}r(h,X  uses the fitted power-law as the starting point for a monte-carlo test of whether the powerlaw is an acceptable fit. It returns a "p-value" that should be >0.1 if a power-law fit is to be considered (though a high p-value does not ensure that the distribution function is a power law!).h-jubeubah3jmubjZ)r}r(h,Xl``plexp_inv`` creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests.h5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,Xl``plexp_inv`` creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests.h-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KKh']r(h)r}r(h,X ``plexp_inv``h5}r(h7]h8]h9]h:]h<]uh-jh']rhHX plexp_invrr}r(h,Uh-jubah3hubhHX_ creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests.rr}r(h,X_ creates a cutoff power-law distribution with an exponential tail-off. It is useful for tests.h-jubeubah3jmubjZ)r}r(h,X7``pl_inv`` creates a pure cutoff power-law distributionrh5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,jh-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KMh']r(h)r}r(h,X ``pl_inv``h5}r(h7]h8]h9]h:]h<]uh-jh']rhHXpl_invrr}r(h,Uh-jubah3hubhHX- creates a pure cutoff power-law distributionrr}r(h,X- creates a pure cutoff power-law distributionh-jubeubah3jmubjZ)r}r(h,X``test_fitter`` uses the previous two functions to test the fitter's ability to return the correct xmin and alpha values for large numbers of iterations h5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,X``test_fitter`` uses the previous two functions to test the fitter's ability to return the correct xmin and alpha values for large numbers of iterationsh-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KNh']r(h)r}r(h,X``test_fitter``h5}r(h7]h8]h9]h:]h<]uh-jh']rhHX test_fitterrr}r(h,Uh-jubah3hubhHX uses the previous two functions to test the fitter's ability to return the correct xmin and alpha values for large numbers of iterationsrr}r(h,X uses the previous two functions to test the fitter's ability to return the correct xmin and alpha values for large numbers of iterationsh-jubeubah3jmubeh3jubah3jubeubeubhL)r}r(h,XThe powerlaw fitter is very effective at returning the correct value of alpha but not as good at returning the correct value of xmin.rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KRh?hh']rhHXThe powerlaw fitter is very effective at returning the correct value of alpha but not as good at returning the correct value of xmin.rr}r(h,jh-jubaubhL)r}r(h,XThere are 3 implementations of the code internals. fplfit.f is a fortran function, cplfit.pyx is a cython function, and plfit.py is the wrapper and includes a python-only implementation that requires numpy. FORTRAN is fastest, follow closely by cython. Python is ~3x slower.rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KUh?hh']rhHXThere are 3 implementations of the code internals. fplfit.f is a fortran function, cplfit.pyx is a cython function, and plfit.py is the wrapper and includes a python-only implementation that requires numpy. FORTRAN is fastest, follow closely by cython. Python is ~3x slower.rr}r(h,jh-jubaubhL)r}r(h,XzAs of November 21, 2011, there is a pure python (i.e., no numpy) implementation at - you can just put this file in your local working directory and import it, since it contains no requirements beyond pure python. It's slower and hobbled, but it works, and perhaps will run fast with `pypy `_.h-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>KZh?hh']r(hHXTAs of November 21, 2011, there is a pure python (i.e., no numpy) implementation at - you can just put this file in your local working directory and import it, since it contains no requirements beyond pure python. It's slower and hobbled, but it works, and perhaps will run fast with rr}r(h,X> - you can just put this file in your local working directory and import it, since it contains no requirements beyond pure python. It's slower and hobbled, but it works, and perhaps will run fast with h-jubhU)r}r(h,X`pypy `_h5}r(UnamehhYXhttp://pypy.org/rh:]h9]h7]h8]h<]uh-jh']rhHXpypyrr}r(h,Uh-jubah3h_ubh`)r}r(h,X hcKh-jh3hdh5}r(Urefurijh:]rh%ah9]h7]h8]h<]rhauh']ubhHX.r }r!(h,X.h-jubeubj9)r"}r#(h,Uh-hh.Nh3j<h5}r$(h7]h8]h9]h:]h<]uh>Nh?hh']r%j?)r&}r'(h,XFor usage *examples*, see * ``_ * ``_ * ``_ h-j"h.h1h3jBh5}r((h7]h8]h9]h:]h<]uh>Kdh']r)(jE)r*}r+(h,XFor usage *examples*, seer,h-j&h.h1h3jIh5}r-(h7]h8]h9]h:]h<]uh>Kdh']r.(hHX For usage r/r0}r1(h,X For usage h-j*ubh)r2}r3(h,X *examples*h5}r4(h7]h8]h9]h:]h<]uh-j*h']r5hHXexamplesr6r7}r8(h,Uh-j2ubah3hubhHX, seer9r:}r;(h,X, seeh-j*ubeubjO)r<}r=(h,Uh5}r>(h7]h8]h9]h:]h<]uh-j&h']r?jT)r@}rA(h,Uh5}rB(jXX*h:]h9]h7]h8]h<]uh-j<h']rC(jZ)rD}rE(h,XT``_rFh5}rG(h7]h8]h9]h:]h<]uh-j@h']rHhL)rI}rJ(h,jFh-jDh.h1h3hOh5}rK(h7]h8]h9]h:]h<]uh>Kbh']rL(hU)rM}rN(h,jFh5}rO(Unameh hYh h:]h9]h7]h8]h<]uh-jIh']rPhHXOhttps://github.com/keflavich/plfit/blob/master/plfit/tests/clauset2009_tests.pyrQrR}rS(h,Uh-jMubah3h_ubh`)rT}rU(h,XQhcKh-jIh3hdh5}rV(Urefurih h:]rWhah9]h7]h8]h<]rXh auh']ubeubah3jmubjZ)rY}rZ(h,XN``_r[h5}r\(h7]h8]h9]h:]h<]uh-j@h']r]hL)r^}r_(h,j[h-jYh.h1h3hOh5}r`(h7]h8]h9]h:]h<]uh>Kch']ra(hU)rb}rc(h,j[h5}rd(UnamehhYhh:]h9]h7]h8]h<]uh-j^h']rehHXIhttps://github.com/keflavich/plfit/blob/master/plfit/tests/plfit_tests.pyrfrg}rh(h,Uh-jbubah3h_ubh`)ri}rj(h,XKhcKh-j^h3hdh5}rk(Urefurihh:]rlhah9]h7]h8]h<]rmhauh']ubeubah3jmubjZ)rn}ro(h,XV``_ h5}rp(h7]h8]h9]h:]h<]uh-j@h']rqhL)rr}rs(h,XU``_rth-jnh.h1h3hOh5}ru(h7]h8]h9]h:]h<]uh>Kdh']rv(hU)rw}rx(h,jth5}ry(UnamehhYhh:]h9]h7]h8]h<]uh-jrh']rzhHXPhttps://github.com/keflavich/plfit/blob/master/plfit/tests/speedcompare_plfit.pyr{r|}r}(h,Uh-jwubah3h_ubh`)r~}r(h,XRhcKh-jrh3hdh5}r(Urefurihh:]rh$ah9]h7]h8]h<]rhauh']ubeubah3jmubeh3jubah3jubeubaubhL)r}r(h,XA very simple example::rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>Kfh?hh']rhHXA very simple example:rr}r(h,XA very simple example:h-jubaubh)r}r(h,XXimport plfit from numpy.random import rand,seed # generate a power law using the "inverse" power-law generator code X=plfit.plexp_inv(rand(1000),1,2.5) # use the numpy version to fit (usefortran=False is only needed if you installed the fortran version) myplfit=plfit.plfit(X,usefortran=False) # output should look something like this: # PYTHON plfit executed in 0.201362 seconds # xmin: 0.621393 n(>xmin): 263 alpha: 2.39465 +/- 0.0859979 Log-Likelihood: -238.959 ks: 0.0278864 p(ks): 0.986695 # generate some plots from pylab import * figure(1) myplfit.plotpdf() figure(2) myplfit.plotcdf()h-hh.h1h3hh5}r(hhh:]h9]h7]h8]h<]uh>Khh?hh']rhHXXimport plfit from numpy.random import rand,seed # generate a power law using the "inverse" power-law generator code X=plfit.plexp_inv(rand(1000),1,2.5) # use the numpy version to fit (usefortran=False is only needed if you installed the fortran version) myplfit=plfit.plfit(X,usefortran=False) # output should look something like this: # PYTHON plfit executed in 0.201362 seconds # xmin: 0.621393 n(>xmin): 263 alpha: 2.39465 +/- 0.0859979 Log-Likelihood: -238.959 ks: 0.0278864 p(ks): 0.986695 # generate some plots from pylab import * figure(1) myplfit.plotpdf() figure(2) myplfit.plotcdf()rr}r(h,Uh-jubaubhL)r}r(h,X*If you use this code, please cite Clauset et al 2009 and consider posting a comment on the* `wiki page `_.rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>K}h?hh']r(h)r}r(h,X\*If you use this code, please cite Clauset et al 2009 and consider posting a comment on the*h5}r(h7]h8]h9]h:]h<]uh-jh']rhHXZIf you use this code, please cite Clauset et al 2009 and consider posting a comment on therr}r(h,Uh-jubah3hubhHX r}r(h,X h-jubhU)r}r(h,X;`wiki page `_h5}r(UnameX wiki pagehYX,https://code.google.com/p/agpy/wiki/PowerLawrh:]h9]h7]h8]h<]uh-jh']rhHX wiki pagerr}r(h,Uh-jubah3h_ubh`)r}r(h,X/ hcKh-jh3hdh5}r(Urefurijh:]rh ah9]h7]h8]h<]rh auh']ubhHX.r}r(h,X.h-jubeubhL)r}r(h,XDirect citations to the source are welcome! The python translation has been cited in the following works (and perhaps others?):rh-hh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>Kh?hh']rhHXDirect citations to the source are welcome! The python translation has been cited in the following works (and perhaps others?):rr}r(h,jh-jubaubcdocutils.nodes block_quote r)r}r(h,Uh-hh.Nh3U block_quoterh5}r(h7]h8]h9]h:]h<]uh>Nh?hh']rjT)r}r(h,Uh5}r(jXX*h:]h9]h7]h8]h<]uh-jh']r(jZ)r}r(h,X1http://adsabs.harvard.edu/abs/2011ApJ...735...51Mrh5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,jh-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>Kh']rhU)r}r(h,jh5}r(Urefurijh:]h9]h7]h8]h<]uh-jh']rhHX1http://adsabs.harvard.edu/abs/2011ApJ...735...51Mrr}r(h,Uh-jubah3h_ubaubah3jmubjZ)r}r(h,X1http://adsabs.harvard.edu/abs/2011ApJ...736..149Grh5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,jh-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>Kh']rhU)r}r(h,jh5}r(Urefurijh:]h9]h7]h8]h<]uh-jh']rhHX1http://adsabs.harvard.edu/abs/2011ApJ...736..149Grr}r(h,Uh-jubah3h_ubaubah3jmubjZ)r}r(h,X=http://www.rsc.org/suppdata/CC/c0/c0cc00366b/c0cc00366b.pdf h5}r(h7]h8]h9]h:]h<]uh-jh']rhL)r}r(h,X;http://www.rsc.org/suppdata/CC/c0/c0cc00366b/c0cc00366b.pdfrh-jh.h1h3hOh5}r(h7]h8]h9]h:]h<]uh>Kh']rhU)r}r(h,jh5}r(Urefurijh:]h9]h7]h8]h<]uh-jh']rhHX;http://www.rsc.org/suppdata/CC/c0/c0cc00366b/c0cc00366b.pdfrr}r(h,Uh-jubah3h_ubaubah3jmubeh3jubaubeubeubh))r}r(h,Uh-hh.h1h3h4h5}r(h7]h8]h9]h:]rh"ah<]rh auh>Kh?hh']r(hA)r}r(h,XIndex and Table of Contentsrh-jh.h1h3hEh5}r(h7]h8]h9]h:]h<]uh>Kh?hh']rhHXIndex and Table of Contentsrr}r(h,jh-jubaubjT)r}r(h,Uh-jh.h1h3jh5}r(jXX*h:]h9]h7]h8]h<]uh>Kh?hh']r(jZ)r}r(h,X :doc:`apidoc`rh-jh.h1h3jmh5}r(h7]h8]h9]h:]h<]uh>Nh?hh']rhL)r}r (h,jh-jh.h1h3hOh5}r (h7]h8]h9]h:]h<]uh>Kh']r csphinx.addnodes pending_xref r )r }r(h,jh-jh.h1h3U pending_xrefrh5}r(UreftypeXdocrUrefwarnrU reftargetrXapidocU refdomainUh:]h9]U refexplicith7]h8]h<]UrefdocrXindexruh>Kh']rh)r}r(h,jh5}r(h7]h8]r(Uxrefrjeh9]h:]h<]uh-j h']rhHXapidocrr}r(h,Uh-jubah3hubaubaubaubjZ)r }r!(h,XAlphabetical :ref:`genindex`r"h-jh.h1h3jmh5}r#(h7]h8]h9]h:]h<]uh>Nh?hh']r$hL)r%}r&(h,j"h-j h.h1h3hOh5}r'(h7]h8]h9]h:]h<]uh>Kh']r((hHX Alphabetical r)r*}r+(h,X Alphabetical h-j%ubj )r,}r-(h,X:ref:`genindex`r.h-j%h.h1h3jh5}r/(UreftypeXrefjjXgenindexU refdomainXstdr0h:]h9]U refexplicith7]h8]h<]jjuh>Kh']r1h)r2}r3(h,j.h5}r4(h7]h8]r5(jj0Xstd-refr6eh9]h:]h<]uh-j,h']r7hHXgenindexr8r9}r:(h,Uh-j2ubah3hubaubeubaubjZ)r;}r<(h,XHierarchical :ref:`modindex`r=h-jh.h1h3jmh5}r>(h7]h8]h9]h:]h<]uh>Nh?hh']r?hL)r@}rA(h,j=h-j;h.h1h3hOh5}rB(h7]h8]h9]h:]h<]uh>Kh']rC(hHX Hierarchical rDrE}rF(h,X Hierarchical h-j@ubj )rG}rH(h,X:ref:`modindex`rIh-j@h.h1h3jh5}rJ(UreftypeXrefjjXmodindexU refdomainXstdrKh:]h9]U refexplicith7]h8]h<]jjuh>Kh']rLh)rM}rN(h,jIh5}rO(h7]h8]rP(jjKXstd-refrQeh9]h:]h<]uh-jGh']rRhHXmodindexrSrT}rU(h,Uh-jMubah3hubaubeubaubjZ)rV}rW(h,X:ref:`search` h-jh.h1h3jmh5}rX(h7]h8]h9]h:]h<]uh>Nh?hh']rYhL)rZ}r[(h,X :ref:`search`r\h-jVh.h1h3hOh5}r](h7]h8]h9]h:]h<]uh>Kh']r^j )r_}r`(h,j\h-jZh.h1h3jh5}ra(UreftypeXrefjjXsearchU refdomainXstdrbh:]h9]U refexplicith7]h8]h<]jjuh>Kh']rch)rd}re(h,j\h5}rf(h7]h8]rg(jjbXstd-refrheh9]h:]h<]uh-j_h']rihHXsearchrjrk}rl(h,Uh-jdubah3hubaubaubaubeubcdocutils.nodes compound rm)rn}ro(h,Uh-jh.h1h3Ucompoundrph5}rq(h7]h8]rrUtoctree-wrapperrsah9]h:]h<]uh>Nh?hh']rtcsphinx.addnodes toctree ru)rv}rw(h,Uh-jnh.h1h3Utoctreerxh5}ry(UnumberedrzKU includehiddenr{h-jU titlesonlyr|Uglobr}h:]h9]h7]h8]h<]Uentriesr~]r(NXindexrrNXapidocrreUhiddenrU includefilesr]r(jjeUmaxdepthrKuh>Kh']ubaubeubeh,UU transformerrNU footnote_refsr}rUrefnamesr}rUsymbol_footnotesr]rUautofootnote_refsr]rUsymbol_footnote_refsr]rU citationsr]rh?hU current_linerNUtransform_messagesr]rUreporterrNUid_startrKU autofootnotesr]rU citation_refsr}rUindirect_targetsr]rUsettingsr(cdocutils.frontend Values ror}r(Ufootnote_backlinksrKUrecord_dependenciesrNU rfc_base_urlrUhttp://tools.ietf.org/html/rU tracebackrUpep_referencesrNUstrip_commentsrNU toc_backlinksrUentryrU language_coderUenrU datestamprNU report_levelrKU _destinationrNU halt_levelrKU strip_classesrNhENUerror_encoding_error_handlerrUbackslashreplacerUdebugrNUembed_stylesheetrUoutput_encoding_error_handlerrUstrictrU sectnum_xformrKUdump_transformsrNU docinfo_xformrKUwarning_streamrNUpep_file_url_templaterUpep-%04drUexit_status_levelrKUconfigrNUstrict_visitorrNUcloak_email_addressesrUtrim_footnote_reference_spacerUenvrNUdump_pseudo_xmlrNUexpose_internalsrNUsectsubtitle_xformrU source_linkrNUrfc_referencesrNUoutput_encodingrUutf-8rU source_urlrNUinput_encodingrU utf-8-sigrU_disable_configrNU id_prefixrUU tab_widthrKUerror_encodingrUUTF-8rU_sourcerU;/var/build/user_builds/plfit/checkouts/latest/doc/index.rstrUgettext_compactrU generatorrNUdump_internalsrNU smart_quotesrU pep_base_urlrUhttp://www.python.org/dev/peps/rUsyntax_highlightrUlongrUinput_encoding_error_handlerrjUauto_id_prefixrUidrUdoctitle_xformrUstrip_elements_with_classesrNU _config_filesr]Ufile_insertion_enabledrU raw_enabledrKU dump_settingsrNubUsymbol_footnote_startrKUidsr}r(h jh&h*hhkhhhhah#hhjih$j~h!hhjTh"jh%juUsubstitution_namesr}rh3h?h5}r(h7]h:]h9]Usourceh1h8]h<]uU footnotesr]rUrefidsr}rub.PKcsED ::%plfit-latest/.doctrees/apidoc.doctreecdocutils.nodes document q)q}q(U nametypesq}q(Xplfit.plfit.plfit.alphavsksqXplfit.plfit.test_fitterqXplfit.plfit.plfit.kstest_qXplfit.plfit.plfit.alpha_q X'plfit.plfit.discrete_max_likelihood_argq Xplfit.plfit.discrete_likelihoodq Xplfit.plfit.discrete_ksDq Xplfit.plfit.most_likely_alphaq Xplfit.plfit.plfit.test_plqXplfit.plfit.plfit.lognormalqX$plfit.plfit.plfit.plot_lognormal_pdfqXplfit.plfit_py.plexpqXplfit.plfit_py.test_fitterqXapi documentationqNXplfit.plfit.plfit.xminvsksqXplfit.plfit.plfit.plotpdfqXplfit.plfit.pl_invqXplfit.plfit.plfitqXplfit.plfit_py.plfit.kstest_qXplfit.plfit_py.plexp_invqX%plfit.plfit.plfit.discrete_best_alphaqXplfit.plfit_py.plfit.alpha_qX$numpy/matplotlib version of plfit.pyqNXplfit_py moduleqNXplfit.plfit.discrete_alpha_mleqXplfit.plfit.discrete_best_alphaqXplfit.plfit.plfit.plotcdfq Xplfit.plfit_py.plfit.plfitq!Xplfit.plfit_py.plfitq"Xplfit.plfit.plexp_invq#X$plfit.plfit.plfit.plot_lognormal_cdfq$X plfit moduleq%NXplfit.plfit.plexpq&Xplfit.plfit.plfit.plfitq'X&plfit.plfit.discrete_likelihood_vectorq(Xplfit.plfit.plfit_lsqq)Xplfit.plfit.plfit.plotppfq*Xpure-python version of plfit.pyq+NXa. clauset, c.r. shalizi, and m.e.j. newman, "power-law distributions in empirical data" siam review, 51, 661-703 (2009). (arxiv:0706.1062)q,X#plfit.plfit.discrete_max_likelihoodq-Xplfit.plfit_py.pl_invq.uUsubstitution_defsq/}q0Uparse_messagesq1]q2(cdocutils.nodes system_message q3)q4}q5(U rawsourceq6UUparentq7csphinx.addnodes desc_content q8)q9}q:(h6Uh7csphinx.addnodes desc q;)q<}q=(h6Uh7h8)q>}q?(h6Uh7h;)q@}qA(h6Uh7cdocutils.nodes section qB)qC}qD(h6Uh7hB)qE}qF(h6Uh7hB)qG}qH(h6Uh7hUsourceqIcdocutils.nodes reprunicode qJX</var/build/user_builds/plfit/checkouts/latest/doc/apidoc.rstqKqL}qMbUtagnameqNUsectionqOU attributesqP}qQ(UdupnamesqR]UclassesqS]UbackrefsqT]UidsqU]qVUapi-documentationqWaUnamesqX]qYhauUlineqZKUdocumentq[hUchildrenq\]q](cdocutils.nodes title q^)q_}q`(h6XAPI Documentationqah7hGhIhLhNUtitleqbhP}qc(hR]hS]hT]hU]hX]uhZKh[hh\]qdcdocutils.nodes Text qeXAPI Documentationqfqg}qh(h6hah7h_ubaubcdocutils.nodes comment qi)qj}qk(h6X):mod:`plfit` Package --------------------h7hGhIhLhNUcommentqlhP}qm(U xml:spaceqnUpreserveqohU]hT]hR]hS]hX]uhZKh[hh\]qpheX):mod:`plfit` Package --------------------qqqr}qs(h6Uh7hjubaubhi)qt}qu(h6XN.. automodule:: plfit :members: :undoc-members: :show-inheritance:h7hGhIhLhNhlhP}qv(hnhohU]hT]hR]hS]hX]uhZK h[hh\]qwheXN.. automodule:: plfit :members: :undoc-members: :show-inheritance:qxqy}qz(h6Uh7htubaubhEhB)q{}q|(h6Uh7hGhIhLhNhOhP}q}(hR]hS]hT]hU]q~Uplfit-py-moduleqahX]qhauhZKh[hh\]q(h^)q}q(h6X:mod:`plfit_py` Moduleqh7h{hIhLhNhbhP}q(hR]hS]hT]hU]hX]uhZKh[hh\]q(csphinx.addnodes pending_xref q)q}q(h6X:mod:`plfit_py`qh7hhIhLhNU pending_xrefqhP}q(UreftypeXmodUrefwarnqU reftargetqXplfit_pyU refdomainXpyqhU]hT]U refexplicithR]hS]hX]UrefdocqXapidocqUpy:classqNU py:moduleqX plfit.plfitquhZKh\]qcdocutils.nodes literal q)q}q(h6hhP}q(hR]hS]q(UxrefqhXpy-modqehT]hU]hX]uh7hh\]qheXplfit_pyqq}q(h6Uh7hubahNUliteralqubaubheX Moduleqq}q(h6X Moduleqh7hubeubcdocutils.nodes paragraph q)q}q(h6X`Duplicate of the above plfit module, but without using numpy (or matplotlib, therefore no plots)qh7h{hIhLhNU paragraphqhP}q(hR]hS]hT]hU]hX]uhZKh[hh\]qheX`Duplicate of the above plfit module, but without using numpy (or matplotlib, therefore no plots)qq}q(h6hh7hubaubcdocutils.nodes target q)q}q(h6Uh7h{hIU qhNUtargetqhP}q(hR]hU]qXmodule-plfit.plfit_pyqahT]UismodhS]hX]uhZKh[hh\]ubcsphinx.addnodes index q)q}q(h6Uh7h{hIhhNUindexqhP}q(hU]hT]hR]hS]hX]Uentries]q(UsingleqXplfit.plfit_py (module)Xmodule-plfit.plfit_pyUtqauhZKh[hh\]ubhB)q}q(h6Uh7h{hIX[/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_pyqhNhOhP}q(hR]hS]hT]hU]qUpure-python-version-of-plfit-pyqahX]qh+auhZKh[hh\]q(h^)q}q(h6XPure-Python version of plfit.pyqh7hhIhhNhbhP}q(hR]hS]hT]hU]hX]uhZKh[hh\]qheXPure-Python version of plfit.pyqͅq}q(h6hh7hubaubh)q}q(h6XA *pure* python power-law distribution fitter based on code by Aaron Clauset. This is the slowest implementation, but has no dependencies.h7hhIhhNhhP}q(hR]hS]hT]hU]hX]uhZKh[hh\]q(heXA qԅq}q(h6XA h7hubcdocutils.nodes emphasis q)q}q(h6X*pure*hP}q(hR]hS]hT]hU]hX]uh7hh\]qheXpureq܅q}q(h6Uh7hubahNUemphasisqubheX python power-law distribution fitter based on code by Aaron Clauset. This is the slowest implementation, but has no dependencies.qq}q(h6X python power-law distribution fitter based on code by Aaron Clauset. This is the slowest implementation, but has no dependencies.h7hubeubh)q}q(h6XExample very simple use::qh7hhIhhNhhP}q(hR]hS]hT]hU]hX]uhZKh[hh\]qheXExample very simple use:q腁q}q(h6XExample very simple use:h7hubaubcdocutils.nodes literal_block q)q}q(h6XGfrom plfit_py import plfit MyPL = plfit(mydata) MyPL.plotpdf(log=True)h7hhIhhNU literal_blockqhP}q(hnhohU]hT]hR]hS]hX]uhZK h[hh\]qheXGfrom plfit_py import plfit MyPL = plfit(mydata) MyPL.plotpdf(log=True)qq}q(h6Uh7hubaubh)q}q(h6Uh7hhI(cdocutils.statemachine StringList qoq}q(Uitemsq]q(U qKqhKqhKqXb/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.pl_invqKrhKrhKreU parent_offsetrK Udatar]r(Xpl_inv(P, xm, a)rX:module: plfit.plfit_pyrXXXX Inverse CDF for a pure power-lawreh7(hor }r (h]r (hKr hKr hKrhKrhKrhKrhKrhK rhK rhK rhK rhKrhhhjjjhKrhKrhKrhKrhKrhKrXa/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plexprKrjKr jKr!jKr"jKr#jKr$hKr%hKr&hKr'hKr(Xe/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plexp_invr)Kr*j)Kr+j)Kr,j)Kr-j)Kr.j)Kr/hKr0hKr1hKr2U r3Kr4hKr5Xa/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plfitr6Kr7j6Kr8j6Kr9j6Kr:j6Kr;j6Kr<j6Kr=j6Kr>j6Kr?j6K r@j6K rAhKrBhKrChKrDhKrEXh/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plfit.alpha_rFKrGjFKrHjFKrIjFKrJjFKrKjFKrLjFKrMhKrNhKrOhKrPhKrQXi/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plfit.kstest_rRKrSjRKrTjRKrUjRKrVhKrWhKrXhKrYhKrZXg/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.plfit.plfitr[Kr\j[Kr]j[Kr^j[Kr_j[Kr`j[Kraj[Krbj[Krcj[Krdj[K rej[K rfj[K rgj[K rhj[K rij[KrjhKrkhKrlhKrmhKrnXg/var/build/user_builds/plfit/checkouts/latest/plfit/plfit_py.py:docstring of plfit.plfit_py.test_fitterroKrpjoKrqjoKrrjoKrsjoKrtjoKrujoKrvjoKrwjoKrxjoK ryjoK rzjoK r{joK r|joK r}joKr~joKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoKrjoK rjoK!rjoK"rjoK#rjoK$rejKj]r(XXMA *pure* python power-law distribution fitter based on code by Aaron Clauset.rX<This is the slowest implementation, but has no dependencies.rXhXX from plfit_py import plfitrXX MyPL = plfit(mydata)rX MyPL.plotpdf(log=True)rXXX!.. py:function:: pl_inv(P, xm, a)rX :module: plfit.plfit_pyrXX rjX# Inverse CDF for a pure power-lawrjjXX&.. py:function:: plexp(x, xm=1, a=2.5)rX :module: plfit.plfit_pyrXjjXM CDF(x) for the piecewise distribution exponential x=xminrXS This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.rjjXX$.. py:function:: plexp_inv(P, xm, a)rX :module: plfit.plfit_pyrXjjX: Inverse CDF for a piecewise PDF as defined in eqn. 3.10rX of Clauset et al. rjjXX .. py:class:: plfit(x, **kwargs)rX :module: plfit.plfit_pyrXXjjX^ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX1 from http://www.santafe.edu/~aaronc/powerlaws/rjXL See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX! http://arxiv.org/abs/0706.1062rjXN The output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`rjjX! .. py:method:: plfit.alpha_(x)rX :module: plfit.plfit_pyrjX rjXP Create a mappable function alpha to apply to each xmin in a list of xmins.rXR This is essentially the slow version of fplfit/cplfit, though I bet it couldrXY be speeded up with a clever use of parellel_map. Not intended to be used by users.rjjjX" .. py:method:: plfit.kstest_(x)rX :module: plfit.plfit_pyrjX rjjjjXn .. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)rX :module: plfit.plfit_pyrjX rjXf A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX4 from http://www.santafe.edu/~aaronc/powerlaws/rjXO See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXK in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX$ http://arxiv.org/abs/0706.1062rjX9 nosmall is on by default; it rejects low s/n pointsrX. can specify xmin to skip xmin estimationrjXI This is only for continuous distributions; I have not implemented arX. pure-python discrete distribution fitterrjXX.. py:function:: test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=, quiet=True, silent=True)rX :module: plfit.plfit_pyrXjjX Tests the power-law fitter rjjX .. rubric:: ExamplesrjjX) Example (fig 3.4b in Clauset et al.)::rjX1 xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rXM xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)rX) loglog(xminin,xmarr.squeeze(),'x')rjX Example 2::rjX1 xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rXM xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)rX, loglog(xminin,xmarr.mean(axis=0),'x')rjX Example 3::rjXL xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)rX hist(xmarr.squeeze());rX # Test results:rX? # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20rX8 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14rXW # biased distribution; far from correct value of xmin but close to correct alpharjX Example 4::rjXZ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)rXr print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))rX` print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))rX? # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35rX6 # mean(af): 2.51 median(af): 2.50 std(af): 0.07rjeh7(hor}r(h]r(hKrhKrhKrhKrhKrj j jjjjjjjjjjhhhjjjjjjjjjjj j!j"j#j$j%j&j'j(j*j+j,j-j.j/j0j1j2j4j5j7j8j9j:j;j<j=j>j?j@jAjBjCjDjEjGjHjIjJjKjLjMjNjOjPjQjSjTjUjVjWjXjYjZj\j]j^j_j`jajbjcjdjejfjgjhjijjjkjljmjnjpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjejNj]r(XX.. py:module:: plfit.plfit_pyrXhX===============================rXjjXhXjXjjXXjjXjjjjjXjjXjjjjjjXjjXjjjjjjXjjXXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjXjjXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjeh7NubububhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX#pl_inv() (in module plfit.plfit_py)h.UtrauhZNh[hh\]ubh;)r}r(h6Uh7hhIhhNUdescrhP}r(UnoindexrUdomainrXpyhU]hT]hR]hS]hX]UobjtyperXfunctionrUdesctyperjuhZNh[hh\]r(csphinx.addnodes desc_signature r)r}r(h6Xpl_inv(P, xm, a)h7jhIhhNUdesc_signaturerhP}r(hU]rh.aUmodulerhJXplfit.plfit_pyrr}rbhT]hR]hS]hX]rh.aUfullnamerXpl_invrUclassrUUfirstruhZNh[hh\]r(csphinx.addnodes desc_addname r)r}r(h6Xplfit.plfit_py.h7jhIhhNU desc_addnamerhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXplfit.plfit_py.r r }r (h6Uh7jubaubcsphinx.addnodes desc_name r)r}r(h6jh7jhIhhNU desc_namerhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXpl_invrr}r(h6Uh7jubaubcsphinx.addnodes desc_parameterlist r)r}r(h6Uh7jhIhhNUdesc_parameterlistrhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(csphinx.addnodes desc_parameter r)r}r(h6XPhP}r (hR]hS]hT]hU]hX]uh7jh\]r!heXPr"}r#(h6Uh7jubahNUdesc_parameterr$ubj)r%}r&(h6XxmhP}r'(hR]hS]hT]hU]hX]uh7jh\]r(heXxmr)r*}r+(h6Uh7j%ubahNj$ubj)r,}r-(h6XahP}r.(hR]hS]hT]hU]hX]uh7jh\]r/heXar0}r1(h6Uh7j,ubahNj$ubeubcsphinx.addnodes only r2)r3}r4(h6Uh7jhINhNUonlyr5hP}r6(UexprUhtmlr7hU]hT]hR]hS]hX]uhZNh[hh\]r8h)r9}r:(h6UhP}r;(UreftypeUviewcoder<UrefdochU refdomainUstdr=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjuh7j3h\]r>cdocutils.nodes inline r?)r@}rA(h6UhP}rB(hR]hS]rCU viewcode-linkrDahT]hU]hX]uh7j9h\]rEheX[source]rFrG}rH(h6Uh7j@ubahNUinlinerIubahNhubaubeubh8)rJ}rK(h6Uh7jhIhhNU desc_contentrLhP}rM(hR]hS]hT]hU]hX]uhZNh[hh\]rNh)rO}rP(h6X Inverse CDF for a pure power-lawrQh7jJhIhhNhhP}rR(hR]hS]hT]hU]hX]uhZKh[hh\]rSheX Inverse CDF for a pure power-lawrTrU}rV(h6jQh7jOubaubaubeubh)rW}rX(h6Uh7hhI(horY}rZ(h]r[(jjjjj j!j"ejKj]r\(Xplexp(x, xm=1, a=2.5)r]X:module: plfit.plfit_pyr^XXXXJCDF(x) for the piecewise distribution exponential x=xminr_XPThis is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.r`eh7(hora}rb(h]rc(jjjjj j!j"j#j$j%j&j'j(j*j+j,j-j.j/j0j1j2j4j5j7j8j9j:j;j<j=j>j?j@jAjBjCjDjEjGjHjIjJjKjLjMjNjOjPjQjSjTjUjVjWjXjYjZj\j]j^j_j`jajbjcjdjejfjgjhjijjjkjljmjnjpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjejKj]rd(jjXjjjjjjXjjXjjjjjjXjjXXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjXjjXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjeh7j ububhNhhP}re(hU]hT]hR]hS]hX]Uentries]rf(hX"plexp() (in module plfit.plfit_py)hUtrgauhZNh[hh\]ubh;)rh}ri(h6Uh7hhIjYhNjhP}rj(jjXpyhU]hT]hR]hS]hX]jXfunctionrkjjkuhZNh[hh\]rl(j)rm}rn(h6Xplexp(x, xm=1, a=2.5)h7jhhIhhNjhP}ro(hU]rphajhJXplfit.plfit_pyrqrr}rsbhT]hR]hS]hX]rthajXplexprujUjuhZNh[hh\]rv(j)rw}rx(h6Xplfit.plfit_py.h7jmhIhhNjhP}ry(hR]hS]hT]hU]hX]uhZNh[hh\]rzheXplfit.plfit_py.r{r|}r}(h6Uh7jwubaubj)r~}r(h6juh7jmhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplexprr}r(h6Uh7j~ubaubj)r}r(h6Uh7jmhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6XxhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxr}r(h6Uh7jubahNj$ubj)r}r(h6Xxm=1hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxm=1rr}r(h6Uh7jubahNj$ubj)r}r(h6Xa=2.5hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXa=2.5rr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jmhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjuuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jhhIhhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6XCDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.rh7jhIjYhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXCDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.rr}r(h6jh7jubaubaubeubh)r}r(h6Uh7hhI(hor}r(h]r(j&j'j(j*j+j,j-ejK j]r(Xplexp_inv(P, xm, a)rX:module: plfit.plfit_pyrXXXX7Inverse CDF for a piecewise PDF as defined in eqn. 3.10rXof Clauset et al. reh7jaubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX&plexp_inv() (in module plfit.plfit_py)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7hhIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXfunctionrjjuhZNh[hh\]r(j)r}r(h6Xplexp_inv(P, xm, a)h7jhIhhNjhP}r(hU]rhajhJXplfit.plfit_pyrr}rbhT]hR]hS]hX]rhajX plexp_invrjUjuhZNh[hh\]r(j)r}r(h6Xplfit.plfit_py.h7jhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplfit.plfit_py.rr}r(h6Uh7jubaubj)r}r(h6jh7jhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheX plexp_invrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6XPhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXPr}r(h6Uh7jubahNj$ubj)r}r(h6XxmhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxmrr}r(h6Uh7jubahNj$ubj)r}r(h6XahP}r(hR]hS]hT]hU]hX]uh7jh\]rheXar}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r (h6Uh7jubahNjIubahNhubaubeubh8)r }r (h6Uh7jhIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r h)r}r(h6XIInverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.rh7j hIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXIInverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.rr}r(h6jh7jubaubaubeubh)r}r(h6Uh7hhINhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hXplfit (class in plfit.plfit_py)h"UtrauhZNh[hh\]ubh;)r}r(h6Uh7hhINhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXclassrjjuhZNh[hh\]r(j)r }r!(h6Xplfit(x, **kwargs)h7jhIhhNjhP}r"(hU]r#h"ajhJXplfit.plfit_pyr$r%}r&bhT]hR]hS]hX]r'h"ajXplfitr(jUjuhZNh[hh\]r)(csphinx.addnodes desc_annotation r*)r+}r,(h6Xclass h7j hIhhNUdesc_annotationr-hP}r.(hR]hS]hT]hU]hX]uhZNh[hh\]r/heXclass r0r1}r2(h6Uh7j+ubaubj)r3}r4(h6Xplfit.plfit_py.h7j hIhhNjhP}r5(hR]hS]hT]hU]hX]uhZNh[hh\]r6heXplfit.plfit_py.r7r8}r9(h6Uh7j3ubaubj)r:}r;(h6j(h7j hIhhNjhP}r<(hR]hS]hT]hU]hX]uhZNh[hh\]r=heXplfitr>r?}r@(h6Uh7j:ubaubj)rA}rB(h6Uh7j hIhhNjhP}rC(hR]hS]hT]hU]hX]uhZNh[hh\]rD(j)rE}rF(h6XxhP}rG(hR]hS]hT]hU]hX]uh7jAh\]rHheXxrI}rJ(h6Uh7jEubahNj$ubj)rK}rL(h6X**kwargshP}rM(hR]hS]hT]hU]hX]uh7jAh\]rNheX**kwargsrOrP}rQ(h6Uh7jKubahNj$ubeubj2)rR}rS(h6Uh7j hINhNj5hP}rT(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rUh)rV}rW(h6UhP}rX(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidj(uh7jRh\]rYj?)rZ}r[(h6UhP}r\(hR]hS]r]jDahT]hU]hX]uh7jVh\]r^heX[source]r_r`}ra(h6Uh7jZubahNjIubahNhubaubeubh8)rb}rc(h6Uh7jhIhhNjLhP}rd(hR]hS]hT]hU]hX]uhZNh[hh\]re(h)rf}rg(h6XA Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/h7jbhI(horh}ri(h]rj(j1j2j4j5j7j8j9j:j;j<j=j>j?j@jAjBjCjDjEjGjHjIjJjKjLjMjNjOjPjQjSjTjUjVjWjXjYjZj\j]j^j_j`jajbjcjdjejfjgjhjiejKj]rk(Xplfit(x, **kwargs)rlX:module: plfit.plfit_pyrmXXXXX[A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrnX.from http://www.santafe.edu/~aaronc/powerlaws/roXXISee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrpXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rqXhttp://arxiv.org/abs/0706.1062rrXXKThe output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`rsXXX.. py:method:: plfit.alpha_(x)rtX :module: plfit.plfit_pyruXX rvX rwXM Create a mappable function alpha to apply to each xmin in a list of xmins.rxXO This is essentially the slow version of fplfit/cplfit, though I bet it couldryXV be speeded up with a clever use of parellel_map. Not intended to be used by users.rzX r{X r|XX.. py:method:: plfit.kstest_(x)r}X :module: plfit.plfit_pyr~XX rX rX rX rXXk.. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)rX :module: plfit.plfit_pyrXX rX rXc A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX1 from http://www.santafe.edu/~aaronc/powerlaws/rX rXL See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX! http://arxiv.org/abs/0706.1062rX rX6 nosmall is on by default; it rejects low s/n pointsrX+ can specify xmin to skip xmin estimationrX rXF This is only for continuous distributions; I have not implemented arX+ pure-python discrete distribution fitterreh7jaubhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]r(heX+A Python implementation of the Matlab code rr}r(h6X+A Python implementation of the Matlab code h7jfubcdocutils.nodes reference r)r}r(h6X0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrhP}r(UrefurijhU]hT]hR]hS]hX]uh7jfh\]rheX0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrr}r(h6Uh7jubahNU referencerubheX from rr}r(h6X from h7jfubj)r}r(h6X)http://www.santafe.edu/~aaronc/powerlaws/rhP}r(UrefurijhU]hT]hR]hS]hX]uh7jfh\]rheX)http://www.santafe.edu/~aaronc/powerlaws/rr}r(h6Uh7jubahNjubeubh)r}r(h6XSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rh7jbhIjhhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rr}r(h6jh7jubaubh)r}r(h6XKThe output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`rh7jbhIjhhNhhP}r(hR]hS]hT]hU]hX]uhZK h[hh\]r(heX(The output "alpha" is defined such that rr}r(h6X(The output "alpha" is defined such that h7jubcsphinx.ext.mathbase math r)r}r(h6UhP}r(UlatexXp(x) \sim (x/xmin)^{-alpha}hU]hT]hR]hS]hX]uh7jh\]hNUmathrubeubh)r}r(h6Uh7jbhI(hor}r(h]r(jhK rjhK rjhK rjhKrjhKrjhKrejK j]r(Xplfit.alpha_(x)rX:module: plfit.plfit_pyrXXJCreate a mappable function alpha to apply to each xmin in a list of xmins.rXLThis is essentially the slow version of fplfit/cplfit, though I bet it couldrXSbe speeded up with a clever use of parellel_map. Not intended to be used by users.reh7(hor}r(h]r(jhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhK rjhK rjjjjjjjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhKrjhK rjhK!rjhK"rjhK#rjhK$rejNj]r(XXX[A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX.from http://www.santafe.edu/~aaronc/powerlaws/rXXISee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rXhttp://arxiv.org/abs/0706.1062rXjXX.. py:method:: plfit.alpha_(x)rX :module: plfit.plfit_pyrXXM Create a mappable function alpha to apply to each xmin in a list of xmins.rXO This is essentially the slow version of fplfit/cplfit, though I bet it couldrXV be speeded up with a clever use of parellel_map. Not intended to be used by users.rXX.. py:method:: plfit.kstest_(x)rX :module: plfit.plfit_pyrXXk.. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)rX :module: plfit.plfit_pyrXXc A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX1 from http://www.santafe.edu/~aaronc/powerlaws/rXXL See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX! http://arxiv.org/abs/0706.1062rXX6 nosmall is on by default; it rejects low s/n pointsr X+ can specify xmin to skip xmin estimationr XXF This is only for continuous distributions; I have not implemented ar X+ pure-python discrete distribution fitterr Xeh7NububhNhhP}r (hU]hT]hR]hS]hX]Uentries]r(hX&alpha_() (plfit.plfit_py.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7jbhIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6jh7jhIjhhNjhP}r(hU]rhajhJXplfit.plfit_pyrr}rbhT]hR]hS]hX]rhajX plfit.alpha_rjj(juhZNh[hh\]r(j)r}r (h6Xalpha_h7jhIjhhNjhP}r!(hR]hS]hT]hU]hX]uhZNh[hh\]r"heXalpha_r#r$}r%(h6Uh7jubaubj)r&}r'(h6Uh7jhIjhhNjhP}r((hR]hS]hT]hU]hX]uhZNh[hh\]r)j)r*}r+(h6XxhP}r,(hR]hS]hT]hU]hX]uh7j&h\]r-heXxr.}r/(h6Uh7j*ubahNj$ubaubj2)r0}r1(h6Uh7jhINhNj5hP}r2(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r3h)r4}r5(h6UhP}r6(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjuh7j0h\]r7j?)r8}r9(h6UhP}r:(hR]hS]r;jDahT]hU]hX]uh7j4h\]r<heX[source]r=r>}r?(h6Uh7j8ubahNjIubahNhubaubeubh8)r@}rA(h6Uh7jhIjhhNjLhP}rB(hR]hS]hT]hU]hX]uhZNh[hh\]rCh)rD}rE(h6XCreate a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.rFh7j@hIjhNhhP}rG(hR]hS]hT]hU]hX]uhZKh[hh\]rHheXCreate a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.rIrJ}rK(h6jFh7jDubaubaubeubh)rL}rM(h6Uh7jbhI(horN}rO(h]rP(jjejKj]rQ(Xplfit.kstest_(x)rRX:module: plfit.plfit_pyrSeh7(horT}rU(h]rV(jjjjjjjjjjjjjjjjjjjejKj]rW(jjXjjXjjXjjjXj j Xj j Xeh7jububhNhhP}rX(hU]hT]hR]hS]hX]Uentries]rY(hX'kstest_() (plfit.plfit_py.plfit method)hUtrZauhZNh[hh\]ubh;)r[}r\(h6Uh7jbhIjNhNjhP}r](jjXpyhU]hT]hR]hS]hX]jXmethodr^jj^uhZNh[hh\]r_(j)r`}ra(h6jRh7j[hIjhhNjhP}rb(hU]rchajhJXplfit.plfit_pyrdre}rfbhT]hR]hS]hX]rghajX plfit.kstest_rhjj(juhZNh[hh\]ri(j)rj}rk(h6Xkstest_h7j`hIjhhNjhP}rl(hR]hS]hT]hU]hX]uhZNh[hh\]rmheXkstest_rnro}rp(h6Uh7jjubaubj)rq}rr(h6Uh7j`hIjhhNjhP}rs(hR]hS]hT]hU]hX]uhZNh[hh\]rtj)ru}rv(h6XxhP}rw(hR]hS]hT]hU]hX]uh7jqh\]rxheXxry}rz(h6Uh7juubahNj$ubaubj2)r{}r|(h6Uh7j`hINhNj5hP}r}(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r~h)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjhuh7j{h\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7j[hIjhhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]ubeubh)r}r(h6Uh7jbhI(hor}r(h]r(jjjjjjjjjjjjjjjejKj]r(X\plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)rX:module: plfit.plfit_pyrXX`A pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX.from http://www.santafe.edu/~aaronc/powerlaws/rXXISee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rXhttp://arxiv.org/abs/0706.1062rXX3nosmall is on by default; it rejects low s/n pointsrX(can specify xmin to skip xmin estimationrXXCThis is only for continuous distributions; I have not implemented arX(pure-python discrete distribution fitterreh7jTubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX%plfit() (plfit.plfit_py.plfit method)h!UtrauhZNh[hh\]ubh;)r}r(h6Uh7jbhIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6X\plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, xmin=None, verbose=False)h7jhIjhhNjhP}r(hU]rh!ajhJXplfit.plfit_pyrr}rbhT]hR]hS]hX]rh!ajX plfit.plfitrjj(juhZNh[hh\]r(j)r}r(h6Xplfith7jhIjhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplfitrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6X nosmall=TruehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX nosmall=Truerr}r(h6Uh7jubahNj$ubj)r}r(h6X finite=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX finite=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X quiet=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX quiet=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X silent=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX silent=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X xmin=NonehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX xmin=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6X verbose=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX verbose=Falserr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jhIjhhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XA pure-Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/h7jhIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]r(heX0A pure-Python implementation of the Matlab code rr}r(h6X0A pure-Python implementation of the Matlab code h7jubj)r}r(h6X0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrhP}r(UrefurijhU]hT]hR]hS]hX]uh7jh\]rheX0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrr}r(h6Uh7jubahNjubheX from r r }r (h6X from h7jubj)r }r (h6X)http://www.santafe.edu/~aaronc/powerlaws/rhP}r(UrefurijhU]hT]hR]hS]hX]uh7jh\]rheX)http://www.santafe.edu/~aaronc/powerlaws/rr}r(h6Uh7j ubahNjubeubh)r}r(h6XSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rh7jhIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rr}r(h6jh7jubaubh)r}r(h6X\nosmall is on by default; it rejects low s/n points can specify xmin to skip xmin estimationrh7jhIjhNhhP}r(hR]hS]hT]hU]hX]uhZK h[hh\]r heX\nosmall is on by default; it rejects low s/n points can specify xmin to skip xmin estimationr!r"}r#(h6jh7jubaubh)r$}r%(h6XlThis is only for continuous distributions; I have not implemented a pure-python discrete distribution fitterr&h7jhIjhNhhP}r'(hR]hS]hT]hU]hX]uhZK h[hh\]r(heXlThis is only for continuous distributions; I have not implemented a pure-python discrete distribution fitterr)r*}r+(h6j&h7j$ubaubeubeubeubeubh)r,}r-(h6Uh7hhI(hor.}r/(h]r0(jljmjnjpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjejKJj]r1(Xytest_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=, quiet=True, silent=True)r2X:module: plfit.plfit_pyr3XXXXTests the power-law fitter r4XXX.. rubric:: Examplesr5XXX&Example (fig 3.4b in Clauset et al.)::r6XX. xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]r7XJ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)r8X& loglog(xminin,xmarr.squeeze(),'x')r9XX Example 2::r:XX. xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]r;XJ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)r<X) loglog(xminin,xmarr.mean(axis=0),'x')r=XX Example 3::r>XXI xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)r?X hist(xmarr.squeeze());r@X # Test results:rAX< # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20rBX5 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14rCXT # biased distribution; far from correct value of xmin but close to correct alpharDXX Example 4::rEXXW xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)rFXo print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))rGX] print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))rHX< # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35rIX3 # mean(af): 2.51 median(af): 2.50 std(af): 0.07rJeh7jaubhNhhP}rK(hU]hT]hR]hS]hX]Uentries]rL(hX(test_fitter() (in module plfit.plfit_py)hUtrMauhZNh[hh\]ubh;)rN}rO(h6Uh7hhIj.hNjhP}rP(jjXpyhU]hT]hR]hS]hX]jXfunctionrQjjQuhZNh[hh\]rR(j)rS}rT(h6Xytest_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=, quiet=True, silent=True)h7jNhIhhNjhP}rU(hU]rVhajhJXplfit.plfit_pyrWrX}rYbhT]hR]hS]hX]rZhajX test_fitterr[jUjuhZNh[hh\]r\(j)r]}r^(h6Xplfit.plfit_py.h7jShIhhNjhP}r_(hR]hS]hT]hU]hX]uhZNh[hh\]r`heXplfit.plfit_py.rarb}rc(h6Uh7j]ubaubj)rd}re(h6j[h7jShIhhNjhP}rf(hR]hS]hT]hU]hX]uhZNh[hh\]rgheX test_fitterrhri}rj(h6Uh7jdubaubj)rk}rl(h6Uh7jShIhhNjhP}rm(hR]hS]hT]hU]hX]uhZNh[hh\]rn(j)ro}rp(h6Xxmin=1.0hP}rq(hR]hS]hT]hU]hX]uh7jkh\]rrheXxmin=1.0rsrt}ru(h6Uh7joubahNj$ubj)rv}rw(h6X alpha=2.5hP}rx(hR]hS]hT]hU]hX]uh7jkh\]ryheX alpha=2.5rzr{}r|(h6Uh7jvubahNj$ubj)r}}r~(h6X niter=500hP}r(hR]hS]hT]hU]hX]uh7jkh\]rheX niter=500rr}r(h6Uh7j}ubahNj$ubj)r}r(h6X npts=1000hP}r(hR]hS]hT]hU]hX]uh7jkh\]rheX npts=1000rr}r(h6Uh7jubahNj$ubj)r}r(h6X(invcdf=hP}r(hR]hS]hT]hU]hX]uh7jkh\]rheX(invcdf=rr}r(h6Uh7jubahNj$ubj)r}r(h6X quiet=TruehP}r(hR]hS]hT]hU]hX]uh7jkh\]rheX quiet=Truerr}r(h6Uh7jubahNj$ubj)r}r(h6X silent=TruehP}r(hR]hS]hT]hU]hX]uh7jkh\]rheX silent=Truerr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jShINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfit_pyUrefidj[uh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jNhIhhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XTests the power-law fitterrh7jhIj.hNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXTests the power-law fitterrr}r(h6jh7jubaubcdocutils.nodes rubric r)r}r(h6XExamplesrh7jhIj.hNUrubricrhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXExamplesrr}r(h6jh7jubaubh)r}r(h6X&Example (fig 3.4b in Clauset et al.)::rh7jhIj.hNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX%Example (fig 3.4b in Clauset et al.):rr}r(h6X%Example (fig 3.4b in Clauset et al.):h7jubaubh)r}r(h6Xxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x')h7jhIj.hNhhP}r(hnhohU]hT]hR]hS]hX]uhZKrh[hh\]rheXxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x')rr}r(h6Uh7jubaubh)r}r(h6X Example 2::rh7jhIj.hNhhP}r(hR]hS]hT]hU]hX]uhZK h[hh\]rheX Example 2:rr}r(h6X Example 2:h7jubaubh)r}r(h6Xxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x')h7jhIj.hNhhP}r(hnhohU]hT]hR]hS]hX]uhZKxh[hh\]rheXxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x')rr}r(h6Uh7jubaubh)r}r(h6X Example 3::rh7jhIj.hNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX Example 3:rr}r(h6X Example 3:h7jubaubh)r}r(h6X(xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alphah7jhIj.hNhhP}r(hnhohU]hT]hR]hS]hX]uhZK~h[hh\]rheX(xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alpharr}r(h6Uh7jubaubh)r}r(h6X Example 4::rh7jhIj.hNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX Example 4:rr}r(h6X Example 4:h7jubaubh)r}r(h6Xxmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07h7jhIj.hNhhP}r(hnhohU]hT]hR]hS]hX]uhZKh[hh\]rheXxmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07rr}r(h6Uh7jubaubeubeubeubhi)r}r(h6XL:mod:`plfit_v1` Module ---------------------- .. automodule:: plfit.plfit_v1h7h{hIhLhNhlhP}r(hnhohU]hT]hR]hS]hX]uhZK#h[hh\]rheXL:mod:`plfit_v1` Module ---------------------- .. automodule:: plfit.plfit_v1rr}r(h6Uh7jubaubeubeubhIhLhNhOhP}r (hR]hS]hT]hU]r (Xmodule-plfit.plfitr U plfit-moduler ehX]r h%auhZKh[hh\]r(h^)r}r(h6X:mod:`plfit` Modulerh7hEhIhLhNhbhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]r(h)r}r(h6X :mod:`plfit`rh7jhIhLhNhhP}r(UreftypeXmodhhXplfitU refdomainXpyrhU]hT]U refexplicithR]hS]hX]hhhNhNuhZKh\]rh)r}r(h6jhP}r(hR]hS]r(hjXpy-modrehT]hU]hX]uh7jh\]rheXplfitr r!}r"(h6Uh7jubahNhubaubheX Moduler#r$}r%(h6X Moduler&h7jubeubh)r'}r((h6Uh7hEhIhhNhhP}r)(hU]hT]hR]hS]hX]Uentries]r*(hXplfit.plfit (module)Xmodule-plfit.plfitUtr+auhZKh[hh\]ubhCeubhIXU/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfitr,hNhOhP}r-(hR]hS]hT]hU]r.U$numpy-matplotlib-version-of-plfit-pyr/ahX]r0hauhZKh[hh\]r1(h^)r2}r3(h6X$numpy/matplotlib version of plfit.pyr4h7hChIj,hNhbhP}r5(hR]hS]hT]hU]hX]uhZKh[hh\]r6heX$numpy/matplotlib version of plfit.pyr7r8}r9(h6j4h7j2ubaubh)r:}r;(h6XA power-law distribution fitter based on code by Aaron Clauset. It can use fortran, cython, or numpy-based power-law fitting 'backends'. Fortran's fastest.r<h7hChIj,hNhhP}r=(hR]hS]hT]hU]hX]uhZKh[hh\]r>heXA power-law distribution fitter based on code by Aaron Clauset. It can use fortran, cython, or numpy-based power-law fitting 'backends'. Fortran's fastest.r?r@}rA(h6j<h7j:ubaubh)rB}rC(h6X1Requires pylab (matplotlib), which requires numpyrDh7hChIj,hNhhP}rE(hR]hS]hT]hU]hX]uhZKh[hh\]rFheX1Requires pylab (matplotlib), which requires numpyrGrH}rI(h6jDh7jBubaubh)rJ}rK(h6XExample very simple use::rLh7hChIj,hNhhP}rM(hR]hS]hT]hU]hX]uhZK h[hh\]rNheXExample very simple use:rOrP}rQ(h6XExample very simple use:h7jJubaubh)rR}rS(h6XDfrom plfit import plfit MyPL = plfit(mydata) MyPL.plotpdf(log=True)h7hChIhhNhhP}rT(hnhohU]hT]hR]hS]hX]uhZKh[hh\]rUheXDfrom plfit import plfit MyPL = plfit(mydata) MyPL.plotpdf(log=True)rVrW}rX(h6Uh7jRubaubh)rY}rZ(h6Uh7hChI(hor[}r\(h]r](hKr^hKr_hKr`Xh/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_alpha_mleraKrbjaKrcjaKrdjaKrejaKrfjaKrgejKj]rh(Xdiscrete_alpha_mle(data, xmin)riX:module: plfit.plfitrjXXXX#Equation B.17 of Clauset et al 2009rkXXHThe Maximum Likelihood Estimator of the "scaling parameter" alpha in therlX7discrete case is similar to that in the continuous casermeh7(horn}ro(h]rp(j,Krqj,Krrj,Krsj,Krtj,Kruj,Krvj,Krwj,K rxj,K ryj,K rzj,K r{j,K r|j,Kr}hKr~j^j_j`jbjcjdjejfjgjaKrhKrhKrhKrhKrXi/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_best_alpharKrjKrjKrjKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXb/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_ksDrKrjKrjKrjKrjKrjKrjKrjKrjKrjK rjK rhKrhKrhKrhKrXi/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_likelihoodrKrjKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXp/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_likelihood_vectorrKrjKrjKrjKrjKrjKrjKrjKrjKrjK rhKrhKrhKrhKrXm/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_max_likelihoodrKrjKrjKrjKrjKrhKrhKrhKrhKrXq/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.discrete_max_likelihood_argrKrjKrjKrjKrjKrhKrhKrhKrhKrXg/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.most_likely_alpharKrjKrjKrjKrjKrhKrhKrhKrhKrX\/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.pl_invrKrjKrjKrjKrjKrhKrhKrhKrhKrX[/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plexprKrjKrjKrjKrjKrjKrhKrhKrhKrhKrX_/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plexp_invrKrjKrjKrjKrjKrjKrhKrhKrhKrj3KrhKrX[/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfitrKrjKrjKrjKrjKrjKrjKrjKrjKrjK rjK rhKrhKr hKr hKr Xb/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.alpha_r Kr j Krj Krj Krj Krj Krj Krj Krj Krj K rj K rj K rj K rhKrhKrhKrhKrXe/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.alphavsksrKrjKr jKr!jKr"jKr#jKr$jKr%jKr&hKr'hKr(hKr)hKr*Xo/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.discrete_best_alphar+Kr,j+Kr-j+Kr.j+Kr/j+Kr0j+Kr1j+Kr2j+Kr3j+Kr4j+K r5j+K r6j+K r7j+K r8j+K r9j+Kr:j+Kr;j+Kr<hKr=hKr>hKr?hKr@Xc/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.kstest_rAKrBjAKrCjAKrDjAKrEjAKrFjAKrGjAKrHjAKrIjAKrJjAK rKjAK rLhKrMhKrNhKrOhKrPXe/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.lognormalrQKrRjQKrSjQKrTjQKrUjQKrVjQKrWhKrXhKrYhKrZhKr[Xa/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plfitr\Kr]j\Kr^j\Kr_j\Kr`j\Kraj\Krbj\Krcj\Krdj\Krej\K rfj\K rgj\K rhj\K rij\K rjj\Krkj\Krlj\Krmj\Krnj\Kroj\Krpj\Krqj\Krrj\Krsj\Krtj\Kruj\Krvj\Krwj\Krxj\Kryj\Krzj\Kr{j\Kr|j\K r}j\K!r~j\K"rj\K#rj\K$rj\K%rj\K&rj\K'rj\K(rj\K)rj\K*rj\K+rj\K,rj\K-rj\K.rhKrhKrhKrhKrXn/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plot_lognormal_cdfrKrjKrjKrjKrjKrhKrhKrhKrhKrXn/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plot_lognormal_pdfrKrjKrjKrjKrjKrhKrhKrhKrhKrXc/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plotcdfrKrjKrjKrjKrjKrhKrhKrhKrhKrXc/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plotpdfrKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXc/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.plotppfrKrjKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXc/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.test_plrKrjKrjKrjKrjKrjKrjKrjKrjKrjK rjK rjK rjK rjK rjKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXd/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit.xminvsksrKrjKrjKrjKrjKrjKrjKrjKrhKrhKrhKrhKrX_/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.plfit_lsqrKrjKrjKrjKrjKrjKrhKrhKrhKrhKrXa/var/build/user_builds/plfit/checkouts/latest/plfit/plfit.py:docstring of plfit.plfit.test_fitterrKrjKrjKrjKrjKrjKrjKrjKrjKrjK rjK rjK rjK rjK rjKrjKrjKrjKrjKr jKr jKr jKr jKr jKrjKrjKrjKrjKrjKrjKrjKrjKrjK rjK!rjK"rjK#rjK$rejKj]r(XKA power-law distribution fitter based on code by Aaron Clauset. It can userXHfortran, cython, or numpy-based power-law fitting 'backends'. Fortran'srXfastest.rXjDXjLXX from plfit import plfitr XX MyPL = plfit(mydata)r!X MyPL.plotpdf(log=True)r"XXX/.. py:function:: discrete_alpha_mle(data, xmin)r#X :module: plfit.plfitr$XjjX& Equation B.17 of Clauset et al 2009r%jXK The Maximum Likelihood Estimator of the "scaling parameter" alpha in ther&X: discrete case is similar to that in the continuous caser'jXXs.. py:function:: discrete_best_alpha(data, alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True)r(X :module: plfit.plfitr)XjjX@ Use the maximum L to determine the most likely value of alphar*jX *alpharangemults* [ 2-tuple ]r+XK Pair of values indicating multiplicative factors above and below ther,XG approximate alpha from the MLE alpha to use when determining ther-XE "exact" alpha (by directly maximizing the likelihood function)r.jXX0.. py:function:: discrete_ksD(data, xmin, alpha)r/X :module: plfit.plfitr0XjjXR given a sorted data set, a minimum, and an alpha, returns the power law ks-testr1X D value w/datar2jX9 The returned value is the "D" parameter in the ks testr3jXM (this is implemented differently from the continuous version because therer4XN are potentially multiple identical points that need comparison to the powerr5X law)r6jXX7.. py:function:: discrete_likelihood(data, xmin, alpha)r7X :module: plfit.plfitr8XjjX Equation B.8 in Clausetr9jXN Given a data set, an xmin value, and an alpha "scaling parameter", computesr:X2 the log-likelihood (the value to be maximized) r;jXX[.. py:function:: discrete_likelihood_vector(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)r<X :module: plfit.plfitr=XjjXP Compute the likelihood for all "scaling parameters" in the range (alpharange)r>XH for a given xmin. This is only part of the discrete value likelihoodr?X5 maximization problem as described in Clauset et alr@X (Equation B.8)rAjX *alpharange* [ 2-tuple ] rBXV Two floats specifying the upper and lower limits of the power law alpha to testrCjXXX.. py:function:: discrete_max_likelihood(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)rDX :module: plfit.plfitrEXjjXV Returns the *argument* of the max of the likelihood of the data given an input xminrFjjXX\.. py:function:: discrete_max_likelihood_arg(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)rGX :module: plfit.plfitrHXjjXV Returns the *argument* of the max of the likelihood of the data given an input xminrIjjXXR.. py:function:: most_likely_alpha(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)rJX :module: plfit.plfitrKXjjX: Return the most likely alpha for the data given an xminrLjjXX!.. py:function:: pl_inv(P, xm, a)rMX :module: plfit.plfitrNXjjX# Inverse CDF for a pure power-lawrOjjXX&.. py:function:: plexp(x, xm=1, a=2.5)rPX :module: plfit.plfitrQXjjXM CDF(x) for the piecewise distribution exponential x=xminrRXS This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.rSjjXX$.. py:function:: plexp_inv(P, xm, a)rTX :module: plfit.plfitrUXjjX: Inverse CDF for a piecewise PDF as defined in eqn. 3.10rVX of Clauset et al. rWjjXX .. py:class:: plfit(x, **kwargs)rXX :module: plfit.plfitrYXXjjXa A Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_rZX5 from `http://www.santafe.edu/~aaronc/powerlaws/`_.r[jXM See `A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsr\XH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)r]X% `_r^jXN The output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`r_jjX! .. py:method:: plfit.alpha_(x)r`X :module: plfit.plfitrajX rbjbXP Create a mappable function alpha to apply to each xmin in a list of xmins.rcXR This is essentially the slow version of fplfit/cplfit, though I bet it couldrdXY be speeded up with a clever use of parellel_map. Not intended to be used by users.rejbX2 Docstring for the generated alpha function::rfjbXJ Given a sorted data set and a minimum, returns power law MLE fitrgXL data is passed as a keyword parameter so that it can be vectorizedrhjbX6 If there is only one element, return alpha=0rijbjX: .. py:method:: plfit.alphavsks(autozoom=True, **kwargs)rjX :module: plfit.plfitrkjX rljlXN Plot alpha versus the ks value for derived alpha. This plot can be usedrmXO as a diagnostic of whether you have derived the 'best' fit: if there are rnXJ multiple local minima, your data set may be well suited to a broken roX' powerlaw or a different function.rpjljljX .. py:method:: plfit.discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)rqX :module: plfit.plfitrrjX rsjsXC Use the maximum L to determine the most likely value of alphartjsX# *alpharangemults* [ 2-tuple ]ruXN Pair of values indicating multiplicative factors above and below thervXJ approximate alpha from the MLE alpha to use when determining therwXH "exact" alpha (by directly maximizing the likelihood function)rxX *n_alpha* [ int ]ryXX Number of alpha values to use when measuring. Larger number is more accurate.rzX *approximate* [ bool ]r{XK If False, try to "zoom-in" around the MLE alpha and get the exactr|XH best alpha value within some range around the approximate bestr}X *vebose* [ bool ]r~X *finite* [ bool ]rX% Correction for finite data?rjsjX" .. py:method:: plfit.kstest_(x)rX :module: plfit.plfitrjX rjXQ Create a mappable function kstest to apply to each xmin in a list of xmins.rjX3 Docstring for the generated kstest function::rjXU Given a sorted data set and a minimum, returns power law MLE ks-test w/datarXL data is passed as a keyword parameter so that it can be vectorizedrjXA The returned value is the "D" parameter in the ks test.rjjX/ .. py:method:: plfit.lognormal(doprint=True)rX :module: plfit.plfitrjX rjXJ Use the maximum likelihood estimator for a lognormal distribution torX/ produce the best-fit lognormal parametersrjjjX .. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)rX :module: plfit.plfitrjX rjXa A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX4 from http://www.santafe.edu/~aaronc/powerlaws/rjXO See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXK in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX$ http://arxiv.org/abs/0706.1062rjXe There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython)rX\ version is ~10% slower, and the python version is ~3x slower than the fortran version.rXf Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknownrX reasons.rjXj There is also a discrete version implemented in python - it is different from the continous version!rjX *discrete* [ bool | None ]rXK If *discrete* is None, the code will try to determine whether therXJ data set is discrete or continous based on the uniqueness of therXJ data; if your data set is continuous but you have any non-uniquerXA data points (e.g., flagged "bad" data), the "automatic"rXG determination will fail. If *discrete* is True or False, therXD distcrete or continuous fitter will be used, respectively.rjX *xmin* [ float / int ]rXL If you specify xmin, the fitter will only determine alpha assumingrXK the given xmin; the rest of the code (and most of the complexity)rX8 is determining an estimate for xmin and alpha.rjX *nosmall* [ bool (True) ]rXJ When on, the code rejects low s/n points. WARNING: This option,rXJ which is on by default, may result in different answers than therX@ original Matlab code and the "powerlaw" python packagerjX *finite* [ bool (False) ]rXX There is a 'finite-size bias' to the estimator. The "alpha" the code measuresrXP is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nrjX *quiet* [ bool (False) ]rXS If False, delivers messages about what fitter is used and the fit resultsrjX! *verbose* [ bool (False) ] rXX Deliver descriptive messages about the fit parameters (only if *quiet*==False)rjX *silent* [ bool (False) ] rX) If True, will print NO messagesrjjX4 .. py:method:: plfit.plot_lognormal_cdf(**kwargs)rX :module: plfit.plfitrjX rjX, Plot the fitted lognormal distributionrjjjX4 .. py:method:: plfit.plot_lognormal_pdf(**kwargs)rX :module: plfit.plfitrjX rjX, Plot the fitted lognormal distributionrjjjXi .. py:method:: plfit.plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)rX :module: plfit.plfitrjX rjX Plots CDF and powerlawrjjjX .. py:method:: plfit.plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)rX :module: plfit.plfitrjX rjX Plots PDF and powerlaw.rjX3 kwargs is passed to pylab.hist and pylab.plotrjjXT .. py:method:: plfit.plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)rX :module: plfit.plfitrjX rjXH Plots the power-law-predicted value on the Y-axis against the realrXG values along the X-axis. Can be used as a diagnostic of the fit rX quality.rjjjXK .. py:method:: plfit.test_pl(niter=1000.0, print_timing=False, **kwargs)rX :module: plfit.plfitrjX rjXW Monte-Carlo test to determine whether distribution is consistent with a power lawrjXX Runs through niter iterations of a sample size identical to the input sample size.rjX[ Will randomly select values from the data < xmin. The number of values selected willrXN be chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential,rXW and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL.rX2 For more details, see figure 4.1 and sectionrjXS **WARNING** This can take a very long time to run! Execution time scales as rX niter * setsizerjjX* .. py:method:: plfit.xminvsks(**kwargs)rX :module: plfit.plfitrjX rjXM Plot xmin versus the ks value for derived alpha. This plot can be usedrXO as a diagnostic of whether you have derived the 'best' fit: if there are rXJ multiple local minima, your data set may be well suited to a broken rX' powerlaw or a different function.rjjXX .. py:function:: plfit_lsq(x, y)rX :module: plfit.plfitrXjjX Returns A and B in y=Ax^BrX@ http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.htmlrjjXXq.. py:function:: test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=)rX :module: plfit.plfitrXjjX Tests the power-law fitter rjjX .. rubric:: ExamplesrjjX) Example (fig 3.4b in Clauset et al.)::rjX1 xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rXM xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)rX) loglog(xminin,xmarr.squeeze(),'x')rjX Example 2::rjX1 xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rXM xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)rX, loglog(xminin,xmarr.mean(axis=0),'x')rjX Example 3::rjXL xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)rX hist(xmarr.squeeze());rX # Test results:rX? # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20rX8 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14rXW # biased distribution; far from correct value of xmin but close to correct alpharjX Example 4::rjXZ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)rXr print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))rX` print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))rX? # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35rX6 # mean(af): 2.51 median(af): 2.50 std(af): 0.07rjeh7(ho}r(h]r(hKr hKr hKr j,Kr j,Kr jqjrjsjtjujvjwjxjyjzj{j|j}j~j^j_j`jbjcjdjejfjgjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j j jjjjjjjjjjjjjjjjjj j!j"j#j$j%j&j'j(j)j*j,j-j.j/j0j1j2j3j4j5j6j7j8j9j:j;j<j=j>j?j@jBjCjDjEjFjGjHjIjJjKjLjMjNjOjPjRjSjTjUjVjWjXjYjZj[j]j^j_j`jajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j j j jjjjjjjjjjjjjjejNj]r (XX.. py:module:: plfit.plfitr Xj4X$====================================r jjjXjDXjLXj Xj!j"XXj#j$Xjjj%jj&j'jXj(j)Xjjj*jj+j,j-j.jXj/j0Xjjj1j2jj3jj4j5j6jXj7j8Xjjj9jj:j;jXj<j=Xjjj>j?j@jAjjBjCjXjDjEXjjjFjjXjGjHXjjjIjjXjJjKXjjjLjjXjMjNXjjjOjjXjPjQXjjjRjSjjXjTjUXjjjVjWjjXjXjYXXjjjZj[jj\j]j^jj_jjj`jajjbjbjcjdjejbjfjbjgjhjbjijbjjjjkjjljljmjnjojpjljljjqjrjjsjsjtjsjujvjwjxjyjzj{j|j}j~jjjsjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjXjjXjjjjjjXjjXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjeh7NubububhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX,discrete_alpha_mle() (in module plfit.plfit)hUtr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj[hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6Xdiscrete_alpha_mle(data, xmin)h7j hIhhNjhP}r (hU]r hajhJX plfit.plfitr r }r bhT]hR]hS]hX]r hajXdiscrete_alpha_mler jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r! }r" (h6j h7j hIhhNjhP}r# (hR]hS]hT]hU]hX]uhZNh[hh\]r$ heXdiscrete_alpha_mler% r& }r' (h6Uh7j! ubaubj)r( }r) (h6Uh7j hIhhNjhP}r* (hR]hS]hT]hU]hX]uhZNh[hh\]r+ (j)r, }r- (h6XdatahP}r. (hR]hS]hT]hU]hX]uh7j( h\]r/ heXdatar0 r1 }r2 (h6Uh7j, ubahNj$ubj)r3 }r4 (h6XxminhP}r5 (hR]hS]hT]hU]hX]uh7j( h\]r6 heXxminr7 r8 }r9 (h6Uh7j3 ubahNj$ubeubj2)r: }r; (h6Uh7j hINhNj5hP}r< (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r= h)r> }r? (h6UhP}r@ (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j: h\]rA j?)rB }rC (h6UhP}rD (hR]hS]rE jDahT]hU]hX]uh7j> h\]rF heX[source]rG rH }rI (h6Uh7jB ubahNjIubahNhubaubeubh8)rJ }rK (h6Uh7j hIhhNjLhP}rL (hR]hS]hT]hU]hX]uhZNh[hh\]rM (h)rN }rO (h6X#Equation B.17 of Clauset et al 2009rP h7jJ hIj[hNhhP}rQ (hR]hS]hT]hU]hX]uhZKh[hh\]rR heX#Equation B.17 of Clauset et al 2009rS rT }rU (h6jP h7jN ubaubh)rV }rW (h6XThe Maximum Likelihood Estimator of the "scaling parameter" alpha in the discrete case is similar to that in the continuous caserX h7jJ hIj[hNhhP}rY (hR]hS]hT]hU]hX]uhZKh[hh\]rZ heXThe Maximum Likelihood Estimator of the "scaling parameter" alpha in the discrete case is similar to that in the continuous caser[ r\ }r] (h6jX h7jV ubaubeubeubh)r^ }r_ (h6Uh7hChINhNhhP}r` (hU]hT]hR]hS]hX]Uentries]ra (hX-discrete_best_alpha() (in module plfit.plfit)hUtrb auhZNh[hh\]ubh;)rc }rd (h6Uh7hChINhNjhP}re (jjXpyhU]hT]hR]hS]hX]jXfunctionrf jjf uhZNh[hh\]rg (j)rh }ri (h6Xbdiscrete_best_alpha(data, alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True)h7jc hIhhNjhP}rj (hU]rk hajhJX plfit.plfitrl rm }rn bhT]hR]hS]hX]ro hajXdiscrete_best_alpharp jUjuhZNh[hh\]rq (j)rr }rs (h6X plfit.plfit.h7jh hIhhNjhP}rt (hR]hS]hT]hU]hX]uhZNh[hh\]ru heX plfit.plfit.rv rw }rx (h6Uh7jr ubaubj)ry }rz (h6jp h7jh hIhhNjhP}r{ (hR]hS]hT]hU]hX]uhZNh[hh\]r| heXdiscrete_best_alphar} r~ }r (h6Uh7jy ubaubj)r }r (h6Uh7jh hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6Xalpharangemults=(0.9hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalpharangemults=(0.9r r }r (h6Uh7j ubahNj$ubj)r }r (h6X1.1)hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX1.1)r r }r (h6Uh7j ubahNj$ubj)r }r (h6X n_alpha=201hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX n_alpha=201r r }r (h6Uh7j ubahNj$ubj)r }r (h6Xapproximate=TruehP}r (hR]hS]hT]hU]hX]uh7j h\]r heXapproximate=Truer r }r (h6Uh7j ubahNj$ubj)r }r (h6X verbose=TruehP}r (hR]hS]hT]hU]hX]uh7j h\]r heX verbose=Truer r }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7jh hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjp uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7jc hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (h)r }r (h6X=Use the maximum L to determine the most likely value of alphar h7j hI(hor }r (h]r (jjjjjjjjjjjejKj]r (Xbdiscrete_best_alpha(data, alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True)r X:module: plfit.plfitr XXXX=Use the maximum L to determine the most likely value of alphar XX*alpharangemults* [ 2-tuple ]r XH Pair of values indicating multiplicative factors above and below ther XD approximate alpha from the MLE alpha to use when determining ther XB "exact" alpha (by directly maximizing the likelihood function)r eh7(hor }r (h]r (jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j j jjjjjjjjjjjjjjjjjj j!j"j#j$j%j&j'j(j)j*j,j-j.j/j0j1j2j3j4j5j6j7j8j9j:j;j<j=j>j?j@jBjCjDjEjFjGjHjIjJjKjLjMjNjOjPjRjSjTjUjVjWjXjYjZj[j]j^j_j`jajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j j j jjjjjjjjjjjjjjejKj]r (j(j)Xjjj*jj+j,j-j.jXj/j0Xjjj1j2jj3jj4j5j6jXj7j8Xjjj9jj:j;jXj<j=Xjjj>j?j@jAjjBjCjXjDjEXjjjFjjXjGjHXjjjIjjXjJjKXjjjLjjXjMjNXjjjOjjXjPjQXjjjRjSjjXjTjUXjjjVjWjjXjXjYXXjjjZj[jj\j]j^jj_jjj`jajjbjbjcjdjejbjfjbjgjhjbjijbjjjjkjjljljmjnjojpjljljjqjrjjsjsjtjsjujvjwjxjyjzj{j|j}j~jjjsjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjXjjXjjjjjjXjjXjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjeh7jnububhNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heX=Use the maximum L to determine the most likely value of alphar r }r (h6j h7j ubaubcdocutils.nodes definition_list r )r }r (h6Uh7j hIj hNUdefinition_listr hP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r cdocutils.nodes definition_list_item r )r }r (h6X*alpharangemults* [ 2-tuple ] Pair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function) h7j hIj hNUdefinition_list_itemr hP}r (hR]hS]hT]hU]hX]uhZKh\]r (cdocutils.nodes term r )r }r (h6X*alpharangemults* [ 2-tuple ]h7j hIj hNUtermr hP}r (hR]hS]hT]hU]hX]uhZKh\]r (h)r }r (h6X*alpharangemults*hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalpharangemultsr r }r (h6Uh7j ubahNhubheX [ 2-tuple ]r r }r (h6X [ 2-tuple ]h7j ubeubcdocutils.nodes definition r )r }r (h6UhP}r (hR]hS]hT]hU]hX]uh7j h\]r h)r }r (h6XPair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function)r h7j hIj hNhhP}r (hR]hS]hT]hU]hX]uhZKh\]r heXPair of values indicating multiplicative factors above and below the approximate alpha from the MLE alpha to use when determining the "exact" alpha (by directly maximizing the likelihood function)r r }r (h6j h7j ubaubahNU definitionr ubeubaubeubeubh)r }r (h6Uh7hChI(hor }r (h]r (jjjjjjjjjjjjjejK j]r (Xdiscrete_ksD(data, xmin, alpha)r X:module: plfit.plfitr XXXXOgiven a sorted data set, a minimum, and an alpha, returns the power law ks-testr XD value w/datar XX6The returned value is the "D" parameter in the ks testr XXJ(this is implemented differently from the continuous version because therer XKare potentially multiple identical points that need comparison to the powerr Xlaw)r eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX&discrete_ksD() (in module plfit.plfit)h Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6Xdiscrete_ksD(data, xmin, alpha)h7j hIhhNjhP}r (hU]r h ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h ajX discrete_ksDr! jUjuhZNh[hh\]r" (j)r# }r$ (h6X plfit.plfit.h7j hIhhNjhP}r% (hR]hS]hT]hU]hX]uhZNh[hh\]r& heX plfit.plfit.r' r( }r) (h6Uh7j# ubaubj)r* }r+ (h6j! h7j hIhhNjhP}r, (hR]hS]hT]hU]hX]uhZNh[hh\]r- heX discrete_ksDr. r/ }r0 (h6Uh7j* ubaubj)r1 }r2 (h6Uh7j hIhhNjhP}r3 (hR]hS]hT]hU]hX]uhZNh[hh\]r4 (j)r5 }r6 (h6XdatahP}r7 (hR]hS]hT]hU]hX]uh7j1 h\]r8 heXdatar9 r: }r; (h6Uh7j5 ubahNj$ubj)r< }r= (h6XxminhP}r> (hR]hS]hT]hU]hX]uh7j1 h\]r? heXxminr@ rA }rB (h6Uh7j< ubahNj$ubj)rC }rD (h6XalphahP}rE (hR]hS]hT]hU]hX]uh7j1 h\]rF heXalpharG rH }rI (h6Uh7jC ubahNj$ubeubj2)rJ }rK (h6Uh7j hINhNj5hP}rL (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rM h)rN }rO (h6UhP}rP (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj! uh7jJ h\]rQ j?)rR }rS (h6UhP}rT (hR]hS]rU jDahT]hU]hX]uh7jN h\]rV heX[source]rW rX }rY (h6Uh7jR ubahNjIubahNhubaubeubh8)rZ }r[ (h6Uh7j hIhhNjLhP}r\ (hR]hS]hT]hU]hX]uhZNh[hh\]r] (h)r^ }r_ (h6X^given a sorted data set, a minimum, and an alpha, returns the power law ks-test D value w/datar` h7jZ hIj hNhhP}ra (hR]hS]hT]hU]hX]uhZKh[hh\]rb heX^given a sorted data set, a minimum, and an alpha, returns the power law ks-test D value w/datarc rd }re (h6j` h7j^ ubaubh)rf }rg (h6X6The returned value is the "D" parameter in the ks testrh h7jZ hIj hNhhP}ri (hR]hS]hT]hU]hX]uhZKh[hh\]rj heX6The returned value is the "D" parameter in the ks testrk rl }rm (h6jh h7jf ubaubh)rn }ro (h6X(this is implemented differently from the continuous version because there are potentially multiple identical points that need comparison to the power law)rp h7jZ hIj hNhhP}rq (hR]hS]hT]hU]hX]uhZKh[hh\]rr heX(this is implemented differently from the continuous version because there are potentially multiple identical points that need comparison to the power law)rs rt }ru (h6jp h7jn ubaubeubeubh)rv }rw (h6Uh7hChI(horx }ry (h]rz (jjjjjjjjjejKj]r{ (X&discrete_likelihood(data, xmin, alpha)r| X:module: plfit.plfitr} XXXXEquation B.8 in Clausetr~ XXKGiven a data set, an xmin value, and an alpha "scaling parameter", computesr X/the log-likelihood (the value to be maximized) r eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX-discrete_likelihood() (in module plfit.plfit)h Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChIjx hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6X&discrete_likelihood(data, xmin, alpha)h7j hIhhNjhP}r (hU]r h ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h ajXdiscrete_likelihoodr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXdiscrete_likelihoodr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6XxminhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxminr r }r (h6Uh7j ubahNj$ubj)r }r (h6XalphahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalphar r }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7j hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7j hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (h)r }r (h6XEquation B.8 in Clausetr h7j hIjx hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heXEquation B.8 in Clausetr r }r (h6j h7j ubaubh)r }r (h6XzGiven a data set, an xmin value, and an alpha "scaling parameter", computes the log-likelihood (the value to be maximized)r h7j hIjx hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heXzGiven a data set, an xmin value, and an alpha "scaling parameter", computes the log-likelihood (the value to be maximized)r r }r (h6j h7j ubaubeubeubh)r }r (h6Uh7hChINhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX4discrete_likelihood_vector() (in module plfit.plfit)h(Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChINhNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6XJdiscrete_likelihood_vector(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)h7j hIhhNjhP}r (hU]r h(ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h(ajXdiscrete_likelihood_vectorr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXdiscrete_likelihood_vectorr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6XxminhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxminr r }r (h6Uh7j ubahNj$ubj)r }r (h6Xalpharange=(1.5hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalpharange=(1.5r r }r (h6Uh7j ubahNj$ubj)r }r (h6X3.5)hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX3.5)r r }r (h6Uh7j ubahNj$ubj)r }r! (h6X n_alpha=201hP}r" (hR]hS]hT]hU]hX]uh7j h\]r# heX n_alpha=201r$ r% }r& (h6Uh7j ubahNj$ubeubj2)r' }r( (h6Uh7j hINhNj5hP}r) (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r* h)r+ }r, (h6UhP}r- (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j' h\]r. j?)r/ }r0 (h6UhP}r1 (hR]hS]r2 jDahT]hU]hX]uh7j+ h\]r3 heX[source]r4 r5 }r6 (h6Uh7j/ ubahNjIubahNhubaubeubh8)r7 }r8 (h6Uh7j hIhhNjLhP}r9 (hR]hS]hT]hU]hX]uhZNh[hh\]r: (h)r; }r< (h6XCompute the likelihood for all "scaling parameters" in the range (alpharange) for a given xmin. This is only part of the discrete value likelihood maximization problem as described in Clauset et al (Equation B.8)r= h7j7 hI(hor> }r? (h]r@ (jjjjjjjjjjjjejK'j]rA (XJdiscrete_likelihood_vector(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)rB X:module: plfit.plfitrC XXXXMCompute the likelihood for all "scaling parameters" in the range (alpharange)rD XEfor a given xmin. This is only part of the discrete value likelihoodrE X2maximization problem as described in Clauset et alrF X(Equation B.8)rG XX*alpharange* [ 2-tuple ] rH XS Two floats specifying the upper and lower limits of the power law alpha to testrI eh7j ubhNhhP}rJ (hR]hS]hT]hU]hX]uhZKh[hh\]rK heXCompute the likelihood for all "scaling parameters" in the range (alpharange) for a given xmin. This is only part of the discrete value likelihood maximization problem as described in Clauset et al (Equation B.8)rL rM }rN (h6j= h7j; ubaubj )rO }rP (h6Uh7j7 hIj> hNj hP}rQ (hR]hS]hT]hU]hX]uhZNh[hh\]rR j )rS }rT (h6Xj*alpharange* [ 2-tuple ] Two floats specifying the upper and lower limits of the power law alpha to test h7jO hIj> hNj hP}rU (hR]hS]hT]hU]hX]uhZK h\]rV (j )rW }rX (h6X*alpharange* [ 2-tuple ] h7jS hIj> hNj hP}rY (hR]hS]hT]hU]hX]uhZK h\]rZ (h)r[ }r\ (h6X *alpharange*hP}r] (hR]hS]hT]hU]hX]uh7jW h\]r^ heX alpharanger_ r` }ra (h6Uh7j[ ubahNhubheX [ 2-tuple ] rb rc }rd (h6X [ 2-tuple ] h7jW ubeubj )re }rf (h6UhP}rg (hR]hS]hT]hU]hX]uh7jS h\]rh h)ri }rj (h6XOTwo floats specifying the upper and lower limits of the power law alpha to testrk h7je hIj> hNhhP}rl (hR]hS]hT]hU]hX]uhZK h\]rm heXOTwo floats specifying the upper and lower limits of the power law alpha to testrn ro }rp (h6jk h7ji ubaubahNj ubeubaubeubeubh)rq }rr (h6Uh7hChI(hors }rt (h]ru (jjjjjjejK5j]rv (XGdiscrete_max_likelihood(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)rw X:module: plfit.plfitrx XXXXSReturns the *argument* of the max of the likelihood of the data given an input xminry eh7j ubhNhhP}rz (hU]hT]hR]hS]hX]Uentries]r{ (hX1discrete_max_likelihood() (in module plfit.plfit)h-Utr| auhZNh[hh\]ubh;)r} }r~ (h6Uh7hChIjs hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6XGdiscrete_max_likelihood(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)h7j} hIhhNjhP}r (hU]r h-ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h-ajXdiscrete_max_likelihoodr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXdiscrete_max_likelihoodr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6XxminhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxminr r }r (h6Uh7j ubahNj$ubj)r }r (h6Xalpharange=(1.5hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalpharange=(1.5r r }r (h6Uh7j ubahNj$ubj)r }r (h6X3.5)hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX3.5)r r }r (h6Uh7j ubahNj$ubj)r }r (h6X n_alpha=201hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX n_alpha=201r r }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7j hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7j} hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r h)r }r (h6XSReturns the *argument* of the max of the likelihood of the data given an input xminh7j hIjs hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r (heX Returns the r r }r (h6X Returns the h7j ubh)r }r (h6X *argument*hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXargumentr r }r (h6Uh7j ubahNhubheX= of the max of the likelihood of the data given an input xminr r }r (h6X= of the max of the likelihood of the data given an input xminh7j ubeubaubeubh)r }r (h6Uh7hChI(hor }r (h]r (jjjjjjejK>j]r (XKdiscrete_max_likelihood_arg(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)r X:module: plfit.plfitr XXXXSReturns the *argument* of the max of the likelihood of the data given an input xminr eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX5discrete_max_likelihood_arg() (in module plfit.plfit)h Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6XKdiscrete_max_likelihood_arg(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)h7j hIhhNjhP}r (hU]r h ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h ajXdiscrete_max_likelihood_argr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXdiscrete_max_likelihood_argr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6XxminhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxminr r }r (h6Uh7j ubahNj$ubj)r! }r" (h6Xalpharange=(1.5hP}r# (hR]hS]hT]hU]hX]uh7j h\]r$ heXalpharange=(1.5r% r& }r' (h6Uh7j! ubahNj$ubj)r( }r) (h6X3.5)hP}r* (hR]hS]hT]hU]hX]uh7j h\]r+ heX3.5)r, r- }r. (h6Uh7j( ubahNj$ubj)r/ }r0 (h6X n_alpha=201hP}r1 (hR]hS]hT]hU]hX]uh7j h\]r2 heX n_alpha=201r3 r4 }r5 (h6Uh7j/ ubahNj$ubeubj2)r6 }r7 (h6Uh7j hINhNj5hP}r8 (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r9 h)r: }r; (h6UhP}r< (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j6 h\]r= j?)r> }r? (h6UhP}r@ (hR]hS]rA jDahT]hU]hX]uh7j: h\]rB heX[source]rC rD }rE (h6Uh7j> ubahNjIubahNhubaubeubh8)rF }rG (h6Uh7j hIhhNjLhP}rH (hR]hS]hT]hU]hX]uhZNh[hh\]rI h)rJ }rK (h6XSReturns the *argument* of the max of the likelihood of the data given an input xminh7jF hIj hNhhP}rL (hR]hS]hT]hU]hX]uhZKh[hh\]rM (heX Returns the rN rO }rP (h6X Returns the h7jJ ubh)rQ }rR (h6X *argument*hP}rS (hR]hS]hT]hU]hX]uh7jJ h\]rT heXargumentrU rV }rW (h6Uh7jQ ubahNhubheX= of the max of the likelihood of the data given an input xminrX rY }rZ (h6X= of the max of the likelihood of the data given an input xminh7jJ ubeubaubeubh)r[ }r\ (h6Uh7hChI(hor] }r^ (h]r_ (jjjjjjejKGj]r` (XAmost_likely_alpha(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)ra X:module: plfit.plfitrb XXXX7Return the most likely alpha for the data given an xminrc eh7j ubhNhhP}rd (hU]hT]hR]hS]hX]Uentries]re (hX+most_likely_alpha() (in module plfit.plfit)h Utrf auhZNh[hh\]ubh;)rg }rh (h6Uh7hChIj] hNjhP}ri (jjXpyhU]hT]hR]hS]hX]jXfunctionrj jjj uhZNh[hh\]rk (j)rl }rm (h6XAmost_likely_alpha(data, xmin, alpharange=(1.5, 3.5), n_alpha=201)h7jg hIhhNjhP}rn (hU]ro h ajhJX plfit.plfitrp rq }rr bhT]hR]hS]hX]rs h ajXmost_likely_alphart jUjuhZNh[hh\]ru (j)rv }rw (h6X plfit.plfit.h7jl hIhhNjhP}rx (hR]hS]hT]hU]hX]uhZNh[hh\]ry heX plfit.plfit.rz r{ }r| (h6Uh7jv ubaubj)r} }r~ (h6jt h7jl hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXmost_likely_alphar r }r (h6Uh7j} ubaubj)r }r (h6Uh7jl hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XdatahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXdatar r }r (h6Uh7j ubahNj$ubj)r }r (h6XxminhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxminr r }r (h6Uh7j ubahNj$ubj)r }r (h6Xalpharange=(1.5hP}r (hR]hS]hT]hU]hX]uh7j h\]r heXalpharange=(1.5r r }r (h6Uh7j ubahNj$ubj)r }r (h6X3.5)hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX3.5)r r }r (h6Uh7j ubahNj$ubj)r }r (h6X n_alpha=201hP}r (hR]hS]hT]hU]hX]uh7j h\]r heX n_alpha=201r r }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7jl hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjt uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7jg hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r h)r }r (h6X7Return the most likely alpha for the data given an xminr h7j hIj] hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heX7Return the most likely alpha for the data given an xminr r }r (h6j h7j ubaubaubeubh)r }r (h6Uh7hChI(hor }r (h]r (jjjjjjejKPj]r (Xpl_inv(P, xm, a)r X:module: plfit.plfitr XXXX Inverse CDF for a pure power-lawr eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX pl_inv() (in module plfit.plfit)hUtr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6Xpl_inv(P, xm, a)h7j hIhhNjhP}r (hU]r hajhJX plfit.plfitr r }r bhT]hR]hS]hX]r hajXpl_invr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heXpl_invr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XPhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXPr }r (h6Uh7j ubahNj$ubj)r }r (h6XxmhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxmr r }r (h6Uh7j ubahNj$ubj)r }r (h6XahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXar }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7j hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7j hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r h)r }r (h6X Inverse CDF for a pure power-lawr h7j hIj hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heX Inverse CDF for a pure power-lawr r! }r" (h6j h7j ubaubaubeubh)r# }r$ (h6Uh7hChI(hor% }r& (h]r' (jjjjjjjejKYj]r( (Xplexp(x, xm=1, a=2.5)r) X:module: plfit.plfitr* XXXXJCDF(x) for the piecewise distribution exponential x=xminr+ XPThis is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.r, eh7j ubhNhhP}r- (hU]hT]hR]hS]hX]Uentries]r. (hXplexp() (in module plfit.plfit)h&Utr/ auhZNh[hh\]ubh;)r0 }r1 (h6Uh7hChIj% hNjhP}r2 (jjXpyhU]hT]hR]hS]hX]jXfunctionr3 jj3 uhZNh[hh\]r4 (j)r5 }r6 (h6Xplexp(x, xm=1, a=2.5)h7j0 hIhhNjhP}r7 (hU]r8 h&ajhJX plfit.plfitr9 r: }r; bhT]hR]hS]hX]r< h&ajXplexpr= jUjuhZNh[hh\]r> (j)r? }r@ (h6X plfit.plfit.h7j5 hIhhNjhP}rA (hR]hS]hT]hU]hX]uhZNh[hh\]rB heX plfit.plfit.rC rD }rE (h6Uh7j? ubaubj)rF }rG (h6j= h7j5 hIhhNjhP}rH (hR]hS]hT]hU]hX]uhZNh[hh\]rI heXplexprJ rK }rL (h6Uh7jF ubaubj)rM }rN (h6Uh7j5 hIhhNjhP}rO (hR]hS]hT]hU]hX]uhZNh[hh\]rP (j)rQ }rR (h6XxhP}rS (hR]hS]hT]hU]hX]uh7jM h\]rT heXxrU }rV (h6Uh7jQ ubahNj$ubj)rW }rX (h6Xxm=1hP}rY (hR]hS]hT]hU]hX]uh7jM h\]rZ heXxm=1r[ r\ }r] (h6Uh7jW ubahNj$ubj)r^ }r_ (h6Xa=2.5hP}r` (hR]hS]hT]hU]hX]uh7jM h\]ra heXa=2.5rb rc }rd (h6Uh7j^ ubahNj$ubeubj2)re }rf (h6Uh7j5 hINhNj5hP}rg (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh h)ri }rj (h6UhP}rk (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj= uh7je h\]rl j?)rm }rn (h6UhP}ro (hR]hS]rp jDahT]hU]hX]uh7ji h\]rq heX[source]rr rs }rt (h6Uh7jm ubahNjIubahNhubaubeubh8)ru }rv (h6Uh7j0 hIhhNjLhP}rw (hR]hS]hT]hU]hX]uhZNh[hh\]rx h)ry }rz (h6XCDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.r{ h7ju hIj% hNhhP}r| (hR]hS]hT]hU]hX]uhZKh[hh\]r} heXCDF(x) for the piecewise distribution exponential x=xmin This is the CDF version of the distributions drawn in fig 3.4a of Clauset et al.r~ r }r (h6j{ h7jy ubaubaubeubh)r }r (h6Uh7hChI(hor }r (h]r (jjjjjjjejKcj]r (Xplexp_inv(P, xm, a)r X:module: plfit.plfitr XXXX7Inverse CDF for a piecewise PDF as defined in eqn. 3.10r Xof Clauset et al. r eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX#plexp_inv() (in module plfit.plfit)h#Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6Xplexp_inv(P, xm, a)h7j hIhhNjhP}r (hU]r h#ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h#ajX plexp_invr jUjuhZNh[hh\]r (j)r }r (h6X plfit.plfit.h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit.plfit.r r }r (h6Uh7j ubaubj)r }r (h6j h7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r heX plexp_invr r }r (h6Uh7j ubaubj)r }r (h6Uh7j hIhhNjhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r (j)r }r (h6XPhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXPr }r (h6Uh7j ubahNj$ubj)r }r (h6XxmhP}r (hR]hS]hT]hU]hX]uh7j h\]r heXxmr r }r (h6Uh7j ubahNj$ubj)r }r (h6XahP}r (hR]hS]hT]hU]hX]uh7j h\]r heXar }r (h6Uh7j ubahNj$ubeubj2)r }r (h6Uh7j hINhNj5hP}r (Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r }r (h6UhP}r (Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j h\]r j?)r }r (h6UhP}r (hR]hS]r jDahT]hU]hX]uh7j h\]r heX[source]r r }r (h6Uh7j ubahNjIubahNhubaubeubh8)r }r (h6Uh7j hIhhNjLhP}r (hR]hS]hT]hU]hX]uhZNh[hh\]r h)r }r (h6XIInverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.r h7j hIj hNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r heXIInverse CDF for a piecewise PDF as defined in eqn. 3.10 of Clauset et al.r r }r (h6j h7j ubaubaubeubh)r }r (h6Uh7hChINhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hXplfit (class in plfit.plfit)hUtr auhZNh[hh\]ubh@h)r }r (h6Uh7hChI(hor }r (h]r (jjjjjjjejMOj]r (Xplfit_lsq(x, y)r X:module: plfit.plfitr XXXXReturns A and B in y=Ax^Br X=http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.htmlr eh7j ubhNhhP}r (hU]hT]hR]hS]hX]Uentries]r (hX#plfit_lsq() (in module plfit.plfit)h)Utr auhZNh[hh\]ubh;)r }r (h6Uh7hChIj hNjhP}r (jjXpyhU]hT]hR]hS]hX]jXfunctionr jj uhZNh[hh\]r (j)r }r (h6Xplfit_lsq(x, y)h7j hIhhNjhP}r (hU]r h)ajhJX plfit.plfitr r }r bhT]hR]hS]hX]r h)ajX plfit_lsqr jUjuhZNh[hh\]r (j)r }r(h6X plfit.plfit.h7j hIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheX plfit.plfit.rr}r(h6Uh7j ubaubj)r}r(h6j h7j hIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r heX plfit_lsqr r }r (h6Uh7jubaubj)r }r(h6Uh7j hIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6XxhP}r(hR]hS]hT]hU]hX]uh7j h\]rheXxr}r(h6Uh7jubahNj$ubj)r}r(h6XyhP}r(hR]hS]hT]hU]hX]uh7j h\]rheXyr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7j hINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r h)r!}r"(h6UhP}r#(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7jh\]r$j?)r%}r&(h6UhP}r'(hR]hS]r(jDahT]hU]hX]uh7j!h\]r)heX[source]r*r+}r,(h6Uh7j%ubahNjIubahNhubaubeubh8)r-}r.(h6Uh7j hIhhNjLhP}r/(hR]hS]hT]hU]hX]uhZNh[hh\]r0h)r1}r2(h6XWReturns A and B in y=Ax^B http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.htmlh7j-hIj hNhhP}r3(hR]hS]hT]hU]hX]uhZKh[hh\]r4(heXReturns A and B in y=Ax^B r5r6}r7(h6XReturns A and B in y=Ax^B h7j1ubj)r8}r9(h6X=http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.htmlr:hP}r;(Urefurij:hU]hT]hR]hS]hX]uh7j1h\]r<heX=http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.htmlr=r>}r?(h6Uh7j8ubahNjubeubaubeubh)r@}rA(h6Uh7hChI(horB}rC(h]rD(jjjjjjjjjjjjjjjjjjjjjj j j j j jjjjjjjjjjjjjejMYj]rE(X`test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=)rFX:module: plfit.plfitrGXXXXTests the power-law fitter rHXXX.. rubric:: ExamplesrIXXX&Example (fig 3.4b in Clauset et al.)::rJXX. xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rKXJ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000)rLX& loglog(xminin,xmarr.squeeze(),'x')rMXX Example 2::rNXX. xminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100]rOXJ xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000)rPX) loglog(xminin,xmarr.mean(axis=0),'x')rQXX Example 3::rRXXI xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000)rSX hist(xmarr.squeeze());rTX # Test results:rUX< # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20rVX5 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14rWXT # biased distribution; far from correct value of xmin but close to correct alpharXXX Example 4::rYXXW xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv)rZXo print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr)))r[X] print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af)))r\X< # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35r]X3 # mean(af): 2.51 median(af): 2.50 std(af): 0.07r^eh7j ubhNhhP}r_(hU]hT]hR]hS]hX]Uentries]r`(hX%test_fitter() (in module plfit.plfit)hUtraauhZNh[hh\]ubh;)rb}rc(h6Uh7hChIjBhNjhP}rd(jjXpyhU]hT]hR]hS]hX]jXfunctionrejjeuhZNh[hh\]rf(j)rg}rh(h6X`test_fitter(xmin=1.0, alpha=2.5, niter=500, npts=1000, invcdf=)h7jbhIhhNjhP}ri(hU]rjhajhJX plfit.plfitrkrl}rmbhT]hR]hS]hX]rnhajX test_fitterrojUjuhZNh[hh\]rp(j)rq}rr(h6X plfit.plfit.h7jghIhhNjhP}rs(hR]hS]hT]hU]hX]uhZNh[hh\]rtheX plfit.plfit.rurv}rw(h6Uh7jqubaubj)rx}ry(h6joh7jghIhhNjhP}rz(hR]hS]hT]hU]hX]uhZNh[hh\]r{heX test_fitterr|r}}r~(h6Uh7jxubaubj)r}r(h6Uh7jghIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6Xxmin=1.0hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxmin=1.0rr}r(h6Uh7jubahNj$ubj)r}r(h6X alpha=2.5hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX alpha=2.5rr}r(h6Uh7jubahNj$ubj)r}r(h6X niter=500hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX niter=500rr}r(h6Uh7jubahNj$ubj)r}r(h6X npts=1000hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX npts=1000rr}r(h6Uh7jubahNj$ubj)r}r(h6X(invcdf=hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX(invcdf=rr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jghINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjouh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jbhIhhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XTests the power-law fitterrh7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXTests the power-law fitterrr}r(h6jh7jubaubj)r}r(h6XExamplesrh7jhIjBhNjhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXExamplesrr}r(h6jh7jubaubh)r}r(h6X&Example (fig 3.4b in Clauset et al.)::h7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX%Example (fig 3.4b in Clauset et al.):rr}r(h6X%Example (fig 3.4b in Clauset et al.):h7jubaubh)r}r(h6Xxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x')h7jhIjBhNhhP}r(hnhohU]hT]hR]hS]hX]uhZMh[hh\]rheXxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=1,npts=50000) loglog(xminin,xmarr.squeeze(),'x')rr}r(h6Uh7jubaubh)r}r(h6X Example 2::h7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZK h[hh\]rheX Example 2:rr}r(h6X Example 2:h7jubaubh)r}r(h6Xxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x')h7jhIjBhNhhP}r(hnhohU]hT]hR]hS]hX]uhZMh[hh\]rheXxminin=[0.25,0.5,0.75,1,1.5,2,5,10,50,100] xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=xminin,niter=10,npts=1000) loglog(xminin,xmarr.mean(axis=0),'x')rr}r(h6Uh7jubaubh)r}r(h6X Example 3::h7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX Example 3:rr}r(h6X Example 3:h7jubaubh)r}r(h6X(xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alphah7jhIjBhNhhP}r(hnhohU]hT]hR]hS]hX]uhZMh[hh\]rheX(xmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000) hist(xmarr.squeeze()); # Test results: # mean(xmarr) = 0.70, median(xmarr)=0.65 std(xmarr)=0.20 # mean(af) = 2.51 median(af) = 2.49 std(af)=0.14 # biased distribution; far from correct value of xmin but close to correct alpharr}r(h6Uh7jubaubh)r}r(h6X Example 4::h7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX Example 4:rr}r(h6X Example 4:h7jubaubh)r}r(h6Xxmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07h7jhIjBhNhhP}r(hnhohU]hT]hR]hS]hX]uhZMh[hh\]rheXxmarr,af,ksv,nxarr = plfit.test_fitter(xmin=1.0,niter=1000,npts=1000,invcdf=pl_inv) print("mean(xmarr): %0.2f median(xmarr): %0.2f std(xmarr): %0.2f" % (mean(xmarr),median(xmarr),std(xmarr))) print("mean(af): %0.2f median(af): %0.2f std(af): %0.2f" % (mean(af),median(af),std(af))) # mean(xmarr): 1.19 median(xmarr): 1.03 std(xmarr): 0.35 # mean(af): 2.51 median(af): 2.50 std(af): 0.07rr}r(h6Uh7jubaubeubeubeubhINhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXclassrjjuhZNh[hh\]r(j)r}r(h6Xplfit(x, **kwargs)h7h@hIhhNjhP}r(hU]rhajhJX plfit.plfitr r }r bhT]hR]hS]hX]r hajXplfitr jUjuhZNh[hh\]r(j*)r}r(h6Xclass h7jhIhhNj-hP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXclass rr}r(h6Uh7jubaubj)r}r(h6X plfit.plfit.h7jhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheX plfit.plfit.rr}r(h6Uh7jubaubj)r}r(h6j h7jhIhhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r heXplfitr!r"}r#(h6Uh7jubaubj)r$}r%(h6Uh7jhIhhNjhP}r&(hR]hS]hT]hU]hX]uhZNh[hh\]r'(j)r(}r)(h6XxhP}r*(hR]hS]hT]hU]hX]uh7j$h\]r+heXxr,}r-(h6Uh7j(ubahNj$ubj)r.}r/(h6X**kwargshP}r0(hR]hS]hT]hU]hX]uh7j$h\]r1heX**kwargsr2r3}r4(h6Uh7j.ubahNj$ubeubj2)r5}r6(h6Uh7jhINhNj5hP}r7(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r8h)r9}r:(h6UhP}r;(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj uh7j5h\]r<j?)r=}r>(h6UhP}r?(hR]hS]r@jDahT]hU]hX]uh7j9h\]rAheX[source]rBrC}rD(h6Uh7j=ubahNjIubahNhubaubeubh>eubhIhhNjLhP}rE(hR]hS]hT]hU]hX]uhZNh[hh\]rF(h)rG}rH(h6XA Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_ from `http://www.santafe.edu/~aaronc/powerlaws/`_.h7h>hI(horI}rJ(h]rK(jjjjjjjjjjjjjjjjj j j j jjjjjjjjjjjjjjjjjj j!j"j#j$j%j&j'j(j)j*j,j-j.j/j0j1j2j3j4j5j6j7j8j9j:j;j<j=j>j?j@jBjCjDjEjFjGjHjIjJjKjLjMjNjOjPjRjSjTjUjVjWjXjYjZj[j]j^j_j`jajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjejKmj]rL(Xplfit(x, **kwargs)rMX:module: plfit.plfitrNXXXXX^A Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_rOX2from `http://www.santafe.edu/~aaronc/powerlaws/`_.rPXXJSee `A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrQXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rRX"`_rSXXKThe output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`rTXXX.. py:method:: plfit.alpha_(x)rUX :module: plfit.plfitrVXX rWX rXXM Create a mappable function alpha to apply to each xmin in a list of xmins.rYXO This is essentially the slow version of fplfit/cplfit, though I bet it couldrZXV be speeded up with a clever use of parellel_map. Not intended to be used by users.r[X r\X/ Docstring for the generated alpha function::r]X r^XG Given a sorted data set and a minimum, returns power law MLE fitr_XI data is passed as a keyword parameter so that it can be vectorizedr`X raX3 If there is only one element, return alpha=0rbX rcXX7.. py:method:: plfit.alphavsks(autozoom=True, **kwargs)rdX :module: plfit.plfitreXX rfX rgXK Plot alpha versus the ks value for derived alpha. This plot can be usedrhXL as a diagnostic of whether you have derived the 'best' fit: if there are riXG multiple local minima, your data set may be well suited to a broken rjX$ powerlaw or a different function.rkX rlX rmXX~.. py:method:: plfit.discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)rnX :module: plfit.plfitroXX rpX rqX@ Use the maximum L to determine the most likely value of alpharrX rsX *alpharangemults* [ 2-tuple ]rtXK Pair of values indicating multiplicative factors above and below theruXG approximate alpha from the MLE alpha to use when determining thervXE "exact" alpha (by directly maximizing the likelihood function)rwX *n_alpha* [ int ]rxXU Number of alpha values to use when measuring. Larger number is more accurate.ryX *approximate* [ bool ]rzXH If False, try to "zoom-in" around the MLE alpha and get the exactr{XE best alpha value within some range around the approximate bestr|X *vebose* [ bool ]r}X *finite* [ bool ]r~X" Correction for finite data?rX rXX.. py:method:: plfit.kstest_(x)rX :module: plfit.plfitrXX rX rXN Create a mappable function kstest to apply to each xmin in a list of xmins.rX rX0 Docstring for the generated kstest function::rX rXR Given a sorted data set and a minimum, returns power law MLE ks-test w/datarXI data is passed as a keyword parameter so that it can be vectorizedrX rX> The returned value is the "D" parameter in the ks test.rX rXX,.. py:method:: plfit.lognormal(doprint=True)rX :module: plfit.plfitrXX rX rXG Use the maximum likelihood estimator for a lognormal distribution torX, produce the best-fit lognormal parametersrX rX rXX.. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)rX :module: plfit.plfitrXX rX rX^ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrX1 from http://www.santafe.edu/~aaronc/powerlaws/rX rXL See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX! http://arxiv.org/abs/0706.1062rX rXb There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython)rXY version is ~10% slower, and the python version is ~3x slower than the fortran version.rXc Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknownrX reasons.rX rXg There is also a discrete version implemented in python - it is different from the continous version!rX rX *discrete* [ bool | None ]rXH If *discrete* is None, the code will try to determine whether therXG data set is discrete or continous based on the uniqueness of therXG data; if your data set is continuous but you have any non-uniquerX> data points (e.g., flagged "bad" data), the "automatic"rXD determination will fail. If *discrete* is True or False, therXA distcrete or continuous fitter will be used, respectively.rX rX *xmin* [ float / int ]rXI If you specify xmin, the fitter will only determine alpha assumingrXH the given xmin; the rest of the code (and most of the complexity)rX5 is determining an estimate for xmin and alpha.rX rX *nosmall* [ bool (True) ]rXG When on, the code rejects low s/n points. WARNING: This option,rXG which is on by default, may result in different answers than therX= original Matlab code and the "powerlaw" python packagerX rX *finite* [ bool (False) ]rXU There is a 'finite-size bias' to the estimator. The "alpha" the code measuresrXM is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nrX rX *quiet* [ bool (False) ]rXP If False, delivers messages about what fitter is used and the fit resultsrX rX *verbose* [ bool (False) ] rXU Deliver descriptive messages about the fit parameters (only if *quiet*==False)rX rX *silent* [ bool (False) ] rX& If True, will print NO messagesrX rXX1.. py:method:: plfit.plot_lognormal_cdf(**kwargs)rX :module: plfit.plfitrXX rX rX) Plot the fitted lognormal distributionrX rX rXX1.. py:method:: plfit.plot_lognormal_pdf(**kwargs)rX :module: plfit.plfitrXX rX rX) Plot the fitted lognormal distributionrX rX rXXf.. py:method:: plfit.plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)rX :module: plfit.plfitrXX rX rX Plots CDF and powerlawrX rX rXX.. py:method:: plfit.plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)rX :module: plfit.plfitrXX rX rX Plots PDF and powerlaw.rX rX0 kwargs is passed to pylab.hist and pylab.plotrX rXXQ.. py:method:: plfit.plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)rX :module: plfit.plfitrXX rX rXE Plots the power-law-predicted value on the Y-axis against the realrXD values along the X-axis. Can be used as a diagnostic of the fit rX quality.rX rX rXXH.. py:method:: plfit.test_pl(niter=1000.0, print_timing=False, **kwargs)rX :module: plfit.plfitrXX rX rXT Monte-Carlo test to determine whether distribution is consistent with a power lawrX rXU Runs through niter iterations of a sample size identical to the input sample size.rX rXX Will randomly select values from the data < xmin. The number of values selected willrXK be chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential,rXT and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL.rX/ For more details, see figure 4.1 and sectionrX rXP **WARNING** This can take a very long time to run! Execution time scales as rX niter * setsizerX rXX'.. py:method:: plfit.xminvsks(**kwargs)rX :module: plfit.plfitrXX rX rXJ Plot xmin versus the ks value for derived alpha. This plot can be usedrXL as a diagnostic of whether you have derived the 'best' fit: if there are rXG multiple local minima, your data set may be well suited to a broken r X$ powerlaw or a different function.r eh7j ubhNhhP}r (hR]hS]hT]hU]hX]uhZKh[hh\]r (heX+A Python implementation of the Matlab code r r}r(h6X+A Python implementation of the Matlab code h7jGubcdocutils.nodes problematic r)r}r(h6X3`http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_rh7jGhINhNU problematicrhP}r(hU]rUid4rahT]hR]hS]hX]UrefidUid3ruhZNh[hh\]rheX3`http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_rr}r(h6Uh7jubaubheX from rr}r(h6X from h7jGubj)r }r!(h6X,`http://www.santafe.edu/~aaronc/powerlaws/`_r"h7jGhINhNjhP}r#(hU]r$Uid6r%ahT]hR]hS]hX]UrefidUid5r&uhZNh[hh\]r'heX,`http://www.santafe.edu/~aaronc/powerlaws/`_r(r)}r*(h6Uh7j ubaubheX.r+}r,(h6X.h7jGubeubh)r-}r.(h6XSee `A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) `_h7h>hIjIhNhhP}r/(hR]hS]hT]hU]hX]uhZKh[hh\]r0(heXSee r1r2}r3(h6XSee h7j-ubj)r4}r5(h6X`A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) `_hP}r6(UnameXA. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)Urefurir7Xhttp://arxiv.org/abs/0706.1062r8hU]hT]hR]hS]hX]uh7j-h\]r9heXA. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)r:r;}r<(h6Uh7j4ubahNjubh)r=}r>(h6X! U referencedr?Kh7j-hNhhP}r@(Urefurij8hU]rAU|a-clauset-c-r-shalizi-and-m-e-j-newman-power-law-distributions-in-empirical-data-siam-review-51-661-703-2009-arxiv-0706-1062rBahT]hR]hS]hX]rCh,auh\]ubeubh)rD}rE(h6XKThe output "alpha" is defined such that :math:`p(x) \sim (x/xmin)^{-alpha}`rFh7h>hIjIhNhhP}rG(hR]hS]hT]hU]hX]uhZK h[hh\]rH(heX(The output "alpha" is defined such that rIrJ}rK(h6X(The output "alpha" is defined such that h7jDubj)rL}rM(h6UhP}rN(UlatexXp(x) \sim (x/xmin)^{-alpha}hU]hT]hR]hS]hX]uh7jDh\]hNjubeubh)rO}rP(h6Uh7h>hI(horQ}rR(h]rS(jIK rTjIK rUjIK rVjIKrWjIKrXjIKrYjIKrZjIKr[jIKr\jIKr]jIKr^jIKr_jIKr`ejK j]ra(Xplfit.alpha_(x)rbX:module: plfit.plfitrcXXJCreate a mappable function alpha to apply to each xmin in a list of xmins.rdXLThis is essentially the slow version of fplfit/cplfit, though I bet it couldreXSbe speeded up with a clever use of parellel_map. Not intended to be used by users.rfXX,Docstring for the generated alpha function::rgXXD Given a sorted data set and a minimum, returns power law MLE fitrhXF data is passed as a keyword parameter so that it can be vectorizedriXX0 If there is only one element, return alpha=0rjeh7(hork}rl(h]rm(jIKrnjIKrojIKrpjIKrqjIKrrjIKrsjIKrtjIKrujIKrvjIK rwjIK rxjTjUjVjWjXjYjZj[j\j]j^j_j`jIKryjIKrzjIKr{jIKr|jIKr}jIKr~jIKrjIKrjIK rjIK!rjIK"rjIK#rjIK$rjIK%rjIK&rjIK'rjIK(rjIK)rjIK*rjIK+rjIK,rjIK-rjIK.rjIK/rjIK0rjIK1rjIK2rjIK3rjIK4rjIK5rjIK6rjIK7rjIK8rjIK9rjIK:rjIK;rjIKrjIK?rjIK@rjIKArjIKBrjIKCrjIKDrjIKErjIKFrjIKGrjIKHrjIKIrjIKJrjIKKrjIKLrjIKMrjIKNrjIKOrjIKPrjIKQrjIKRrjIKSrjIKTrjIKUrjIKVrjIKWrjIKXrjIKYrjIKZrjIK[rjIK\rjIK]rjIK^rjIK_rjIK`rjIKarjIKbrjIKcrjIKdrjIKerjIKfrjIKgrjIKhrjIKirjIKjrjIKkrjIKlrjIKmrjIKnrjIKorjIKprjIKqrjIKrrjIKsrjIKtrjIKurjIKvrjIKwrjIKxrjIKyrjIKzrjIK{rjIK|rjIK}rjIK~rjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKrjIKr jIKr jIKr jIKr jIKr jIKrjIKrejNj]r(XXX^A Python implementation of the Matlab code `http://www.santafe.edu/~aaronc/powerlaws/plfit.m`_rX2from `http://www.santafe.edu/~aaronc/powerlaws/`_.rXXJSee `A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rX"`_rXjFXX.. py:method:: plfit.alpha_(x)rX :module: plfit.plfitrXXM Create a mappable function alpha to apply to each xmin in a list of xmins.rXO This is essentially the slow version of fplfit/cplfit, though I bet it couldrXV be speeded up with a clever use of parellel_map. Not intended to be used by users.rXX/ Docstring for the generated alpha function::rXXG Given a sorted data set and a minimum, returns power law MLE fitrXI data is passed as a keyword parameter so that it can be vectorizedrXX3 If there is only one element, return alpha=0rXX7.. py:method:: plfit.alphavsks(autozoom=True, **kwargs)rX :module: plfit.plfitr XXK Plot alpha versus the ks value for derived alpha. This plot can be usedr!XL as a diagnostic of whether you have derived the 'best' fit: if there are r"XG multiple local minima, your data set may be well suited to a broken r#X$ powerlaw or a different function.r$XX~.. py:method:: plfit.discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)r%X :module: plfit.plfitr&XX@ Use the maximum L to determine the most likely value of alphar'XX *alpharangemults* [ 2-tuple ]r(XK Pair of values indicating multiplicative factors above and below ther)XG approximate alpha from the MLE alpha to use when determining ther*XE "exact" alpha (by directly maximizing the likelihood function)r+X *n_alpha* [ int ]r,XU Number of alpha values to use when measuring. Larger number is more accurate.r-X *approximate* [ bool ]r.XH If False, try to "zoom-in" around the MLE alpha and get the exactr/XE best alpha value within some range around the approximate bestr0X *vebose* [ bool ]r1X *finite* [ bool ]r2X" Correction for finite data?r3XX.. py:method:: plfit.kstest_(x)r4X :module: plfit.plfitr5XXN Create a mappable function kstest to apply to each xmin in a list of xmins.r6XX0 Docstring for the generated kstest function::r7XXR Given a sorted data set and a minimum, returns power law MLE ks-test w/datar8XI data is passed as a keyword parameter so that it can be vectorizedr9XX> The returned value is the "D" parameter in the ks test.r:XX,.. py:method:: plfit.lognormal(doprint=True)r;X :module: plfit.plfitr<XXG Use the maximum likelihood estimator for a lognormal distribution tor=X, produce the best-fit lognormal parametersr>XX.. py:method:: plfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)r?X :module: plfit.plfitr@XX^ A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrAX1 from http://www.santafe.edu/~aaronc/powerlaws/rBXXL See A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrCXH in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)rDX! http://arxiv.org/abs/0706.1062rEXXb There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython)rFXY version is ~10% slower, and the python version is ~3x slower than the fortran version.rGXc Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknownrHX reasons.rIXXg There is also a discrete version implemented in python - it is different from the continous version!rJXX *discrete* [ bool | None ]rKXH If *discrete* is None, the code will try to determine whether therLXG data set is discrete or continous based on the uniqueness of therMXG data; if your data set is continuous but you have any non-uniquerNX> data points (e.g., flagged "bad" data), the "automatic"rOXD determination will fail. If *discrete* is True or False, therPXA distcrete or continuous fitter will be used, respectively.rQXX *xmin* [ float / int ]rRXI If you specify xmin, the fitter will only determine alpha assumingrSXH the given xmin; the rest of the code (and most of the complexity)rTX5 is determining an estimate for xmin and alpha.rUXX *nosmall* [ bool (True) ]rVXG When on, the code rejects low s/n points. WARNING: This option,rWXG which is on by default, may result in different answers than therXX= original Matlab code and the "powerlaw" python packagerYXX *finite* [ bool (False) ]rZXU There is a 'finite-size bias' to the estimator. The "alpha" the code measuresr[XM is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nr\XX *quiet* [ bool (False) ]r]XP If False, delivers messages about what fitter is used and the fit resultsr^XX *verbose* [ bool (False) ] r_XU Deliver descriptive messages about the fit parameters (only if *quiet*==False)r`XX *silent* [ bool (False) ] raX& If True, will print NO messagesrbXX1.. py:method:: plfit.plot_lognormal_cdf(**kwargs)rcX :module: plfit.plfitrdXX) Plot the fitted lognormal distributionreXX1.. py:method:: plfit.plot_lognormal_pdf(**kwargs)rfX :module: plfit.plfitrgXX) Plot the fitted lognormal distributionrhXXf.. py:method:: plfit.plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)riX :module: plfit.plfitrjXX Plots CDF and powerlawrkXX.. py:method:: plfit.plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)rlX :module: plfit.plfitrmXX Plots PDF and powerlaw.rnXX0 kwargs is passed to pylab.hist and pylab.plotroXXQ.. py:method:: plfit.plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)rpX :module: plfit.plfitrqXXE Plots the power-law-predicted value on the Y-axis against the realrrXD values along the X-axis. Can be used as a diagnostic of the fit rsX quality.rtXXH.. py:method:: plfit.test_pl(niter=1000.0, print_timing=False, **kwargs)ruX :module: plfit.plfitrvXXT Monte-Carlo test to determine whether distribution is consistent with a power lawrwXXU Runs through niter iterations of a sample size identical to the input sample size.rxXXX Will randomly select values from the data < xmin. The number of values selected willryXK be chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential,rXT and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL.rX/ For more details, see figure 4.1 and sectionrXXP **WARNING** This can take a very long time to run! Execution time scales as rX niter * setsizerXX'.. py:method:: plfit.xminvsks(**kwargs)rX :module: plfit.plfitrXXJ Plot xmin versus the ks value for derived alpha. This plot can be usedrXL as a diagnostic of whether you have derived the 'best' fit: if there are rXG multiple local minima, your data set may be well suited to a broken rX$ powerlaw or a different function.rXeh7NububhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX#alpha_() (plfit.plfit.plfit method)h UtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjQhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6jbh7jhIjIhNjhP}r(hU]rh ajhJX plfit.plfitrr}rbhT]hR]hS]hX]rh ajX plfit.alpha_rjj juhZNh[hh\]r(j)r}r(h6Xalpha_h7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXalpha_rr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rj)r}r(h6XxhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxr}r(h6Uh7jubahNj$ubaubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XCreate a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.rh7jhIjQhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXCreate a mappable function alpha to apply to each xmin in a list of xmins. This is essentially the slow version of fplfit/cplfit, though I bet it could be speeded up with a clever use of parellel_map. Not intended to be used by users.rr}r(h6jh7jubaubh)r}r(h6X,Docstring for the generated alpha function::h7jhIjQhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX+Docstring for the generated alpha function:rr}r(h6X+Docstring for the generated alpha function:h7jubaubh)r}r(h6XGiven a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized If there is only one element, return alpha=0h7jhIjQhNhhP}r(hnhohU]hT]hR]hS]hX]uhZKh[hh\]rheXGiven a sorted data set and a minimum, returns power law MLE fit data is passed as a keyword parameter so that it can be vectorized If there is only one element, return alpha=0rr}r(h6Uh7jubaubeubeubh)r}r(h6Uh7h>hI(hor}r(h]r(jzj{j|j}j~jjejKj]r(X(plfit.alphavsks(autozoom=True, **kwargs)rX:module: plfit.plfitrXXHPlot alpha versus the ks value for derived alpha. This plot can be usedrXIas a diagnostic of whether you have derived the 'best' fit: if there are rXDmultiple local minima, your data set may be well suited to a broken rX!powerlaw or a different function.reh7(hor}r(h]r(jzj{j|j}j~jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj j j j j jjejKj]r(jj Xj!j"j#j$Xj%j&Xj'Xj(j)j*j+j,j-j.j/j0j1j2j3Xj4j5Xj6Xj7Xj8j9Xj:Xj;j<Xj=j>Xj?j@XjAjBXjCjDjEXjFjGjHjIXjJXjKjLjMjNjOjPjQXjRjSjTjUXjVjWjXjYXjZj[j\Xj]j^Xj_j`XjajbXjcjdXjeXjfjgXjhXjijjXjkXjljmXjnXjoXjpjqXjrjsjtXjujvXjwXjxXjyjzXj{j|j}j~jjjXjjXjjXjjjjXeh7jkububhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX&alphavsks() (plfit.plfit.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6X(plfit.alphavsks(autozoom=True, **kwargs)h7jhIjIhNjhP}r(hU]rhajhJX plfit.plfitrr}rbhT]hR]hS]hX]rhajXplfit.alphavsksrjj juhZNh[hh\]r(j)r}r(h6X alphavsksh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheX alphavsksrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6X autozoom=TruehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX autozoom=Truerr }r (h6Uh7jubahNj$ubj)r }r (h6X**kwargshP}r (hR]hS]hT]hU]hX]uh7jh\]rheX**kwargsrr}r(h6Uh7j ubahNj$ubeubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr }r!(h6Uh7jubahNjIubahNhubaubeubh8)r"}r#(h6Uh7jhIjIhNjLhP}r$(hR]hS]hT]hU]hX]uhZNh[hh\]r%h)r&}r'(h6XPlot alpha versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.r(h7j"hIjhNhhP}r)(hR]hS]hT]hU]hX]uhZKh[hh\]r*heXPlot alpha versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.r+r,}r-(h6j(h7j&ubaubaubeubh)r.}r/(h6Uh7h>hI(hor0}r1(h]r2(jjjjjjjjjjjjjjjjjejKj]r3(Xoplfit.discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)r4X:module: plfit.plfitr5XX=Use the maximum L to determine the most likely value of alphar6XX*alpharangemults* [ 2-tuple ]r7XH Pair of values indicating multiplicative factors above and below ther8XD approximate alpha from the MLE alpha to use when determining ther9XB "exact" alpha (by directly maximizing the likelihood function)r:X*n_alpha* [ int ]r;XR Number of alpha values to use when measuring. Larger number is more accurate.r<X*approximate* [ bool ]r=XE If False, try to "zoom-in" around the MLE alpha and get the exactr>XB best alpha value within some range around the approximate bestr?X*vebose* [ bool ]r@X*finite* [ bool ]rAX Correction for finite data?rBeh7jubhNhhP}rC(hU]hT]hR]hS]hX]Uentries]rD(hX0discrete_best_alpha() (plfit.plfit.plfit method)hUtrEauhZNh[hh\]ubhhI(horH}rI(h]rJ(jjjjjjjjjjjejKj]rK(Xplfit.kstest_(x)rLX:module: plfit.plfitrMXXKCreate a mappable function kstest to apply to each xmin in a list of xmins.rNXX-Docstring for the generated kstest function::rOXXO Given a sorted data set and a minimum, returns power law MLE ks-test w/datarPXF data is passed as a keyword parameter so that it can be vectorizedrQXX; The returned value is the "D" parameter in the ks test.rReh7jubhNhhP}rS(hU]hT]hR]hS]hX]Uentries]rT(hX$kstest_() (plfit.plfit.plfit method)hUtrUauhZNh[hh\]ubh;)rV}rW(h6Uh7h>hIjHhNjhP}rX(jjXpyhU]hT]hR]hS]hX]jXmethodrYjjYuhZNh[hh\]rZ(j)r[}r\(h6jLh7jVhIjIhNjhP}r](hU]r^hajhJX plfit.plfitr_r`}rabhT]hR]hS]hX]rbhajX plfit.kstest_rcjj juhZNh[hh\]rd(j)re}rf(h6Xkstest_h7j[hIjIhNjhP}rg(hR]hS]hT]hU]hX]uhZNh[hh\]rhheXkstest_rirj}rk(h6Uh7jeubaubj)rl}rm(h6Uh7j[hIjIhNjhP}rn(hR]hS]hT]hU]hX]uhZNh[hh\]roj)rp}rq(h6XxhP}rr(hR]hS]hT]hU]hX]uh7jlh\]rsheXxrt}ru(h6Uh7jpubahNj$ubaubj2)rv}rw(h6Uh7j[hINhNj5hP}rx(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]ryh)rz}r{(h6UhP}r|(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjcuh7jvh\]r}j?)r~}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jzh\]rheX[source]rr}r(h6Uh7j~ubahNjIubahNhubaubeubh8)r}r(h6Uh7jVhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XKCreate a mappable function kstest to apply to each xmin in a list of xmins.rh7jhIjHhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXKCreate a mappable function kstest to apply to each xmin in a list of xmins.rr}r(h6jh7jubaubh)r}r(h6X-Docstring for the generated kstest function::h7jhIjHhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX,Docstring for the generated kstest function:rr}r(h6X,Docstring for the generated kstest function:h7jubaubh)r}r(h6XGiven a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test.h7jhIjHhNhhP}r(hnhohU]hT]hR]hS]hX]uhZKh[hh\]rheXGiven a sorted data set and a minimum, returns power law MLE ks-test w/data data is passed as a keyword parameter so that it can be vectorized The returned value is the "D" parameter in the ks test.rr}r(h6Uh7jubaubeubeubh)r}r(h6Uh7h>hI(hor}r(h]r(jjjjjejK&j]r(Xplfit.lognormal(doprint=True)rX:module: plfit.plfitrXXDUse the maximum likelihood estimator for a lognormal distribution torX)produce the best-fit lognormal parametersreh7jubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX&lognormal() (plfit.plfit.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6jh7jhIjIhNjhP}r(hU]rhajhJX plfit.plfitrr}rbhT]hR]hS]hX]rhajXplfit.lognormalrjj juhZNh[hh\]r(j)r}r(h6X lognormalh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheX lognormalrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rj)r}r(h6X doprint=TruehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX doprint=Truerr}r(h6Uh7jubahNj$ubaubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6XnUse the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parametersrh7jhIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXnUse the maximum likelihood estimator for a lognormal distribution to produce the best-fit lognormal parametersrr}r(h6jh7jubaubaubeubh)r}r(h6Uh7h>hINhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX"plfit() (plfit.plfit.plfit method)h'UtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hINhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6Xplfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)h7jhIjIhNjhP}r(hU]rh'ajhJX plfit.plfitrr}rbhT]hR]hS]hX]rh'ajX plfit.plfitrjj juhZNh[hh\]r(j)r}r(h6Xplfith7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplfitrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r }r (h6X nosmall=TruehP}r (hR]hS]hT]hU]hX]uh7jh\]r heX nosmall=Truer r}r(h6Uh7j ubahNj$ubj)r}r(h6X finite=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX finite=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X quiet=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX quiet=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X silent=FalsehP}r (hR]hS]hT]hU]hX]uh7jh\]r!heX silent=Falser"r#}r$(h6Uh7jubahNj$ubj)r%}r&(h6Xusefortran=FalsehP}r'(hR]hS]hT]hU]hX]uh7jh\]r(heXusefortran=Falser)r*}r+(h6Uh7j%ubahNj$ubj)r,}r-(h6X usecy=FalsehP}r.(hR]hS]hT]hU]hX]uh7jh\]r/heX usecy=Falser0r1}r2(h6Uh7j,ubahNj$ubj)r3}r4(h6X xmin=NonehP}r5(hR]hS]hT]hU]hX]uh7jh\]r6heX xmin=Noner7r8}r9(h6Uh7j3ubahNj$ubj)r:}r;(h6X verbose=FalsehP}r<(hR]hS]hT]hU]hX]uh7jh\]r=heX verbose=Falser>r?}r@(h6Uh7j:ubahNj$ubj)rA}rB(h6X discrete=NonehP}rC(hR]hS]hT]hU]hX]uh7jh\]rDheX discrete=NonerErF}rG(h6Uh7jAubahNj$ubj)rH}rI(h6Xdiscrete_approx=TruehP}rJ(hR]hS]hT]hU]hX]uh7jh\]rKheXdiscrete_approx=TruerLrM}rN(h6Uh7jHubahNj$ubj)rO}rP(h6Xdiscrete_n_alpha=1000hP}rQ(hR]hS]hT]hU]hX]uh7jh\]rRheXdiscrete_n_alpha=1000rSrT}rU(h6Uh7jOubahNj$ubeubj2)rV}rW(h6Uh7jhINhNj5hP}rX(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rYh)rZ}r[(h6UhP}r\(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jVh\]r]j?)r^}r_(h6UhP}r`(hR]hS]rajDahT]hU]hX]uh7jZh\]rbheX[source]rcrd}re(h6Uh7j^ubahNjIubahNhubaubeubh8)rf}rg(h6Uh7jhIjIhNjLhP}rh(hR]hS]hT]hU]hX]uhZNh[hh\]ri(h)rj}rk(h6XA Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.m from http://www.santafe.edu/~aaronc/powerlaws/h7jfhI(horl}rm(h]rn(jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjejK,j]ro(Xplfit.plfit(nosmall=True, finite=False, quiet=False, silent=False, usefortran=False, usecy=False, xmin=None, verbose=False, discrete=None, discrete_approx=True, discrete_n_alpha=1000)rpX:module: plfit.plfitrqXX[A Python implementation of the Matlab code http://www.santafe.edu/~aaronc/powerlaws/plfit.mrrX.from http://www.santafe.edu/~aaronc/powerlaws/rsXXISee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributionsrtXEin empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062)ruXhttp://arxiv.org/abs/0706.1062rvXX_There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython)rwXVversion is ~10% slower, and the python version is ~3x slower than the fortran version.rxX`Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknownryXreasons.rzXXdThere is also a discrete version implemented in python - it is different from the continous version!r{XX*discrete* [ bool | None ]r|XE If *discrete* is None, the code will try to determine whether ther}XD data set is discrete or continous based on the uniqueness of ther~XD data; if your data set is continuous but you have any non-uniquerX; data points (e.g., flagged "bad" data), the "automatic"rXA determination will fail. If *discrete* is True or False, therX> distcrete or continuous fitter will be used, respectively.rXX*xmin* [ float / int ]rXF If you specify xmin, the fitter will only determine alpha assumingrXE the given xmin; the rest of the code (and most of the complexity)rX2 is determining an estimate for xmin and alpha.rXX*nosmall* [ bool (True) ]rXD When on, the code rejects low s/n points. WARNING: This option,rXD which is on by default, may result in different answers than therX: original Matlab code and the "powerlaw" python packagerXX*finite* [ bool (False) ]rXR There is a 'finite-size bias' to the estimator. The "alpha" the code measuresrXJ is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nrXX*quiet* [ bool (False) ]rXM If False, delivers messages about what fitter is used and the fit resultsrXX*verbose* [ bool (False) ] rXR Deliver descriptive messages about the fit parameters (only if *quiet*==False)rXX*silent* [ bool (False) ] rX# If True, will print NO messagesreh7jubhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]r(heX+A Python implementation of the Matlab code rr}r(h6X+A Python implementation of the Matlab code h7jjubj)r}r(h6X0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrhP}r(UrefurijhU]hT]hR]hS]hX]uh7jjh\]rheX0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrr}r(h6Uh7jubahNjubheX from rr}r(h6X from h7jjubj)r}r(h6X)http://www.santafe.edu/~aaronc/powerlaws/rhP}r(UrefurijhU]hT]hR]hS]hX]uh7jjh\]rheX)http://www.santafe.edu/~aaronc/powerlaws/rr}r(h6Uh7jubahNjubeubh)r}r(h6XSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rh7jfhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXSee A. Clauset, C.R. Shalizi, and M.E.J. Newman, "Power-law distributions in empirical data" SIAM Review, 51, 661-703 (2009). (arXiv:0706.1062) http://arxiv.org/abs/0706.1062rr}r(h6jh7jubaubh)r}r(h6X There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython) version is ~10% slower, and the python version is ~3x slower than the fortran version. Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknown reasons.rh7jfhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZK h[hh\]rheX There are 3 implementations of xmin estimation. The fortran version is fastest, the C (cython) version is ~10% slower, and the python version is ~3x slower than the fortran version. Also, the cython code suffers ~2% numerical error relative to the fortran and python for unknown reasons.rr}r(h6jh7jubaubh)r}r(h6XdThere is also a discrete version implemented in python - it is different from the continous version!rh7jfhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXdThere is also a discrete version implemented in python - it is different from the continous version!rr}r(h6jh7jubaubj )r}r(h6Uh7jfhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j )r}r(h6X*discrete* [ bool | None ] If *discrete* is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If *discrete* is True or False, the distcrete or continuous fitter will be used, respectively. h7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZKh\]r(j )r}r(h6X*discrete* [ bool | None ]rh7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZKh\]r(h)r}r(h6X *discrete*hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXdiscreterr}r(h6Uh7jubahNhubheX [ bool | None ]rr}r(h6X [ bool | None ]h7jubeubj )r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rh)r}r(h6XtIf *discrete* is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If *discrete* is True or False, the distcrete or continuous fitter will be used, respectively.h7jhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZKh\]r(heXIf rr}r(h6XIf h7jubh)r}r(h6X *discrete*hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXdiscreterr}r(h6Uh7jubahNhubheX  is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If rr}r(h6X  is None, the code will try to determine whether the data set is discrete or continous based on the uniqueness of the data; if your data set is continuous but you have any non-unique data points (e.g., flagged "bad" data), the "automatic" determination will fail. If h7jubh)r}r(h6X *discrete*hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXdiscreterr}r(h6Uh7jubahNhubheXQ is True or False, the distcrete or continuous fitter will be used, respectively.rr}r(h6XQ is True or False, the distcrete or continuous fitter will be used, respectively.h7jubeubahNj ubeubj )r}r(h6X*xmin* [ float / int ] If you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha. h7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZKh[hh\]r(j )r}r(h6X*xmin* [ float / int ]rh7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZKh\]r(h)r}r(h6X*xmin*hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXxminrr}r (h6Uh7jubahNhubheX [ float / int ]r r }r (h6X [ float / int ]h7jubeubj )r }r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rh)r}r(h6XIf you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha.rh7j hIjlhNhhP}r(hR]hS]hT]hU]hX]uhZKh\]rheXIf you specify xmin, the fitter will only determine alpha assuming the given xmin; the rest of the code (and most of the complexity) is determining an estimate for xmin and alpha.rr}r(h6jh7jubaubahNj ubeubj )r}r(h6X*nosmall* [ bool (True) ] When on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the "powerlaw" python package h7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZK!h[hh\]r(j )r}r(h6X*nosmall* [ bool (True) ]rh7jhIjlhNj hP}r (hR]hS]hT]hU]hX]uhZK!h\]r!(h)r"}r#(h6X *nosmall*hP}r$(hR]hS]hT]hU]hX]uh7jh\]r%heXnosmallr&r'}r((h6Uh7j"ubahNhubheX [ bool (True) ]r)r*}r+(h6X [ bool (True) ]h7jubeubj )r,}r-(h6UhP}r.(hR]hS]hT]hU]hX]uh7jh\]r/h)r0}r1(h6XWhen on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the "powerlaw" python packager2h7j,hIjlhNhhP}r3(hR]hS]hT]hU]hX]uhZKh\]r4heXWhen on, the code rejects low s/n points. WARNING: This option, which is on by default, may result in different answers than the original Matlab code and the "powerlaw" python packager5r6}r7(h6j2h7j0ubaubahNj ubeubj )r8}r9(h6X*finite* [ bool (False) ] There is a 'finite-size bias' to the estimator. The "alpha" the code measures is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / n h7jhIjlhNj hP}r:(hR]hS]hT]hU]hX]uhZK%h[hh\]r;(j )r<}r=(h6X*finite* [ bool (False) ]r>h7j8hIjlhNj hP}r?(hR]hS]hT]hU]hX]uhZK%h\]r@(h)rA}rB(h6X*finite*hP}rC(hR]hS]hT]hU]hX]uh7j<h\]rDheXfiniterErF}rG(h6Uh7jAubahNhubheX [ bool (False) ]rHrI}rJ(h6X [ bool (False) ]h7j<ubeubj )rK}rL(h6UhP}rM(hR]hS]hT]hU]hX]uh7j8h\]rNh)rO}rP(h6XThere is a 'finite-size bias' to the estimator. The "alpha" the code measures is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nrQh7jKhIjlhNhhP}rR(hR]hS]hT]hU]hX]uhZK$h\]rSheXThere is a 'finite-size bias' to the estimator. The "alpha" the code measures is "alpha-hat" s.t. ᾶ = (nα-1)/(n-1), or α = (1 + ᾶ (n-1)) / nrTrU}rV(h6jQh7jOubaubahNj ubeubj )rW}rX(h6Xc*quiet* [ bool (False) ] If False, delivers messages about what fitter is used and the fit results h7jhIjlhNj hP}rY(hR]hS]hT]hU]hX]uhZK(h[hh\]rZ(j )r[}r\(h6X*quiet* [ bool (False) ]r]h7jWhIjlhNj hP}r^(hR]hS]hT]hU]hX]uhZK(h\]r_(h)r`}ra(h6X*quiet*hP}rb(hR]hS]hT]hU]hX]uh7j[h\]rcheXquietrdre}rf(h6Uh7j`ubahNhubheX [ bool (False) ]rgrh}ri(h6X [ bool (False) ]h7j[ubeubj )rj}rk(h6UhP}rl(hR]hS]hT]hU]hX]uh7jWh\]rmh)rn}ro(h6XIIf False, delivers messages about what fitter is used and the fit resultsrph7jjhIjlhNhhP}rq(hR]hS]hT]hU]hX]uhZK(h\]rrheXIIf False, delivers messages about what fitter is used and the fit resultsrsrt}ru(h6jph7jnubaubahNj ubeubj )rv}rw(h6Xk*verbose* [ bool (False) ] Deliver descriptive messages about the fit parameters (only if *quiet*==False) h7jhIjlhNj hP}rx(hR]hS]hT]hU]hX]uhZK+h[hh\]ry(j )rz}r{(h6X*verbose* [ bool (False) ] r|h7jvhIjlhNj hP}r}(hR]hS]hT]hU]hX]uhZK+h\]r~(h)r}r(h6X *verbose*hP}r(hR]hS]hT]hU]hX]uh7jzh\]rheXverboserr}r(h6Uh7jubahNhubheX [ bool (False) ] rr}r(h6X [ bool (False) ] h7jzubeubj )r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jvh\]rh)r}r(h6XNDeliver descriptive messages about the fit parameters (only if *quiet*==False)h7jhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZK+h\]r(heX?Deliver descriptive messages about the fit parameters (only if rr}r(h6X?Deliver descriptive messages about the fit parameters (only if h7jubj)r}r(h6X*hP}r(hU]rUid2rahT]hR]hS]hX]UrefidUid1ruh7jh\]rheX*r}r(h6Uh7jubahNjubheXquiet*==False)rr}r(h6Xquiet*==False)h7jubeubahNj ubeubj )r}r(h6X;*silent* [ bool (False) ] If True, will print NO messages h7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZK.h[hh\]r(j )r}r(h6X*silent* [ bool (False) ] rh7jhIjlhNj hP}r(hR]hS]hT]hU]hX]uhZK.h\]r(h)r}r(h6X*silent*hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXsilentrr}r(h6Uh7jubahNhubheX [ bool (False) ] rr}r(h6X [ bool (False) ] h7jubeubj )r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rh)r}r(h6XIf True, will print NO messagesrh7jhIjlhNhhP}r(hR]hS]hT]hU]hX]uhZK.h\]rheXIf True, will print NO messagesrr}r(h6jh7jubaubahNj ubeubeubeubeubh)r}r(h6Uh7h>hI(hor}r(h]r(jjjjejK\j]r(X"plfit.plot_lognormal_cdf(**kwargs)rX:module: plfit.plfitrXX&Plot the fitted lognormal distributionreh7jubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX/plot_lognormal_cdf() (plfit.plfit.plfit method)h$UtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6jh7jhIjIhNjhP}r(hU]rh$ajhJX plfit.plfitrr}rbhT]hR]hS]hX]rh$ajXplfit.plot_lognormal_cdfrjj juhZNh[hh\]r(j)r}r(h6Xplot_lognormal_cdfh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplot_lognormal_cdfrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rj)r}r(h6X**kwargshP}r(hR]hS]hT]hU]hX]uh7jh\]rheX**kwargsrr}r(h6Uh7jubahNj$ubaubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7jhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6X&Plot the fitted lognormal distributionrh7jhIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheX&Plot the fitted lognormal distributionrr}r(h6jh7jubaubaubeubh)r}r (h6Uh7h>hI(hor }r (h]r (jjjjejKaj]r (X"plfit.plot_lognormal_pdf(**kwargs)rX:module: plfit.plfitrXX&Plot the fitted lognormal distributionreh7jubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX/plot_lognormal_pdf() (plfit.plfit.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIj hNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6jh7jhIjIhNjhP}r(hU]rhajhJX plfit.plfitrr}rbhT]hR]hS]hX]r hajXplfit.plot_lognormal_pdfr!jj juhZNh[hh\]r"(j)r#}r$(h6Xplot_lognormal_pdfh7jhIjIhNjhP}r%(hR]hS]hT]hU]hX]uhZNh[hh\]r&heXplot_lognormal_pdfr'r(}r)(h6Uh7j#ubaubj)r*}r+(h6Uh7jhIjIhNjhP}r,(hR]hS]hT]hU]hX]uhZNh[hh\]r-j)r.}r/(h6X**kwargshP}r0(hR]hS]hT]hU]hX]uh7j*h\]r1heX**kwargsr2r3}r4(h6Uh7j.ubahNj$ubaubj2)r5}r6(h6Uh7jhINhNj5hP}r7(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r8h)r9}r:(h6UhP}r;(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj!uh7j5h\]r<j?)r=}r>(h6UhP}r?(hR]hS]r@jDahT]hU]hX]uh7j9h\]rAheX[source]rBrC}rD(h6Uh7j=ubahNjIubahNhubaubeubh8)rE}rF(h6Uh7jhIjIhNjLhP}rG(hR]hS]hT]hU]hX]uhZNh[hh\]rHh)rI}rJ(h6X&Plot the fitted lognormal distributionrKh7jEhIj hNhhP}rL(hR]hS]hT]hU]hX]uhZKh[hh\]rMheX&Plot the fitted lognormal distributionrNrO}rP(h6jKh7jIubaubaubeubh)rQ}rR(h6Uh7h>hI(horS}rT(h]rU(jjjjejKfj]rV(XWplfit.plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)rWX:module: plfit.plfitrXXXPlots CDF and powerlawrYeh7jubhNhhP}rZ(hU]hT]hR]hS]hX]Uentries]r[(hX$plotcdf() (plfit.plfit.plfit method)h Utr\auhZNh[hh\]ubh;)r]}r^(h6Uh7h>hIjShNjhP}r_(jjXpyhU]hT]hR]hS]hX]jXmethodr`jj`uhZNh[hh\]ra(j)rb}rc(h6XWplfit.plotcdf(x=None, xmin=None, alpha=None, pointcolor='k', pointmarker='+', **kwargs)h7j]hIjIhNjhP}rd(hU]reh ajhJX plfit.plfitrfrg}rhbhT]hR]hS]hX]rih ajX plfit.plotcdfrjjj juhZNh[hh\]rk(j)rl}rm(h6Xplotcdfh7jbhIjIhNjhP}rn(hR]hS]hT]hU]hX]uhZNh[hh\]roheXplotcdfrprq}rr(h6Uh7jlubaubj)rs}rt(h6Uh7jbhIjIhNjhP}ru(hR]hS]hT]hU]hX]uhZNh[hh\]rv(j)rw}rx(h6Xx=NonehP}ry(hR]hS]hT]hU]hX]uh7jsh\]rzheXx=Noner{r|}r}(h6Uh7jwubahNj$ubj)r~}r(h6X xmin=NonehP}r(hR]hS]hT]hU]hX]uh7jsh\]rheX xmin=Nonerr}r(h6Uh7j~ubahNj$ubj)r}r(h6X alpha=NonehP}r(hR]hS]hT]hU]hX]uh7jsh\]rheX alpha=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6Xpointcolor='k'hP}r(hR]hS]hT]hU]hX]uh7jsh\]rheXpointcolor='k'rr}r(h6Uh7jubahNj$ubj)r}r(h6Xpointmarker='+'hP}r(hR]hS]hT]hU]hX]uh7jsh\]rheXpointmarker='+'rr}r(h6Uh7jubahNj$ubj)r}r(h6X**kwargshP}r(hR]hS]hT]hU]hX]uh7jsh\]rheX**kwargsrr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jbhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7j]hIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6XPlots CDF and powerlawrh7jhIjShNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXPlots CDF and powerlawrr}r(h6jh7jubaubaubeubh)r}r(h6Uh7h>hI(hor}r(h]r(jjjjjjejKkj]r(Xplfit.plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)rX:module: plfit.plfitrXXPlots PDF and powerlaw.rXX-kwargs is passed to pylab.hist and pylab.plotreh7jubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX$plotpdf() (plfit.plfit.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6Xplfit.plotpdf(x=None, xmin=None, alpha=None, nbins=50, dolog=True, dnds=False, drawstyle='steps-post', histcolor='k', plcolor='r', **kwargs)h7jhIjIhNjhP}r(hU]rhajhJX plfit.plfitrr}rbhT]hR]hS]hX]rhajX plfit.plotpdfrjj juhZNh[hh\]r(j)r}r(h6Xplotpdfh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXplotpdfrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6Xx=NonehP}r(hR]hS]hT]hU]hX]uh7jh\]rheXx=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6X xmin=NonehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX xmin=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6X alpha=NonehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX alpha=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6Xnbins=50hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXnbins=50rr}r(h6Uh7jubahNj$ubj)r}r(h6X dolog=TruehP}r(hR]hS]hT]hU]hX]uh7jh\]rheX dolog=Truerr}r(h6Uh7jubahNj$ubj)r}r(h6X dnds=FalsehP}r (hR]hS]hT]hU]hX]uh7jh\]r heX dnds=Falser r }r (h6Uh7jubahNj$ubj)r}r(h6Xdrawstyle='steps-post'hP}r(hR]hS]hT]hU]hX]uh7jh\]rheXdrawstyle='steps-post'rr}r(h6Uh7jubahNj$ubj)r}r(h6X histcolor='k'hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX histcolor='k'rr}r(h6Uh7jubahNj$ubj)r}r(h6X plcolor='r'hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX plcolor='r'r r!}r"(h6Uh7jubahNj$ubj)r#}r$(h6X**kwargshP}r%(hR]hS]hT]hU]hX]uh7jh\]r&heX**kwargsr'r(}r)(h6Uh7j#ubahNj$ubeubj2)r*}r+(h6Uh7jhINhNj5hP}r,(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]r-h)r.}r/(h6UhP}r0(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7j*h\]r1j?)r2}r3(h6UhP}r4(hR]hS]r5jDahT]hU]hX]uh7j.h\]r6heX[source]r7r8}r9(h6Uh7j2ubahNjIubahNhubaubeubh8)r:}r;(h6Uh7jhIjIhNjLhP}r<(hR]hS]hT]hU]hX]uhZNh[hh\]r=(h)r>}r?(h6XPlots PDF and powerlaw.r@h7j:hIjhNhhP}rA(hR]hS]hT]hU]hX]uhZKh[hh\]rBheXPlots PDF and powerlaw.rCrD}rE(h6j@h7j>ubaubh)rF}rG(h6X-kwargs is passed to pylab.hist and pylab.plotrHh7j:hIjhNhhP}rI(hR]hS]hT]hU]hX]uhZKh[hh\]rJheX-kwargs is passed to pylab.hist and pylab.plotrKrL}rM(h6jHh7jFubaubeubeubh)rN}rO(h6Uh7h>hI(horP}rQ(h]rR(jjjjjjejKrj]rS(XBplfit.plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)rTX:module: plfit.plfitrUXXBPlots the power-law-predicted value on the Y-axis against the realrVXAvalues along the X-axis. Can be used as a diagnostic of the fit rWXquality.rXeh7jubhNhhP}rY(hU]hT]hR]hS]hX]Uentries]rZ(hX$plotppf() (plfit.plfit.plfit method)h*Utr[auhZNh[hh\]ubh;)r\}r](h6Uh7h>hIjPhNjhP}r^(jjXpyhU]hT]hR]hS]hX]jXmethodr_jj_uhZNh[hh\]r`(j)ra}rb(h6XBplfit.plotppf(x=None, xmin=None, alpha=None, dolog=True, **kwargs)h7j\hIjIhNjhP}rc(hU]rdh*ajhJX plfit.plfitrerf}rgbhT]hR]hS]hX]rhh*ajX plfit.plotppfrijj juhZNh[hh\]rj(j)rk}rl(h6Xplotppfh7jahIjIhNjhP}rm(hR]hS]hT]hU]hX]uhZNh[hh\]rnheXplotppfrorp}rq(h6Uh7jkubaubj)rr}rs(h6Uh7jahIjIhNjhP}rt(hR]hS]hT]hU]hX]uhZNh[hh\]ru(j)rv}rw(h6Xx=NonehP}rx(hR]hS]hT]hU]hX]uh7jrh\]ryheXx=Nonerzr{}r|(h6Uh7jvubahNj$ubj)r}}r~(h6X xmin=NonehP}r(hR]hS]hT]hU]hX]uh7jrh\]rheX xmin=Nonerr}r(h6Uh7j}ubahNj$ubj)r}r(h6X alpha=NonehP}r(hR]hS]hT]hU]hX]uh7jrh\]rheX alpha=Nonerr}r(h6Uh7jubahNj$ubj)r}r(h6X dolog=TruehP}r(hR]hS]hT]hU]hX]uh7jrh\]rheX dolog=Truerr}r(h6Uh7jubahNj$ubj)r}r(h6X**kwargshP}r(hR]hS]hT]hU]hX]uh7jrh\]rheX**kwargsrr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jahINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjiuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]rr}r(h6Uh7jubahNjIubahNhubaubeubh8)r}r(h6Uh7j\hIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6XPlots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality.rh7jhIjPhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXPlots the power-law-predicted value on the Y-axis against the real values along the X-axis. Can be used as a diagnostic of the fit quality.rr}r(h6jh7jubaubaubeubh)r}r(h6Uh7h>hI(hor}r(h]r(jjjjjjjjjjjjjjjjjjjjejKyj]r(X9plfit.test_pl(niter=1000.0, print_timing=False, **kwargs)rX:module: plfit.plfitrXXQMonte-Carlo test to determine whether distribution is consistent with a power lawrXXRRuns through niter iterations of a sample size identical to the input sample size.rXXUWill randomly select values from the data < xmin. The number of values selected willrXHbe chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential,rXQand n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL.rX,For more details, see figure 4.1 and sectionrXXM**WARNING** This can take a very long time to run! Execution time scales as rXniter * setsizereh7jubhNhhP}r(hU]hT]hR]hS]hX]Uentries]r(hX$test_pl() (plfit.plfit.plfit method)hUtrauhZNh[hh\]ubh;)r}r(h6Uh7h>hIjhNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6X9plfit.test_pl(niter=1000.0, print_timing=False, **kwargs)h7jhIjIhNjhP}r(hU]rhajhJX plfit.plfitrr}rbhT]hR]hS]hX]rhajX plfit.test_plrjj juhZNh[hh\]r(j)r}r(h6Xtest_plh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rheXtest_plrr}r(h6Uh7jubaubj)r}r(h6Uh7jhIjIhNjhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(j)r}r(h6X niter=1000.0hP}r(hR]hS]hT]hU]hX]uh7jh\]rheX niter=1000.0rr}r(h6Uh7jubahNj$ubj)r}r(h6Xprint_timing=FalsehP}r(hR]hS]hT]hU]hX]uh7jh\]rheXprint_timing=Falserr}r(h6Uh7jubahNj$ubj)r}r(h6X**kwargshP}r(hR]hS]hT]hU]hX]uh7jh\]rheX**kwargsrr}r(h6Uh7jubahNj$ubeubj2)r}r(h6Uh7jhINhNj5hP}r(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rh)r}r(h6UhP}r(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidjuh7jh\]rj?)r}r(h6UhP}r(hR]hS]rjDahT]hU]hX]uh7jh\]rheX[source]r r }r (h6Uh7jubahNjIubahNhubaubeubh8)r }r (h6Uh7jhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]r(h)r}r(h6XQMonte-Carlo test to determine whether distribution is consistent with a power lawrh7j hIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXQMonte-Carlo test to determine whether distribution is consistent with a power lawrr}r(h6jh7jubaubh)r}r(h6XRRuns through niter iterations of a sample size identical to the input sample size.rh7j hIjhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXRRuns through niter iterations of a sample size identical to the input sample size.rr}r(h6jh7jubaubh)r }r!(h6XWill randomly select values from the data < xmin. The number of values selected will be chosen from a uniform random distribution with p(xmin)>100 is required to distinguish a PL from an exponential, and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL. For more details, see figure 4.1 and sectionr*h7j hIjhNhhP}r+(hR]hS]hT]hU]hX]uhZK h[hh\]r,heX0Once the sample is created, it is fit using above methods, then the best fit is used to compute a Kolmogorov-Smirnov statistic. The KS stat distribution is compared to the KS value for the fit to the actual data, and p = fraction of random ks values greater than the data ks value is computed. If p<.1, the data may be inconsistent with a powerlaw. A data set of n(>xmin)>100 is required to distinguish a PL from an exponential, and n(>xmin)>~300 is required to distinguish a log-normal distribution from a PL. For more details, see figure 4.1 and sectionr-r.}r/(h6j*h7j(ubaubh)r0}r1(h6X]**WARNING** This can take a very long time to run! Execution time scales as niter * setsizeh7j hIjhNhhP}r2(hR]hS]hT]hU]hX]uhZKh[hh\]r3(cdocutils.nodes strong r4)r5}r6(h6X **WARNING**hP}r7(hR]hS]hT]hU]hX]uh7j0h\]r8heXWARNINGr9r:}r;(h6Uh7j5ubahNUstrongr<ubheXR This can take a very long time to run! Execution time scales as niter * setsizer=r>}r?(h6XR This can take a very long time to run! Execution time scales as niter * setsizeh7j0ubeubeubeubh)r@}rA(h6Uh7h>hI(horB}rC(h]rD(jj j j j j jejKj]rE(Xplfit.xminvsks(**kwargs)rFX:module: plfit.plfitrGXXGPlot xmin versus the ks value for derived alpha. This plot can be usedrHXIas a diagnostic of whether you have derived the 'best' fit: if there are rIXDmultiple local minima, your data set may be well suited to a broken rJX!powerlaw or a different function.rKeh7jubhNhhP}rL(hU]hT]hR]hS]hX]Uentries]rM(hX%xminvsks() (plfit.plfit.plfit method)hUtrNauhZNh[hh\]ubh;)rO}rP(h6Uh7h>hIjBhNjhP}rQ(jjXpyhU]hT]hR]hS]hX]jXmethodrRjjRuhZNh[hh\]rS(j)rT}rU(h6jFh7jOhIjIhNjhP}rV(hU]rWhajhJX plfit.plfitrXrY}rZbhT]hR]hS]hX]r[hajXplfit.xminvsksr\jj juhZNh[hh\]r](j)r^}r_(h6Xxminvsksh7jThIjIhNjhP}r`(hR]hS]hT]hU]hX]uhZNh[hh\]raheXxminvsksrbrc}rd(h6Uh7j^ubaubj)re}rf(h6Uh7jThIjIhNjhP}rg(hR]hS]hT]hU]hX]uhZNh[hh\]rhj)ri}rj(h6X**kwargshP}rk(hR]hS]hT]hU]hX]uh7jeh\]rlheX**kwargsrmrn}ro(h6Uh7jiubahNj$ubaubj2)rp}rq(h6Uh7jThINhNj5hP}rr(Uexprj7hU]hT]hR]hS]hX]uhZNh[hh\]rsh)rt}ru(h6UhP}rv(Ureftypej<UrefdochU refdomainj=hU]hT]U refexplicithR]hS]hX]U reftargetX_modules/plfit/plfitUrefidj\uh7jph\]rwj?)rx}ry(h6UhP}rz(hR]hS]r{jDahT]hU]hX]uh7jth\]r|heX[source]r}r~}r(h6Uh7jxubahNjIubahNhubaubeubh8)r}r(h6Uh7jOhIjIhNjLhP}r(hR]hS]hT]hU]hX]uhZNh[hh\]rh)r}r(h6XPlot xmin versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.rh7jhIjBhNhhP}r(hR]hS]hT]hU]hX]uhZKh[hh\]rheXPlot xmin versus the ks value for derived alpha. This plot can be used as a diagnostic of whether you have derived the 'best' fit: if there are multiple local minima, your data set may be well suited to a broken powerlaw or a different function.rr}r(h6jh7jubaubaubeubeubhIj0hNjhP}r(jjXpyhU]hT]hR]hS]hX]jXmethodrjjuhZNh[hh\]r(j)r}r(h6Xoplfit.discrete_best_alpha(alpharangemults=(0.9, 1.1), n_alpha=201, approximate=True, verbose=True, finite=True)h7h}r?(h6XIf False, try to "zoom-in" around the MLE alpha and get the exact best alpha value within some range around the approximate bestr@h7j:hIj0hNhhP}rA(hR]hS]hT]hU]hX]uhZK h\]rBheXIf False, try to "zoom-in" around the MLE alpha and get the exact best alpha value within some range around the approximate bestrCrD}rE(h6j@h7j>ubaubahNj ubeubeubh)rF}rG(h6X#*vebose* [ bool ] *finite* [ bool ]h7h9hIj0hNhhP}rH(hR]hS]hT]hU]hX]uhZKh[hh\]rI(h)rJ}rK(h6X*vebose*hP}rL(hR]hS]hT]hU]hX]uh7jFh\]rMheXveboserNrO}rP(h6Uh7jJubahNhubheX [ bool ] rQrR}rS(h6X [ bool ] h7jFubh)rT}rU(h6X*finite*hP}rV(hR]hS]hT]hU]hX]uh7jFh\]rWheXfiniterXrY}rZ(h6Uh7jTubahNhubheX [ bool ]r[r\}r](h6X [ bool ]h7jFubeubcdocutils.nodes block_quote r^)r_}r`(h6Uh7h9hIj0hNU block_quoterahP}rb(hR]hS]hT]hU]hX]uhZNh[hh\]rch)rd}re(h6XCorrection for finite data?rfh7j_hIj0hNhhP}rg(hR]hS]hT]hU]hX]uhZKh\]rhheXCorrection for finite data?rirj}rk(h6jfh7jdubaubaubeubhIj0hNUsystem_messagerlhP}rm(hR]UlevelKhU]hT]Usourcej+hS]hX]UlineKUtypeUWARNINGrnuhZK h[hh\]roh)rp}rq(h6UhP}rr(hR]hS]hT]hU]hX]uh7h4h\]rsheX?Definition list ends without a blank line; unexpected unindent.rtru}rv(h6Uh7jpubahNhubaubh3)rw}rx(h6Uh7h9hIj0hNjlhP}ry(hR]UlevelKhU]hT]Usourcej0hS]hX]UlineKUtypeUERRORrzuhZKh[hh\]r{h)r|}r}(h6UhP}r~(hR]hS]hT]hU]hX]uh7jwh\]rheXUnexpected indentation.rr}r(h6Uh7j|ubahNhubaubh3)r}r(h6UhP}r(hR]UlevelKhU]rjahT]rjaUsourcej\hS]hX]UlineKUtypejnuh7jh\]rh)r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rheX0Inline emphasis start-string without end-string.rr}r(h6Uh7jubahNhubahNjlubeUcurrent_sourcerNU decorationrNUautofootnote_startrKUnameidsr}r(hhhhhhh h h h h h h h h h hhhhhhhhhhhhWhhhhhhhhhhhhhhhhhj/hhhhhhh h h!h!h"h"h#h#h$h$h%j h&h&h'h'h(h(h)h)h*h*h+hh,jBh-h-h.h.uh\]rhGah6UU transformerrNU footnote_refsr}rUrefnamesr}r(X)http://www.santafe.edu/~aaronc/powerlaws/r]rj)r}r(h6j"hP}r(UnamejhU]hT]hR]UrefnamerjhS]hX]uh7jGh\]rheX)http://www.santafe.edu/~aaronc/powerlaws/rr}r(h6Uh7jubahNjubaX0http://www.santafe.edu/~aaronc/powerlaws/plfit.mr]rj)r}r(h6jhP}r(UnamejhU]hT]hR]jjhS]hX]uh7jGh\]rheX0http://www.santafe.edu/~aaronc/powerlaws/plfit.mrr}r(h6Uh7jubahNjubauUsymbol_footnotesr]rUautofootnote_refsr]rUsymbol_footnote_refsr]rU citationsr]rh[hU current_linerNUtransform_messagesr]r(h3)r}r(h6UhP}r(hR]UlevelKhU]rjahT]rjaUsourcejIhS]hX]UlineKUtypejzuh\]rh)r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXHUnknown target name: "http://www.santafe.edu/~aaronc/powerlaws/plfit.m".rr}r(h6Uh7jubahNhubahNjlubh3)r}r(h6UhP}r(hR]UlevelKhU]rj&ahT]rj%aUsourcejIhS]hX]UlineKUtypejzuh\]rh)r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rheXAUnknown target name: "http://www.santafe.edu/~aaronc/powerlaws/".rr}r(h6Uh7jubahNhubahNjlubh3)r}r(h6UhP}r(hR]UlevelKhU]hT]UsourcehhS]hX]UlineKUtypeUINFOruh\]rh)r}r(h6UhP}r(hR]hS]hT]hU]hX]uh7jh\]rheX;Hyperlink target "module-plfit.plfit_py" is not referenced.rr}r(h6Uh7jubahNhubahNjlubeUreporterrNUid_startrKU autofootnotesr]rU citation_refsr}rUindirect_targetsr]rUsettingsr(cdocutils.frontend Values ror}r(Ufootnote_backlinksrKUrecord_dependenciesrNU rfc_base_urlrUhttp://tools.ietf.org/html/rU tracebackrUpep_referencesrNUstrip_commentsrNU toc_backlinksrUentryrU language_coderUenrU datestamprNU report_levelrKU _destinationrNU halt_levelrKU strip_classesrNhbNUerror_encoding_error_handlerrUbackslashreplacerUdebugrNUembed_stylesheetrUoutput_encoding_error_handlerrUstrictrU sectnum_xformrKUdump_transformsrNU docinfo_xformrKUwarning_streamrNUpep_file_url_templaterUpep-%04drUexit_status_levelrKUconfigrNUstrict_visitorr NUcloak_email_addressesr Utrim_footnote_reference_spacer Uenvr NUdump_pseudo_xmlr NUexpose_internalsrNUsectsubtitle_xformrU source_linkrNUrfc_referencesrNUoutput_encodingrUutf-8rU source_urlrNUinput_encodingrU utf-8-sigrU_disable_configrNU id_prefixrUU tab_widthrKUerror_encodingrUUTF-8rU_sourcerUh}q?(h]h]h]h]h]uhKhhh ]q@h'X.qA}qB(h X.hhNUerror_encoding_error_handlerqUbackslashreplaceqUdebugqNUembed_stylesheetqUoutput_encoding_error_handlerqUstrictqU sectnum_xformqKUdump_transformsqNU docinfo_xformqKUwarning_streamqNUpep_file_url_templateqUpep-%04dqUexit_status_levelqKUconfigqNUstrict_visitorqNUcloak_email_addressesqUtrim_footnote_reference_spaceqUenvqNUdump_pseudo_xmlqNUexpose_internalsqNUsectsubtitle_xformqU source_linkqNUrfc_referencesqNUoutput_encodingqUutf-8qU source_urlqNUinput_encodingqU utf-8-sigqU_disable_configqNU id_prefixqUU tab_widthqKUerror_encodingqUUTF-8qU_sourceqU=/var/build/user_builds/plfit/checkouts/latest/doc/modules.rstqUgettext_compactqU generatorqNUdump_internalsqNU smart_quotesqU pep_base_urlqUhttp://www.python.org/dev/peps/qUsyntax_highlightqUlongqUinput_encoding_error_handlerqhUauto_id_prefixqUidqUdoctitle_xformqUstrip_elements_with_classesqNU _config_filesq]Ufile_insertion_enabledqU raw_enabledqKU dump_settingsqNubUsymbol_footnote_startqKUidsq}qh1h4sUsubstitution_namesq}qhhh}q(h]h]h]Usourcehh]h]uU footnotesq]qUrefidsq}qub.PK] -Daplfit-latest/_static/plus.pngPNG  IHDR &q pHYs  tIME 1l9tEXtComment̖RIDATcz(BpipPc |IENDB`PK}6CN_ plfit-latest/_static/scipy.css@import "default.css"; /** * Spacing fixes */ div.body p, div.body dd, div.body li { line-height: 125%; } ul.simple { margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; } /* spacing around blockquoted fields in parameters/attributes/returns */ td.field-body > blockquote { margin-top: 0.1em; margin-bottom: 0.5em; } /* spacing around example code */ div.highlight > pre { padding: 2px 5px 2px 5px; } /* spacing in see also definition lists */ dl.last > dd { margin-top: 1px; margin-bottom: 5px; margin-left: 30px; } /** * Hide dummy toctrees */ ul { padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; } ul li { padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; } ul li a.reference { padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; } /** * Make high-level subsections easier to distinguish from top-level ones */ div.body h3 { background-color: transparent; } div.body h4 { border: none; background-color: transparent; } /** * Scipy colors */ /* body { background-color: rgb(100,135,220); } div.document { background-color: rgb(230,230,230); } div.related { background-color: rgb(100,135,220); } div.sphinxsidebar { background-color: rgb(230,230,230); } div.sphinxsidebar h3 { color: rgb(0,102,204); } div.sphinxsidebar h3 a { color: rgb(0,102,204); } div.sphinxsidebar h4 { color: rgb(0,82,194); } div.sphinxsidebar p { color: black; } div.sphinxsidebar a { color: #355f7c; } div.sphinxsidebar ul.want-points { list-style: disc; } */ .field-list th { color: rgb(0,102,204); } /** * Extra admonitions */ div.tip { background-color: #ffffe4; border: 1px solid #ee6; } div.plot-output { clear-after: both; } div.plot-output .figure { float: left; text-align: center; margin-bottom: 0; padding-bottom: 0; } div.plot-output .caption { margin-top: 2; padding-top: 0; } div.plot-output p.admonition-title { display: none; } div.plot-output:after { content: ""; display: block; height: 0; clear: both; } /* div.admonition-example { background-color: #e4ffe4; border: 1px solid #ccc; }*/ /** * Styling for field lists */ table.field-list th { border-left: 1px solid #aaa !important; padding-left: 5px; } table.field-list { border-collapse: separate; border-spacing: 10px; } /** * Styling for footnotes */ table.footnote td, table.footnote th { border: none; } PKesEDkl\\!plfit-latest/_static/pygments.css.highlight .hll { background-color: #ffffcc } .highlight { background: #eeffcc; } .highlight .c { color: #408090; font-style: italic } /* Comment */ .highlight .err { border: 1px solid #FF0000 } /* Error */ .highlight .k { color: #007020; font-weight: bold } /* Keyword */ .highlight .o { color: #666666 } /* Operator */ .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ .highlight .cp { color: #007020 } /* Comment.Preproc */ .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #A00000 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #FF0000 } /* Generic.Error */ .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ .highlight .gi { color: #00A000 } /* Generic.Inserted */ .highlight .go { color: #333333 } /* Generic.Output */ .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ .highlight .gt { color: #0044DD } /* Generic.Traceback */ .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #007020 } /* Keyword.Pseudo */ .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #902000 } /* Keyword.Type */ .highlight .m { color: #208050 } /* Literal.Number */ .highlight .s { color: #4070a0 } /* Literal.String */ .highlight .na { color: #4070a0 } /* Name.Attribute */ .highlight .nb { color: #007020 } /* Name.Builtin */ .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ .highlight .no { color: #60add5 } /* Name.Constant */ .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ .highlight .ne { color: #007020 } /* Name.Exception */ .highlight .nf { color: #06287e } /* Name.Function */ .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #bb60d5 } /* Name.Variable */ .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mf { color: #208050 } /* Literal.Number.Float */ .highlight .mh { color: #208050 } /* Literal.Number.Hex */ .highlight .mi { color: #208050 } /* Literal.Number.Integer */ .highlight .mo { color: #208050 } /* Literal.Number.Oct */ .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ .highlight .sc { color: #4070a0 } /* Literal.String.Char */ .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ .highlight .sx { color: #c65d09 } /* Literal.String.Other */ .highlight .sr { color: #235388 } /* Literal.String.Regex */ .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ .highlight .ss { color: #517918 } /* Literal.String.Symbol */ .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */PK] -DDUkkplfit-latest/_static/up.pngPNG  IHDRasRGBbKGDC pHYs B(xtIME!.<̓EIDAT8͓NABP\EG{%<|xc  cr6@t;b$;3&)h1!﫳Hzz@=)p 3۵e2/ߴ ( %^ND^ }3H1DoǪISFұ?, G`{v^X[b]&HC3{:sO& ?,[eL#IENDB`PK}6C"0 plfit-latest/_static/default.css/* * default.css_t * ~~~~~~~~~~~~~ * * Sphinx stylesheet -- default theme. * * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ @import url("basic.css"); /* -- page layout ----------------------------------------------------------- */ body { font-family: sans-serif; font-size: 100%; background-color: #11303d; color: #000; margin: 0; padding: 0; } div.document { background-color: #1c4e63; } div.documentwrapper { float: left; width: 100%; } div.bodywrapper { margin: 0 0 0 230px; } div.body { background-color: #ffffff; color: #000000; padding: 0 20px 30px 20px; } div.footer { color: #ffffff; width: 100%; padding: 9px 0 9px 0; text-align: center; font-size: 75%; } div.footer a { color: #ffffff; text-decoration: underline; } div.related { background-color: #133f52; line-height: 30px; color: #ffffff; } div.related a { color: #ffffff; } div.sphinxsidebar { } div.sphinxsidebar h3 { font-family: 'Trebuchet MS', sans-serif; color: #ffffff; font-size: 1.4em; font-weight: normal; margin: 0; padding: 0; } div.sphinxsidebar h3 a { color: #ffffff; } div.sphinxsidebar h4 { font-family: 'Trebuchet MS', sans-serif; color: #ffffff; font-size: 1.3em; font-weight: normal; margin: 5px 0 0 0; padding: 0; } div.sphinxsidebar p { color: #ffffff; } div.sphinxsidebar p.topless { margin: 5px 10px 10px 10px; } div.sphinxsidebar ul { margin: 10px; padding: 0; color: #ffffff; } div.sphinxsidebar a { color: #98dbcc; } div.sphinxsidebar input { border: 1px solid #98dbcc; font-family: sans-serif; font-size: 1em; } /* -- hyperlink styles ------------------------------------------------------ */ a { color: #355f7c; text-decoration: none; } a:visited { color: #355f7c; text-decoration: none; } a:hover { text-decoration: underline; } /* -- body styles ----------------------------------------------------------- */ div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6 { font-family: 'Trebuchet MS', sans-serif; background-color: #f2f2f2; font-weight: normal; color: #20435c; border-bottom: 1px solid #ccc; margin: 20px -20px 10px -20px; padding: 3px 0 3px 10px; } div.body h1 { margin-top: 0; font-size: 200%; } div.body h2 { font-size: 160%; } div.body h3 { font-size: 140%; } div.body h4 { font-size: 120%; } div.body h5 { font-size: 110%; } div.body h6 { font-size: 100%; } a.headerlink { color: #c60f0f; font-size: 0.8em; padding: 0 4px 0 4px; text-decoration: none; } a.headerlink:hover { background-color: #c60f0f; color: white; } div.body p, div.body dd, div.body li { text-align: justify; line-height: 130%; } div.admonition p.admonition-title + p { display: inline; } div.admonition p { margin-bottom: 5px; } div.admonition pre { margin-bottom: 5px; } div.admonition ul, div.admonition ol { margin-bottom: 5px; } div.note { background-color: #eee; border: 1px solid #ccc; } div.seealso { background-color: #ffc; border: 1px solid #ff6; } div.topic { background-color: #eee; } div.warning { background-color: #ffe4e4; border: 1px solid #f66; } p.admonition-title { display: inline; } p.admonition-title:after { content: ":"; } pre { padding: 5px; background-color: #eeffcc; color: #333333; line-height: 120%; border: 1px solid #ac9; border-left: none; border-right: none; } tt { background-color: #ecf0f3; padding: 0 1px 0 1px; font-size: 0.95em; } th { background-color: #ede; } .warning tt { background: #efc2c2; } .note tt { background: #d6d6d6; } .viewcode-back { font-family: sans-serif; } div.viewcode-block:target { background-color: #f4debf; border-top: 1px solid #ac9; border-bottom: 1px solid #ac9; }PKFEDVR>>plfit-latest/_static/rtd.css/* * rtd.css * ~~~~~~~~~~~~~~~ * * Sphinx stylesheet -- sphinxdoc theme. Originally created by * Armin Ronacher for Werkzeug. * * Customized for ReadTheDocs by Eric Pierce & Eric Holscher * * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ /* RTD colors * light blue: #e8ecef * medium blue: #8ca1af * dark blue: #465158 * dark grey: #444444 * * white hover: #d1d9df; * medium blue hover: #697983; * green highlight: #8ecc4c * light blue (project bar): #e8ecef */ @import url("basic.css"); /* PAGE LAYOUT -------------------------------------------------------------- */ body { font: 100%/1.5 "ff-meta-web-pro-1","ff-meta-web-pro-2",Arial,"Helvetica Neue",sans-serif; text-align: center; color: black; background-color: #465158; padding: 0; margin: 0; } div.document { text-align: left; background-color: #e8ecef; } div.bodywrapper { background-color: #ffffff; border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; margin: 0 0 0 16em; } div.body { margin: 0; padding: 0.5em 1.3em; min-width: 20em; } div.related { font-size: 1em; background-color: #465158; } div.documentwrapper { float: left; width: 100%; background-color: #e8ecef; } /* HEADINGS --------------------------------------------------------------- */ h1 { margin: 0; padding: 0.7em 0 0.3em 0; font-size: 1.5em; line-height: 1.15; color: #111; clear: both; } h2 { margin: 2em 0 0.2em 0; font-size: 1.35em; padding: 0; color: #465158; } h3 { margin: 1em 0 -0.3em 0; font-size: 1.2em; color: #6c818f; } div.body h1 a, div.body h2 a, div.body h3 a, div.body h4 a, div.body h5 a, div.body h6 a { color: black; } h1 a.anchor, h2 a.anchor, h3 a.anchor, h4 a.anchor, h5 a.anchor, h6 a.anchor { display: none; margin: 0 0 0 0.3em; padding: 0 0.2em 0 0.2em; color: #aaa !important; } h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor { display: inline; } h1 a.anchor:hover, h2 a.anchor:hover, h3 a.anchor:hover, h4 a.anchor:hover, h5 a.anchor:hover, h6 a.anchor:hover { color: #777; background-color: #eee; } /* LINKS ------------------------------------------------------------------ */ /* Normal links get a pseudo-underline */ a { color: #444; text-decoration: none; border-bottom: 1px solid #ccc; } /* Links in sidebar, TOC, index trees and tables have no underline */ .sphinxsidebar a, .toctree-wrapper a, .indextable a, #indices-and-tables a { color: #444; text-decoration: none; /* border-bottom: none; */ } /* Search box size */ div.sphinxsidebar #searchbox input[type="submit"] { width: 50px; } /* Most links get an underline-effect when hovered */ a:hover, div.toctree-wrapper a:hover, .indextable a:hover, #indices-and-tables a:hover { color: #111; text-decoration: none; border-bottom: 1px solid #111; } /* Footer links */ div.footer a { color: #86989B; text-decoration: none; border: none; } div.footer a:hover { color: #a6b8bb; text-decoration: underline; border: none; } /* Permalink anchor (subtle grey with a red hover) */ div.body a.headerlink { color: #ccc; font-size: 1em; margin-left: 6px; padding: 0 4px 0 4px; text-decoration: none; border: none; } div.body a.headerlink:hover { color: #c60f0f; border: none; } /* NAVIGATION BAR --------------------------------------------------------- */ div.related ul { height: 2.5em; } div.related ul li { margin: 0; padding: 0.65em 0; float: left; display: block; color: white; /* For the >> separators */ font-size: 0.8em; } div.related ul li.right { float: right; margin-right: 5px; color: transparent; /* Hide the | separators */ } /* "Breadcrumb" links in nav bar */ div.related ul li a { order: none; background-color: inherit; font-weight: bold; margin: 6px 0 6px 4px; line-height: 1.75em; color: #ffffff; padding: 0.4em 0.8em; border: none; border-radius: 3px; } /* previous / next / modules / index links look more like buttons */ div.related ul li.right a { margin: 0.375em 0; background-color: #697983; text-shadow: 0 1px rgba(0, 0, 0, 0.5); border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } /* All navbar links light up as buttons when hovered */ div.related ul li a:hover { background-color: #8ca1af; color: #ffffff; text-decoration: none; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; } /* Take extra precautions for tt within links */ a tt, div.related ul li a tt { background: inherit !important; color: inherit !important; } /* SIDEBAR ---------------------------------------------------------------- */ div.sphinxsidebarwrapper { padding: 0; } div.sphinxsidebar { margin: 0; margin-left: -100%; float: left; top: 3em; left: 0; padding: 0 1em; width: 14em; font-size: 1em; text-align: left; background-color: #e8ecef; } div.sphinxsidebar img { max-width: 12em; } div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p.logo { margin: 1.2em 0 0.3em 0; font-size: 1em; padding: 0; color: #222222; font-family: "ff-meta-web-pro-1", "ff-meta-web-pro-2", "Arial", "Helvetica Neue", sans-serif; } div.sphinxsidebar h3 a { color: #444444; } div.sphinxsidebar ul, div.sphinxsidebar p { margin-top: 0; padding-left: 0; line-height: 130%; background-color: #e8ecef; } /* No bullets for nested lists, but a little extra indentation */ div.sphinxsidebar ul ul { list-style-type: none; margin-left: 1.5em; padding: 0; } /* A little top/bottom padding to prevent adjacent links' borders * from overlapping each other */ div.sphinxsidebar ul li { padding: 1px 0; } /* A little left-padding to make these align with the ULs */ div.sphinxsidebar p.topless { padding-left: 0 0 0 1em; } /* Make these into hidden one-liners */ div.sphinxsidebar ul li, div.sphinxsidebar p.topless { white-space: nowrap; overflow: hidden; } /* ...which become visible when hovered */ div.sphinxsidebar ul li:hover, div.sphinxsidebar p.topless:hover { overflow: visible; } /* Search text box and "Go" button */ #searchbox { margin-top: 2em; margin-bottom: 1em; background: #ddd; padding: 0.5em; border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; } #searchbox h3 { margin-top: 0; } /* Make search box and button abut and have a border */ input, div.sphinxsidebar input { border: 1px solid #999; float: left; } /* Search textbox */ input[type="text"] { margin: 0; padding: 0 3px; height: 20px; width: 144px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; -moz-border-radius-topleft: 3px; -moz-border-radius-bottomleft: 3px; -webkit-border-top-left-radius: 3px; -webkit-border-bottom-left-radius: 3px; } /* Search button */ input[type="submit"] { margin: 0 0 0 -1px; /* -1px prevents a double-border with textbox */ height: 22px; color: #444; background-color: #e8ecef; padding: 1px 4px; font-weight: bold; border-top-right-radius: 3px; border-bottom-right-radius: 3px; -moz-border-radius-topright: 3px; -moz-border-radius-bottomright: 3px; -webkit-border-top-right-radius: 3px; -webkit-border-bottom-right-radius: 3px; } input[type="submit"]:hover { color: #ffffff; background-color: #8ecc4c; } div.sphinxsidebar p.searchtip { clear: both; padding: 0.5em 0 0 0; background: #ddd; color: #666; font-size: 0.9em; } /* Sidebar links are unusual */ div.sphinxsidebar li a, div.sphinxsidebar p a { background: #e8ecef; /* In case links overlap main content */ border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border: 1px solid transparent; /* To prevent things jumping around on hover */ padding: 0 5px 0 5px; } div.sphinxsidebar li a:hover, div.sphinxsidebar p a:hover { color: #111; text-decoration: none; border: 1px solid #888; } div.sphinxsidebar p.logo a { border: 0; } /* Tweak any link appearing in a heading */ div.sphinxsidebar h3 a { } /* OTHER STUFF ------------------------------------------------------------ */ cite, code, tt { font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em; letter-spacing: 0.01em; } tt { background-color: #f2f2f2; color: #444; } tt.descname, tt.descclassname, tt.xref { border: 0; } hr { border: 1px solid #abc; margin: 2em; } pre, #_fontwidthtest { font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; margin: 1em 2em; font-size: 0.95em; letter-spacing: 0.015em; line-height: 120%; padding: 0.5em; border: 1px solid #ccc; background-color: #eee; border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; } pre a { color: inherit; text-decoration: underline; } td.linenos pre { margin: 1em 0em; } td.code pre { margin: 1em 0em; } div.quotebar { background-color: #f8f8f8; max-width: 250px; float: right; padding: 2px 7px; border: 1px solid #ccc; } div.topic { background-color: #f8f8f8; } table { border-collapse: collapse; margin: 0 -0.5em 0 -0.5em; } table td, table th { padding: 0.2em 0.5em 0.2em 0.5em; } /* ADMONITIONS AND WARNINGS ------------------------------------------------- */ /* Shared by admonitions, warnings and sidebars */ div.admonition, div.warning, div.sidebar { font-size: 0.9em; margin: 2em; padding: 0; /* border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px; */ } div.admonition p, div.warning p, div.sidebar p { margin: 0.5em 1em 0.5em 1em; padding: 0; } div.admonition pre, div.warning pre, div.sidebar pre { margin: 0.4em 1em 0.4em 1em; } div.admonition p.admonition-title, div.warning p.admonition-title, div.sidebar p.sidebar-title { margin: 0; padding: 0.1em 0 0.1em 0.5em; color: white; font-weight: bold; font-size: 1.1em; text-shadow: 0 1px rgba(0, 0, 0, 0.5); } div.admonition ul, div.admonition ol, div.warning ul, div.warning ol, div.sidebar ul, div.sidebar ol { margin: 0.1em 0.5em 0.5em 3em; padding: 0; } /* Admonitions and sidebars only */ div.admonition, div.sidebar { border: 1px solid #609060; background-color: #e9ffe9; } div.admonition p.admonition-title, div.sidebar p.sidebar-title { background-color: #70A070; border-bottom: 1px solid #609060; } /* Warnings only */ div.warning { border: 1px solid #900000; background-color: #ffe9e9; } div.warning p.admonition-title { background-color: #b04040; border-bottom: 1px solid #900000; } /* Sidebars only */ div.sidebar { max-width: 30%; } div.versioninfo { margin: 1em 0 0 0; border: 1px solid #ccc; background-color: #DDEAF0; padding: 8px; line-height: 1.3em; font-size: 0.9em; } .viewcode-back { font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva', 'Verdana', sans-serif; } div.viewcode-block:target { background-color: #f4debf; border-top: 1px solid #ac9; border-bottom: 1px solid #ac9; } dl { margin: 1em 0 2.5em 0; } dl dt { font-style: italic; } dl dd { color: rgb(68, 68, 68); font-size: 0.95em; } /* Highlight target when you click an internal link */ dt:target { background: #ffe080; } /* Don't highlight whole divs */ div.highlight { background: transparent; } /* But do highlight spans (so search results can be highlighted) */ span.highlight { background: #ffe080; } div.footer { background-color: #465158; color: #eeeeee; padding: 0 2em 2em 2em; clear: both; font-size: 0.8em; text-align: center; } p { margin: 0.8em 0 0.5em 0; } .section p img.math { margin: 0; } .section p img { margin: 1em 2em; } table.docutils td, table.docutils th { padding: 1px 8px 1px 5px; } /* MOBILE LAYOUT -------------------------------------------------------------- */ @media screen and (max-width: 600px) { h1, h2, h3, h4, h5 { position: relative; } ul { padding-left: 1.25em; } div.bodywrapper a.headerlink, #indices-and-tables h1 a { color: #e6e6e6; font-size: 80%; float: right; line-height: 1.8; position: absolute; right: -0.7em; visibility: inherit; } div.bodywrapper h1 a.headerlink, #indices-and-tables h1 a { line-height: 1.5; } pre { font-size: 0.7em; overflow: auto; word-wrap: break-word; white-space: pre-wrap; } div.related ul { height: 2.5em; padding: 0; text-align: left; } div.related ul li { clear: both; color: #465158; padding: 0.2em 0; } div.related ul li:last-child { border-bottom: 1px dotted #8ca1af; padding-bottom: 0.4em; margin-bottom: 1em; width: 100%; } div.related ul li a { color: #465158; padding-right: 0; } div.related ul li a:hover { background: inherit; color: inherit; } div.related ul li.right { clear: none; padding: 0.65em 0; margin-bottom: 0.5em; } div.related ul li.right a { color: #fff; padding-right: 0.8em; } div.related ul li.right a:hover { background-color: #8ca1af; } div.body { clear: both; min-width: 0; word-wrap: break-word; } div.bodywrapper { margin: 0 0 0 0; } div.sphinxsidebar { float: none; margin: 0; width: auto; } div.sphinxsidebar input[type="text"] { height: 2em; line-height: 2em; width: 70%; } div.sphinxsidebar input[type="submit"] { height: 2em; margin-left: 0.5em; width: 20%; } div.sphinxsidebar p.searchtip { background: inherit; margin-bottom: 1em; } div.sphinxsidebar ul li, div.sphinxsidebar p.topless { white-space: normal; } .bodywrapper img { display: block; margin-left: auto; margin-right: auto; max-width: 100%; } div.documentwrapper { float: none; } div.admonition, div.warning, pre, blockquote { margin-left: 0em; margin-right: 0em; } .body p img { margin: 0; } #searchbox { background: transparent; } .related:not(:first-child) li { display: none; } .related:not(:first-child) li.right { display: block; } div.footer { padding: 1em; } .rtd_doc_footer .rtd-badge { float: none; margin: 1em auto; position: static; } .rtd_doc_footer .rtd-badge.revsys-inline { margin-right: auto; margin-bottom: 2em; } table.indextable { display: block; width: auto; } .indextable tr { display: block; } .indextable td { display: block; padding: 0; width: auto !important; } .indextable td dt { margin: 1em 0; } ul.search { margin-left: 0.25em; } ul.search li div.context { font-size: 90%; line-height: 1.1; margin-bottom: 1; margin-left: 0; } } PK}6C`P^^plfit-latest/_static/extra.css/* Extra formatting stuff that is not included in the default themes */ @import "scipy.css"; @import "astropy.css"; @import "agogo.css"; @import "agogo.css"; div.bodywrapper { margin: 0 0 0 0; } .field-list th { white-space: nowrap; } .field-name th { white-space: nowrap; color: rgb(0,102,204); } a:visited { color: #4a8f43; } PK] -D;l/l/"plfit-latest/_static/underscore.js// Underscore.js 1.3.1 // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore is freely distributable under the MIT license. // Portions of Underscore are inspired or borrowed from Prototype, // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); PKisED'plfit-latest/_static/readthedocs-ext.js // User's analytics code. var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-6253200-8']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); PK] -D<>$plfit-latest/_static/ajax-loader.gifGIF89aU|NU|l!Created with ajaxload.info! ! NETSCAPE2.0,30Ikc:Nf E1º.`q-[9ݦ9 JkH! ,4N!  DqBQT`1 `LE[|ua C%$*! ,62#+AȐ̔V/cNIBap ̳ƨ+Y2d! ,3b%+2V_ ! 1DaFbR]=08,Ȥr9L! ,2r'+JdL &v`\bThYB)@<&,ȤR! ,3 9tڞ0!.BW1  sa50 m)J! ,2 ٜU]qp`a4AF0` @1Α! ,20IeBԜ) q10ʰPaVڥ ub[;PK}6CCVrr plfit-latest/_static/astropy.css@import "default.css"; /* TODO: I'd like to put some of the fixes in here into stsci_sphinxext proper * at which point this file might be able to go away */ .figure.align-center { clear: none; } /* This is a div for containing multiple figures side-by-side, for use with * .. container:: figures */ div.figures { border: 1px solid #CCCCCC; background-color: #F8F8F8; margin: 1em; text-align: center; } div.figures .figure { clear: none; float: none; display: inline-block; border: none; margin-left: 0.5em; margin-right: 0.5em; } .field-list th { white-space: nowrap; }PK] -DPu u plfit-latest/_static/comment.pngPNG  IHDRa OiCCPPhotoshop ICC profilexڝSgTS=BKKoR RB&*! J!QEEȠQ, !{kּ> H3Q5 B.@ $pd!s#~<<+"x M0B\t8K@zB@F&S`cbP-`'{[! eDh;VEX0fK9-0IWfH  0Q){`##xFW<+*x<$9E[-qWW.(I+6aa@.y24x6_-"bbϫp@t~,/;m%h^ uf@Wp~<5j>{-]cK'Xto(hw?G%fIq^D$.Tʳ?D*A, `6B$BB dr`)B(Ͱ*`/@4Qhp.U=pa( Aa!ڈbX#!H$ ɈQ"K5H1RT UH=r9\F;2G1Q= C7F dt1r=6Ыhڏ>C03l0.B8, c˱" VcϱwE 6wB aAHXLXNH $4 7 Q'"K&b21XH,#/{C7$C2'ITFnR#,4H#dk9, +ȅ3![ b@qS(RjJ4e2AURݨT5ZBRQ4u9̓IKhhitݕNWGw Ljg(gwLӋT071oUX**| J&*/Tު UUT^S}FU3S ԖUPSSg;goT?~YYLOCQ_ cx,!k u5&|v*=9C3J3WRf?qtN (~))4L1e\kXHQG6EYAJ'\'GgSSݧ M=:.kDwn^Loy}/TmG X $ <5qo</QC]@Caaᄑ.ȽJtq]zۯ6iܟ4)Y3sCQ? 0k߬~OCOg#/c/Wװwa>>r><72Y_7ȷOo_C#dz%gA[z|!?:eAAA!h쐭!ΑiP~aa~ 'W?pX15wCsDDDޛg1O9-J5*>.j<74?.fYXXIlK9.*6nl {/]py.,:@LN8A*%w% yg"/6шC\*NH*Mz쑼5y$3,幄'L Lݛ:v m2=:1qB!Mggfvˬen/kY- BTZ(*geWf͉9+̳ې7ᒶKW-X潬j9(xoʿܔĹdff-[n ڴ VE/(ۻCɾUUMfeI?m]Nmq#׹=TR+Gw- 6 U#pDy  :v{vg/jBFS[b[O>zG499?rCd&ˮ/~јѡ򗓿m|x31^VwwO| (hSЧc3-bKGD pHYs  tIME 1;VIDAT8ukU?sg4h`G1 RQܸp%Bn"bЍXJ .4V iZ##T;m!4bP~7r>ιbwc;m;oӍAΆ ζZ^/|s{;yR=9(rtVoG1w#_ө{*E&!(LVuoᲵ‘D PG4 :&~*ݳreu: S-,U^E&JY[P!RB ŖޞʖR@_ȐdBfNvHf"2T]R j'B1ddAak/DIJD D2H&L`&L $Ex,6|~_\P $MH`I=@Z||ttvgcЕWTZ'3rje"ܵx9W> mb|byfFRx{w%DZC$wdցHmWnta(M<~;9]C/_;Տ#}o`zSڷ_>:;x컓?yݩ|}~wam-/7=0S5RP"*֯ IENDB`PK] -Dhkkplfit-latest/_static/down.pngPNG  IHDRasRGBbKGDC pHYs B(xtIME"U{IDAT8ҡNCAJ, ++@4>/U^,~T&3M^^^PM6ٹs*RJa)eG*W<"F Fg78G>q OIp:sAj5GنyD^+yU:p_%G@D|aOs(yM,"msx:.b@D|`Vٟ۲иeKſ/G!IENDB`PK] -D+0plfit-latest/_static/file.pngPNG  IHDRabKGD pHYs  tIME  )TIDAT8˭J@Ir('[ "&xYZ X0!i|_@tD] #xjv YNaEi(əy@D&`6PZk$)5%"z.NA#Aba`Vs_3c,2mj [klvy|!Iմy;v "߮a?A7`c^nk?Bg}TЙD# "RD1yER*6MJ3K_Ut8F~IENDB`PK] -D[{gtt#plfit-latest/_static/up-pressed.pngPNG  IHDRasRGBbKGDC pHYs B(xtIME ,ZeIDAT8͓jA*WKk-,By@- و/`cXYh!6jf GrOlXvvfk2!p!GOOԲ &zf 6|M~%`]* ΛM]K ZĆ1Er%ȶcm1`= 0 && !jQuery(node.parentNode).hasClass(className)) { var span = document.createElement("span"); span.className = className; span.appendChild(document.createTextNode(val.substr(pos, text.length))); node.parentNode.insertBefore(span, node.parentNode.insertBefore( document.createTextNode(val.substr(pos + text.length)), node.nextSibling)); node.nodeValue = val.substr(0, pos); } } else if (!jQuery(node).is("button, select, textarea")) { jQuery.each(node.childNodes, function() { highlight(this); }); } } return this.each(function() { highlight(this); }); }; /** * Small JavaScript module for the documentation. */ var Documentation = { init : function() { this.fixFirefoxAnchorBug(); this.highlightSearchWords(); this.initIndexTable(); }, /** * i18n support */ TRANSLATIONS : {}, PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, LOCALE : 'unknown', // gettext and ngettext don't access this so that the functions // can safely bound to a different name (_ = Documentation.gettext) gettext : function(string) { var translated = Documentation.TRANSLATIONS[string]; if (typeof translated == 'undefined') return string; return (typeof translated == 'string') ? translated : translated[0]; }, ngettext : function(singular, plural, n) { var translated = Documentation.TRANSLATIONS[singular]; if (typeof translated == 'undefined') return (n == 1) ? singular : plural; return translated[Documentation.PLURALEXPR(n)]; }, addTranslations : function(catalog) { for (var key in catalog.messages) this.TRANSLATIONS[key] = catalog.messages[key]; this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); this.LOCALE = catalog.locale; }, /** * add context elements like header anchor links */ addContextElements : function() { $('div[id] > :header:first').each(function() { $('\u00B6'). attr('href', '#' + this.id). attr('title', _('Permalink to this headline')). appendTo(this); }); $('dt[id]').each(function() { $('\u00B6'). attr('href', '#' + this.id). attr('title', _('Permalink to this definition')). appendTo(this); }); }, /** * workaround a firefox stupidity */ fixFirefoxAnchorBug : function() { if (document.location.hash && $.browser.mozilla) window.setTimeout(function() { document.location.href += ''; }, 10); }, /** * highlight the search words provided in the url in the text */ highlightSearchWords : function() { var params = $.getQueryParameters(); var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; if (terms.length) { var body = $('div.body'); window.setTimeout(function() { $.each(terms, function() { body.highlightText(this.toLowerCase(), 'highlighted'); }); }, 10); $('') .appendTo($('#searchbox')); } }, /** * init the domain index toggle buttons */ initIndexTable : function() { var togglers = $('img.toggler').click(function() { var src = $(this).attr('src'); var idnum = $(this).attr('id').substr(7); $('tr.cg-' + idnum).toggle(); if (src.substr(-9) == 'minus.png') $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); else $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); }).css('display', ''); if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { togglers.click(); } }, /** * helper function to hide the search marks again */ hideSearchWords : function() { $('#searchbox .highlight-link').fadeOut(300); $('span.highlighted').removeClass('highlighted'); }, /** * make the url absolute */ makeURL : function(relativeURL) { return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; }, /** * get the current relative url */ getCurrentURL : function() { var path = document.location.pathname; var parts = path.split(/\//); $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { if (this == '..') parts.pop(); }); var url = parts.join('/'); return path.substring(url.lastIndexOf('/') + 1, path.length - 1); } }; // quick alias for translations _ = Documentation.gettext; $(document).ready(function() { Documentation.init(); }); PK}6Cl8plfit-latest/_static/sidebar.js/* * sidebar.js * ~~~~~~~~~~ * * This script makes the Sphinx sidebar collapsible. * * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton * used to collapse and expand the sidebar. * * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden * and the width of the sidebar and the margin-left of the document * are decreased. When the sidebar is expanded the opposite happens. * This script saves a per-browser/per-session cookie used to * remember the position of the sidebar among the pages. * Once the browser is closed the cookie is deleted and the position * reset to the default (expanded). * * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ $(function() { // global elements used by the functions. // the 'sidebarbutton' element is defined as global after its // creation, in the add_sidebar_button function var bodywrapper = $('.bodywrapper'); var sidebar = $('.sphinxsidebar'); var sidebarwrapper = $('.sphinxsidebarwrapper'); // for some reason, the document has no sidebar; do not run into errors if (!sidebar.length) return; // original margin-left of the bodywrapper and width of the sidebar // with the sidebar expanded var bw_margin_expanded = bodywrapper.css('margin-left'); var ssb_width_expanded = sidebar.width(); // margin-left of the bodywrapper and width of the sidebar // with the sidebar collapsed var bw_margin_collapsed = '.8em'; var ssb_width_collapsed = '.8em'; // colors used by the current theme var dark_color = $('.related').css('background-color'); var light_color = $('.document').css('background-color'); function sidebar_is_collapsed() { return sidebarwrapper.is(':not(:visible)'); } function toggle_sidebar() { if (sidebar_is_collapsed()) expand_sidebar(); else collapse_sidebar(); } function collapse_sidebar() { sidebarwrapper.hide(); sidebar.css('width', ssb_width_collapsed); bodywrapper.css('margin-left', bw_margin_collapsed); sidebarbutton.css({ 'margin-left': '0', 'height': bodywrapper.height() }); sidebarbutton.find('span').text('»'); sidebarbutton.attr('title', _('Expand sidebar')); document.cookie = 'sidebar=collapsed'; } function expand_sidebar() { bodywrapper.css('margin-left', bw_margin_expanded); sidebar.css('width', ssb_width_expanded); sidebarwrapper.show(); sidebarbutton.css({ 'margin-left': ssb_width_expanded-12, 'height': bodywrapper.height() }); sidebarbutton.find('span').text('«'); sidebarbutton.attr('title', _('Collapse sidebar')); document.cookie = 'sidebar=expanded'; } function add_sidebar_button() { sidebarwrapper.css({ 'float': 'left', 'margin-right': '0', 'width': ssb_width_expanded - 28 }); // create the button sidebar.append( '
«
' ); var sidebarbutton = $('#sidebarbutton'); light_color = sidebarbutton.css('background-color'); // find the height of the viewport to center the '<<' in the page var viewport_height; if (window.innerHeight) viewport_height = window.innerHeight; else viewport_height = $(window).height(); sidebarbutton.find('span').css({ 'display': 'block', 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 }); sidebarbutton.click(toggle_sidebar); sidebarbutton.attr('title', _('Collapse sidebar')); sidebarbutton.css({ 'color': '#FFFFFF', 'border-left': '1px solid ' + dark_color, 'font-size': '1.2em', 'cursor': 'pointer', 'height': bodywrapper.height(), 'padding-top': '1px', 'margin-left': ssb_width_expanded - 12 }); sidebarbutton.hover( function () { $(this).css('background-color', dark_color); }, function () { $(this).css('background-color', light_color); } ); } function set_position_from_cookie() { if (!document.cookie) return; var items = document.cookie.split(';'); for(var k=0; k4$4"" R6;.BJRT0aIx B UW8T-LRX_5ASt\tOCBNZm-XNKWWG\IVdomd@Nudy_ous%umR{~qvC{}Pvv toti}H N[yx: Ul*z~$@ @P$ PKfsED(xEE#plfit-latest/_static/searchtools.js/* * searchtools.js_t * ~~~~~~~~~~~~~~~~ * * Sphinx JavaScript utilties for the full-text search. * * :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */ /** * Porter Stemmer */ var Stemmer = function() { var step2list = { ational: 'ate', tional: 'tion', enci: 'ence', anci: 'ance', izer: 'ize', bli: 'ble', alli: 'al', entli: 'ent', eli: 'e', ousli: 'ous', ization: 'ize', ation: 'ate', ator: 'ate', alism: 'al', iveness: 'ive', fulness: 'ful', ousness: 'ous', aliti: 'al', iviti: 'ive', biliti: 'ble', logi: 'log' }; var step3list = { icate: 'ic', ative: '', alize: 'al', iciti: 'ic', ical: 'ic', ful: '', ness: '' }; var c = "[^aeiou]"; // consonant var v = "[aeiouy]"; // vowel var C = c + "[^aeiouy]*"; // consonant sequence var V = v + "[aeiou]*"; // vowel sequence var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 var s_v = "^(" + C + ")?" + v; // vowel in stem this.stemWord = function (w) { var stem; var suffix; var firstch; var origword = w; if (w.length < 3) return w; var re; var re2; var re3; var re4; firstch = w.substr(0,1); if (firstch == "y") w = firstch.toUpperCase() + w.substr(1); // Step 1a re = /^(.+?)(ss|i)es$/; re2 = /^(.+?)([^s])s$/; if (re.test(w)) w = w.replace(re,"$1$2"); else if (re2.test(w)) w = w.replace(re2,"$1$2"); // Step 1b re = /^(.+?)eed$/; re2 = /^(.+?)(ed|ing)$/; if (re.test(w)) { var fp = re.exec(w); re = new RegExp(mgr0); if (re.test(fp[1])) { re = /.$/; w = w.replace(re,""); } } else if (re2.test(w)) { var fp = re2.exec(w); stem = fp[1]; re2 = new RegExp(s_v); if (re2.test(stem)) { w = stem; re2 = /(at|bl|iz)$/; re3 = new RegExp("([^aeiouylsz])\\1$"); re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); if (re2.test(w)) w = w + "e"; else if (re3.test(w)) { re = /.$/; w = w.replace(re,""); } else if (re4.test(w)) w = w + "e"; } } // Step 1c re = /^(.+?)y$/; if (re.test(w)) { var fp = re.exec(w); stem = fp[1]; re = new RegExp(s_v); if (re.test(stem)) w = stem + "i"; } // Step 2 re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; if (re.test(w)) { var fp = re.exec(w); stem = fp[1]; suffix = fp[2]; re = new RegExp(mgr0); if (re.test(stem)) w = stem + step2list[suffix]; } // Step 3 re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; if (re.test(w)) { var fp = re.exec(w); stem = fp[1]; suffix = fp[2]; re = new RegExp(mgr0); if (re.test(stem)) w = stem + step3list[suffix]; } // Step 4 re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; re2 = /^(.+?)(s|t)(ion)$/; if (re.test(w)) { var fp = re.exec(w); stem = fp[1]; re = new RegExp(mgr1); if (re.test(stem)) w = stem; } else if (re2.test(w)) { var fp = re2.exec(w); stem = fp[1] + fp[2]; re2 = new RegExp(mgr1); if (re2.test(stem)) w = stem; } // Step 5 re = /^(.+?)e$/; if (re.test(w)) { var fp = re.exec(w); stem = fp[1]; re = new RegExp(mgr1); re2 = new RegExp(meq1); re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) w = stem; } re = /ll$/; re2 = new RegExp(mgr1); if (re.test(w) && re2.test(w)) { re = /.$/; w = w.replace(re,""); } // and turn initial Y back to y if (firstch == "y") w = firstch.toLowerCase() + w.substr(1); return w; } } /** * Simple result scoring code. */ var Scorer = { // Implement the following function to further tweak the score for each result // The function takes a result array [filename, title, anchor, descr, score] // and returns the new score. /* score: function(result) { return result[4]; }, */ // query matches the full name of an object objNameMatch: 11, // or matches in the last dotted part of the object name objPartialMatch: 6, // Additive scores depending on the priority of the object objPrio: {0: 15, // used to be importantResults 1: 5, // used to be objectResults 2: -5}, // used to be unimportantResults // Used when the priority is not in the mapping. objPrioDefault: 0, // query found in title title: 15, // query found in terms term: 5 }; /** * Search Module */ var Search = { _index : null, _queued_query : null, _pulse_status : -1, init : function() { var params = $.getQueryParameters(); if (params.q) { var query = params.q[0]; $('input[name="q"]')[0].value = query; this.performSearch(query); } }, loadIndex : function(url) { $.ajax({type: "GET", url: url, data: null, dataType: "script", cache: true, complete: function(jqxhr, textstatus) { if (textstatus != "success") { document.getElementById("searchindexloader").src = url; } }}); }, setIndex : function(index) { var q; this._index = index; if ((q = this._queued_query) !== null) { this._queued_query = null; Search.query(q); } }, hasIndex : function() { return this._index !== null; }, deferQuery : function(query) { this._queued_query = query; }, stopPulse : function() { this._pulse_status = 0; }, startPulse : function() { if (this._pulse_status >= 0) return; function pulse() { var i; Search._pulse_status = (Search._pulse_status + 1) % 4; var dotString = ''; for (i = 0; i < Search._pulse_status; i++) dotString += '.'; Search.dots.text(dotString); if (Search._pulse_status > -1) window.setTimeout(pulse, 500); } pulse(); }, /** * perform a search for something (or wait until index is loaded) */ performSearch : function(query) { // create the required interface elements this.out = $('#search-results'); this.title = $('

' + _('Searching') + '

').appendTo(this.out); this.dots = $('').appendTo(this.title); this.status = $('

').appendTo(this.out); this.output = $('