I want to supply a negative exponent for the scipy.stats.powerlaw routine, e.g. a=-1.5, in order to draw random samples:
"""
powerlaw.pdf(x, a) = a * x**(a-1)
"""
from scipy.stats import powerlaw
R = powerlaw.rvs(a, size=100)
Why is a > 0 required, how can I supply a negative a in order to generate the random samples, and how can I supply a normalization coefficient/transform, i.e.
PDF(x,C,a) = C * x**a
The documentation is here
http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.powerlaw.html
Thanks!
EDIT: I should add that I'm trying to replicate IDL's RANDOMP function:
The Python package powerlaw can do this. Consider for
a>1
a power law distribution with probability density functionfor
x > x_min
andf(x) = 0
otherwise. Herec
is a normalization factor and is determined asIn the example below it is
a = 1.5
andx_min = 1.0
and comparing the probability density function estimated from the random sample with the PDF from the expression above gives the expected result.returns
A PDF, integrated over its domain, must equal one. In other words, the area under a probability density function's curve must equal one.
The powerlaw density function has a domain from 0 <= x <= 1. On this domain, the integral of
x**b
is finite for anyb
> -1. Whenb
is smaller,x**b
blows up too rapidly nearx = 0
. So it is not a valid probability density function whenb <= -1
.Thus for
x**(a-1)
,a
must satisfya-1 > -1
or equivalently,a > 0
.The first constant
a
ina * x**(a-1)
is the normalizing constant which makes the integral ofa * x**(a-1)
over the domain [0,1] equal to 1. So you don't get to choose this constant independent ofa
.Now if you change the domain to be a measurable distance away from 0, then yes, you could define a PDF of the form
C * x**a
for negativea
. But you'd have to state what domain you want, and I don't think there is (yet) a PDF available inscipy.stats
for this.If you want to generate power-law distribution, you can use a random deviation. You just have to generate a random number between [0,1] and apply the inverse method (Wolfran). In this case, the probability density function is:
and y is the variable uniform between 0 and 1.
Now to generate a distribution, you just have to create an array
This will work to generate a power-law distribution with gamma=3.0, if you want to fixe the average of distribution, you have to study Complex Networks cause the k_min depends of k_max and the average conectivity.
If r is a uniform random deviate U(0,1), then x in the following expression is a power-law distributed random deviate:
where xmin is the smallest (positive) value above which the power-law distribution holds, and alpha is the exponent of the distribution.