3

I'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 :)

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
nikky
  • 1,681
  • 3
  • 17
  • 19

4 Answers4

4

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

Community
  • 1
  • 1
Alexandre C.
  • 53,934
  • 10
  • 121
  • 192
3

Maybe the Colt java library can help. It generates random numbers according to many distributions.

Eyal Schneider
  • 21,756
  • 5
  • 46
  • 73
1

Apache Commons Math lib was quite slow on my system (maybe I missed something...). This standalone class PowerLaw.java worked for me.

Renaud
  • 15,164
  • 5
  • 76
  • 77
1

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).

Peter
  • 204
  • 1
  • 2
  • 8
  • for powerlaw fitting, does this package already sort the collection in order to find the alpha? – 1EnemyLeft Nov 13 '18 at 22:43
  • As far as I remember, the data does not need to be sorted for the estimator to work. The data is only sorted (in a copy) when the KS test is run, I think. – Peter Nov 14 '18 at 07:26