我有一个概率列表,每个概率代表成功的概率。我想获得2个或更多人成功的可能性。我知道它是由1-P(全部失败)-P(成功)计算得出的,我如何获得P(成功)?
import numpy
success = [0.1,0.2,0.3,....]
fail= [(1-i) for i in success]
P_all_fail = numpy.prod(fail)
答案 0 :(得分:0)
事件i成功而其他所有失败的概率为
P_all_fail *success[i] /fail[i]
因此,恰好一个是成功而其他所有都失败的概率是
P_one_success = P_all_fail * numpy.sum([ s / f for s,f in zip(success,fail)])
答案 1 :(得分:0)
完全成功的概率可以通过将每个人作为唯一继承者的概率相加来计算。由于此个体概率是某人成功的概率乘以其他所有人失败的概率,因此代码应为:
P_one_success = 0
current_P = 1
for x in success:
current_P = x
#we start by getting the probability of success for our current person
for y in success:
if y != x:
current_P = current_P * (1 - y)
#here we multiply our chance of having exactly one success by the chance that
#every other person fails
P_one_success = P_one_success + current_P
#finally we add all of these probabilities together