Java: Power Law Distribution [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionI'm trying to generate p2p network according to power law distribution. How to generate power law distribution in java? does it have any library?
thanks :)
If you can't/don't want to use a library:
In this case, the easiest way to go is to work out the CDF (check it against Wikipedia), that is the function F : x -> P(X < x). Then you draw uniform random numbers y on [0,1] with your favorite generator, and you solve y = F(x). The sequence of such x are identically distributed and follow a Power Law Distribution.
Edit: the answer is there
Maybe the Colt java library can help. It generates random numbers according to many distributions.
Apache Commons Math lib was quite slow on my system (maybe I missed something...). This standalone class PowerLaw.java worked for me.
This library: https://github.com/pbloem/powerlaws contains a power law generator, used as follows:
List<Double> data = new Continuous(3.14, 2.5).generate(1000);
This generates 1000 points from a power law distribution with 3.14 as minimal value and 2.5 as exponent. It also has a discrete distribution and a Continuous approximation of a discrete distribution. All these distribution can also be fit to existing data.
(Disclaimer: I wrote this library).
精彩评论