how to implement non uniform probability distribution?

纵饮孤独 提交于 2019-11-28 10:34:57

For a simple discrete distribution, you can write a sampler that will return your outcomes with the desired frequency by using the cumulative probabilities.

Random r = new Random();
double v = r.nextDouble();

if (v <= 0.85) { return 0; }
if (v <= 0.86) { return 1; }
return 2;

This will return the numbers 0, 1 and 2 with a probability of 0.85, 0.01 and 0.14.

As far as the theory on non-uniform probability distributions, you can start with this Wikipedia article on probability distributions; take special note of the collapsible sections at the bottom of the page. You will find that there are dozens of non-uniform distribution (both continuous and discrete) with different properties.

In your particular case it is better to get a random value in [0; 100) using uniform distribution and then check what range it falls in: [0; 85), [85;99), [99, 100)

Sandor Murakozi

Based on your description it seems to me that you are talking about fitness proportionate selection (also known as roulette wheel selection).
http://en.wikipedia.org/wiki/Roulette-wheel_selection

I think nailxx' answer is a pretty compact description what you need to do.

see also Roulette Selection in Genetic Algorithms
Roulette wheel selection algorithm

If I'm wrong here are some libraries that you may find useful:
http://www.ee.ucl.ac.uk/~mflanaga/java/Stat.html
http://commons.apache.org/math/apidocs/org/apache/commons/math/random/package-summary.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!