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
  • 732,580
  • 175
  • 1,330
  • 1,459
nikky
  • 1,835
  • 3
  • 18
  • 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.
  • 55,948
  • 11
  • 128
  • 197
3

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

Eyal Schneider
  • 22,166
  • 5
  • 47
  • 78
1

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

Renaud
  • 16,073
  • 6
  • 81
  • 79
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
  • 213
  • 1
  • 3
  • 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