xor: N things with variable probabilities

Viewed 96

Forgive me; I'm a coder and not a mathematician, so I'm asking this to my own stack. I'm trying to reduce an array of probabilities (0-1), let's say [.1,.3,.5] to find:

  1. The likelihood of all of them happening (simple multiplication, let's call this function AND: probs.reduce((m,p)=>p*m,1)),

    1.1 This can be written x_1 :\cap: x_2 :... \cap: x_n

  2. any one of them happening (one minus none of them happening 1 - probs.reduce((m,p)=>m*(1-p),1), call it OR), and

    2.1 This can be written x_1 :\cup: x_2 :... \cup: x_n

  3. XOR ONLY one, no more and no less, of them happening. At first I thought this was simple because if there are only two inputs, the chance of only one happening should be OR minus AND. But as I'm banging my head on this as an array of more than two values, normal XOR logic seems to disintegrate.

    3.1 This can be written (verbosely) (x_1 :\cup: \neg x_2 :... \cup: \neg x_n) :\cap: (\neg x_1 :\cup: x_2 :... \cup: \neg x_n) :...: \cap (\neg x_1 :\cup: \neg x_2 :... \cup: x_n)

Do I need to get the "OR" and then subtractively multiply all possible AND scenarios iteratively? Or is there a non-iterative formula to find out the total probability of exactly one probability in a list longer than two?

0,0,0 should be 0 in my case. 0,.4.0 should yield a .4 of only one happening. 1,.4,0 should yield 0.6. I know that .5,.5 should yield 0.25 chance of only one happening. But I'm really not sure how to calculate the chance of only one .5,.5,.5 without counting on my fingers. My mind is saying I have to loop through each probability, and subtract from it the chance of any others (OR the rest of the array), then OR the final results... but this is speculative. That seems very weird and inefficient. I can't believe this would be an NP-Hard problem, but it's a corner of things I'm not familiar with...

Please answer in visual, logical or programmatic terms, not pure Math if possible...

** Edit here: I don't need to clarify the exact probability of a particular element in the array being exclusive to the others; I'm trying to find the general probability of any of them being exclusive. **

** Edit. This is what I've got now. I'm excluding all other possibilities for each individual one. Is this the fastest way?... *


function And(probs) {
        return (probs.reduce((m,p)=>p*m,1));
    }
    function Or(probs) {
        return (1 - probs.reduce((m,p)=>m*(1-p),1));
    }
    function Xor(probs) {
        let _exclusiveProbabilities = [];
        for (let k=0; k < probs.length; k++) {
            let _others = [];
            for (let j = 0; j < probs.length; j++) {
                if (j != k) {
                    _others.push(probs[j]);
                    console.log(k,'pushed',probs[j]);
                }
            }
            const _anyOtherProb = Or(_others);
            _exclusiveProbabilities.push(probs[k] * (1 - _anyOtherProb));
        }
        return (Or(_exclusiveProbabilities)); 
    }

** edit. Nope, that's great for two but doesn't work for three. **

1 Answers

Let's say you have three probabilities, which we'll call A, B, and C.

The probability of A being the only event that happened is A * (1-B) * (1-C). In other words, in this scenario A happened, but B did not happen and C did not happen.

But, of course it is possible that B was the only successful event, or that C was the successful event. We will need to sum together the probabilities of all of these situations.

So, we are going to need to loop through all of the events, and compute the probability that only that event happened (and all the others failed), and then compute the sum.

For the case of three events, this would be: ( A * (1-B) * (1-C) ) + ( (1-A) * B * (1-C) ) + ( (1-A) * (1-B) * C )

If there are N total events, then there will be a total of N^2 (N squared) total terms in this expression.

Related