简体   繁体   中英

Power Law distribution for a given exponent in C# using MathNet

I am currently working on a project where I need to generate multiple values (floats or doubles preferably) that follow a power law distribution with a given exponent!

I was advised to use the MathNet.Iridium library to help me. The problem I have is that the documentation is not as explicit as it should be if there is any!

I see multiple distributions that fit the general idea of the power law distribution but I cannot pinpoint a good distribution to use with a certain exponent as a parameter.

Does anybody have more experience in that matter and could give me some hints or advice?

To generate values of a distribution of your choice, you could use the inverse cumulative distribution function, as mentioned in the wikipedia .

Step by step, this would look like:

  1. Choose a distribution function that you like.
  2. Calculate the inverse cumulative distribution function using pen and paper.
  3. Generate a value based on a uniform distribution on the unit interval. Random will do nicely here.
  4. Input the value into your ICDF.

The result is a value chosen at random using your chosen distribution function.

If you run into problems with step 2, maybe the folks at https://mathoverflow.net/ can help you.

Edit: If you just need any power law distribution with exponent gamma, this will generate one value:

double r = 1.0 / Math.Pow(1-new Random().NextDouble(), 1.0/(gamma+1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM