Re: Re: How to calculate a union
- To: mathgroup at smc.vnet.net
- Subject: [mg104551] Re: [mg104536] Re: How to calculate a union
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Wed, 4 Nov 2009 01:30:59 -0500 (EST)
- References: <hcjjdv$jte$1@smc.vnet.net> <hcl3rn$buv$1@smc.vnet.net> <200911030755.CAA01500@smc.vnet.net>
rat wrote: > Helen Read: >> Bill Rowe wrote: >>> On 10/31/09 at 1:54 AM, ramiro.barrantes at gmail.com (Ramiro) wrote: >>> >>>> I am trying to compute the probability of a union, the formula >>>> requires to sum and subtract all possible combinations of >>>> intersections for all pairs, triplets, etc. When n is big, getting >>>> all the terms is a challenge. Otherwise, I can easily compute any >>>> given intersection. >>>> ex. P(AUBUC) = P(A) + P(B) + P(C) - (P(A,B)+P(A,C)+P(B,C)) + >>>> P(A,B,C) >>> Hmm... You say you are computing a probability. So, I would read >>> P(AUBUC) as being the probability of event A or event B or event >>> C occurring. Using that interpretation then >>> >>> P(AUBUC) = P(A) + P(B) + P(C) >>> >>> where I've assumed events A,B and C are independent events. >> The size union is only equal to the sum of the sizes of the individual >> sets if the sets are disjoint, which one cannot assume. >> >>> This is clearly different than the expression you have. >>> Additionally, P(A,B) is meaningless to me. >> He meant P(A intersect B) by that, and has applied the >> inclusion/exclusion principle correctly. >> >> > > > Hi Helen. > > I have a similar problem. > > I'm new to Mathematica and I'd like to program the inclusion-exclusion > principle to calculate P(AUBUCUD), for different probabilities > P(A),P(B),P(C),P(D) asuming these events are indepedent. > > What functions would be useful? I need something to start investigating... If the individual probabilities are known, and the events are independent, then you can do this iteratively as below. Works because the intersection probabilities of any event combination are simply the products of the individual probabilities. probabilityOfUnion[a_, b_] := prob[a] + prob[b] - prob[a]*prob[b] probabilityOfUnion[a_, b_, c__] := Module[ {ab, res}, prob[ab] = probabilityOfUnion[a, b]; res = probabilityOfUnion[ab, c]; Unset[prob[ab]]; res] Here is an example. I randomly assign probabilities less than .2 to 15 independent events. len = 15; aa = Array[a, len]; Do[prob[a[j]] = RandomReal[.2], {j, len}] We compute the union probability: In[88]:= Apply[probabilityOfUnion, aa] Out[88]= 0.8317 If you are willing to work directly with the probabilities of the individual events, it can be code much more succinctly as below. prob[ll : {_, _}] := Total[ll] - Apply[Times, ll] prob[{a_, b_, c__}] := prob[{prob[{a, b}], c}] len = 15; aa = RandomReal[.2, len]; In[10]:= prob[aa] Out[10]= 0.833538 Daniel Lichtblau Wolfram Research
- References:
- Re: How to calculate a union
- From: rat <b@fas.com>
- Re: How to calculate a union