Results 1 to 2 of 2

Thread: Combinations with different probability

  1. #1
    Junior Member
    Join Date
    Oct 12
    Posts
    18

    Question 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?
    Last edited by angelina90; Oct 26th, 2012 at 11:27 AM.

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 02
    Posts
    2,301

    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.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •