As I have been doing some social network analysis, I have stumbled upon the problem of fitting a probability distribution on network degree.
So, I have a probability distribution P(X >= x)
which, from visual inspection, follows a power law with an exponential cutoff rather than a pure power law (a straight line).
So, given that the equation for power law distribution with exponential cutoff is:
f(x) = x**alpha * exp(beta*x)
How might I estimate the parameters alpha
and beta
using Python?
I know scipy.stats.powerlaw package exists and they have a .fit()
function but that doesn't seem to do the job as it only returns the location and scale of the plot, which seems to be useful only for normal distribution? There are also not enough tutorials on this package.
P.S. I'm well aware of the implementation of CLauset et al but they don't seem to provide ways to estimate the parameters of alternate distributions.
(c) Power law with an exponential cutoff behaves like a power law for small values of x, but drops more steeply (exponentially) for larger x. (d) Log-normal/power law composite has a log-normal distribution (which can have a peak) for smaller x, and a power law for larger x.
The essential difference is that an exponential function has its variable in its exponent, but a power function has its variable in its base. For example, f(x)=3x is an exponential function, but g(x)=x3 is a power function.
Powerlaw library can directly be used to estimate the parameters as follows:
Install all the pythons dependencies:
pip install powerlaw mpmath scipy
Run the powerlaw package fit in a python environment:
import powerlaw
data = [5, 4, ... ]
results = powerlaw.Fit(data)
get the parameters from the results
results.truncated_power_law.parameter1 # power law parameter (alpha)
results.truncated_power_law.parameter2 # exponential cut-off parameter (beta)
The function scipy.stats.powerlaw.fit may still work for your purposes. It's a bit confusing how the distributions in scipy.stats work (the documentation for each one refers to the optional parameters loc and scale, even though not all of them use these parameters, and each uses them differently). If you look at the docs:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.powerlaw.html
there's also a second non-optional parameter "a", which is the "shape parameters". In the case of powerlaw, this contains a single parameter. Don't worry about "loc" and "scale".
Edit: Sorry, forgot that you wanted the beta parameter too. Your best best may be to define the powerlaw function you want yourself, and then use scipy's generic fitting algorithms to learn the parameters. For example: http://www.scipy.org/Cookbook/FittingData#head-5eba0779a34c07f5a596bbcf99dbc7886eac18e5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With