如何挑选一批基于概率有多大? [英] How to pick a number based on probability?

查看:191
本文介绍了如何挑选一批基于概率有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要选择 0,1,2,3 ... N ,但是我想使这种选择的机会<$ C的随机数$ C> K | 0℃; K&n种将降低的 X 从选择 K - 1 X =(K - 1)/ K 。由于较大的数量较小的机会把它捡起来。

作为一个答案,我希望看到下一个方法的实现:

  INT pickANumber(N,X)
 

这是一个游戏,我发展,我看到了这些问题的相关但不完全相同:

  • 如何通过它的概率挑选一个项
  • <一个href="http://stackoverflow.com/questions/2649717/c-function-for-picking-from-a-list-where-each-element-has-a-distinct-probabili">C功能从一个列表,其中每个元素都有一个独特的probabili
  • 采摘
解决方案

  P1 + P2 + ... + PN = 1
P1 = P2 * X
P2 = P3 * X
...
P_N-1 = PN * X
 

解决这个给你:

  P1 + P2 + ... + PN = 1
(P2 * X)+(P3 * X)+ ... +(PN * X)+ PN = 1
((P3 * x)的* X)+((P4 * x)的* X)+ ... +((P_N-1 * *)* X)+ PN = 1
....
PN *(X ^(N-1)+ X ^(N-2)+ ... + X ^ 1 + X ^ 0)= 1
的pn *(1-X ^ N)/(1-X)= 1
PN =(1-X)/(1-X ^ n)的
 

这给你,你需要设置为 PN 的概率,你可以从中计算出概率的所有其他P1,P2,... P_N-1

现在,你可以用一个黑盒子RNG是选择一个号码与分布,像那些在你所提到的线程。

有一个简单的方法来做到这一点是建立一个辅助数组:

  AUX [I] = P1 + P2 + ... + PI
 

现在,画一个随机数之间的 0 均匀分布 AUX [N] ,并使用二进制搜索(辅助数组排序),得到的第一个值,这在匹配值的辅助大于你得到了随机统一编号


原来的答复,对于减法(问题是editted前):

有关 N 的项目,你需要解决的等式:

  P1 + P2 + ... + PN = 1
P1 = P2 + X
P2 = P3 + X
...
P_N-1 = PN + X
 

解决这个给你:

  P1 + P2 + ... + PN = 1
(P2 + X)+(P3 + X)+ ...(PN + X)+ PN = 1
((P3 + X)+ X)+((P4 + X)+ X)+ ... +((P_N-1 + X)+ X)+ PN = 1
....
的pn *((N-1)X +(N-2)X + ... + X + 0)= 1
PN * X = N(N-1)/ 2
的pn = N(N-1)/(2×)
 

这给你,你需要设置为 PN 的概率,你可以从中计算出概率的所有其他P1,P2,... P_N-1

现在,你可以用一个黑盒子RNG是选择一个号码与分布,像那些在你所提到的线程。


被告知,这是不能保证你将有一个解决方案,使得 0℃p_i&LT; 1 所有,但你不能保证一个来自你的要求给出,并且它要依赖于数值 N X 以适应。

I want to select a random number from 0,1,2,3...n, however I want to make it that the chance of selecting k|0<k<n will be lower by multiplication of x from selecting k - 1 so x = (k - 1) / k. As bigger the number as smaller the chances to pick it up.

As an answer I want to see the implementation of the next method:

int pickANumber(n,x)

This is for a game that I am developing, I saw those questions as related but not exactly that same:

解决方案

p1 + p2 + ... + pn = 1
p1 = p2 * x
p2 = p3 * x
...
p_n-1 = pn * x

Solving this gives you:

p1 + p2 + ... + pn = 1
(p2 * x) + (p3 * x) + ... + (pn * x) + pn = 1
((p3*x) * x) + ((p4*x) * x) + ... + ((p_n-1*x) * x) + pn = 1
....
pn* (x^(n-1) + x^(n-2) + ... +x^1 + x^0) = 1
pn*(1-x^n)/(1-x) = 1
pn = (1-x)/(1-x^n)

This gives you the probability you need to set to pn, and from it you can calculate the probabilities for all other p1,p2,...p_n-1

Now, you can use a "black box" RNG that chooses a number with a distribution, like those in the threads you mentioned.

A simple approach to do it is to set an auxillary array:

aux[i] = p1 + p2 + ... + pi

Now, draw a random number with uniform distribution between 0 to aux[n], and using binary search (aux array is sorted), get the first value, which matching value in aux is greater than the random uniform number you got


Original answer, for substraction (before question was editted):

For n items, you need to solve the equation:

p1 + p2 + ... + pn = 1
p1 = p2 + x
p2 = p3 + x
...
p_n-1 = pn + x

Solving this gives you:

p1 + p2 + ... + pn = 1
(p2 + x) + (p3 + x) + ... + (pn + x) + pn = 1
((p3+x) + x) + ((p4+x) + x) + ... + ((p_n-1+x) + x) + pn = 1
....
pn* ((n-1)x + (n-2)x + ... +x + 0) = 1
pn* x = n(n-1)/2
pn = n(n-1)/(2x)

This gives you the probability you need to set to pn, and from it you can calculate the probabilities for all other p1,p2,...p_n-1

Now, you can use a "black box" RNG that chooses a number with a distribution, like those in the threads you mentioned.


Be advised, this is not guaranteed you will have a solution such that 0<p_i<1 for all i, but you cannot guarantee one given from your requirements, and it is going to depend on values of n and x to fit.

这篇关于如何挑选一批基于概率有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆