Combinations with different probability
Lets say I have 5 independent events (A-E):
Pr(A) = 0,5
Pr(B) = 0,4
Pr(C) = 0,3
Pr(D) = 0,2
Pr(E) = 0,1
One "attempt" per event. I want to calculate the probability of three succesful events.
I do it like this:
Pr(A)*Pr(B)*Pr(C) * (1-Pr(D)) * (1-Pr(E))... for all different combinations.
But thats a lot of calculation and if I want more events it will get out of hand.
Perhaps there is some program or code that can do theese type of calculations?
Re: Combinations with different probability
Not that I know of, at least when the probabilities are not all equal. Higher order iteration libraries like Python's Itertools allow you to iterate over combinations like you've described, and you might have access to such a library depending on your programming language. You can also do the operation recursively as follows. Let T(n, s) be the probability of precisely s successes in events at index n or higher. Here, for instance, D has index 3 (starting from 0) so T(3, 1) = Pr(D)*(1-Pr(E)) + (1-Pr(D))*Pr(E) = 0.2*0.9 + 0.8*0.1 = 0.26. In general,
T(n, s) = Pr(n) * T(n+1, s-1) + (1-Pr(n)) * T(n+1, s),
where in the base cases,
T(n, 0) = 1 if n is out of range
T(n, -1) = 0 if n is out of range
Again in Python, this is...
Code:
def T(n, s):
if n>=len(P):
return 1 if s==0 else 0
return P[n] * T(n+1, s-1) + (1-P[n])* T(n+1, s)
and some example output is
Code:
>>> P = [0.5, 0.4, 0.3, 0.2, 0.1]
>>> T(3, 1)
0.26
>>> T(0, 3)
0.1274
Note that this code works very poorly for remotely large lists since it doubles the number of calls at each step--but I don't know any algorithm that would work particularly well in the general case anyway.