# Making inferences from Bayes networks and CPTs

So I'm practicing working with Bayes Networks and conditional probability tables and I feel like some of my numbers simply don't make sense.

Here's the situation: I have a bag of three different biased coins. Coin A has P(heads) of 0.2, coin B has P(heads) of 0.6, and coin C has P(heads) of 0.8.

I pick a coin at random and then flip it three times. I'm trying to work out the probability of each coin being the chosen coin, given a result of two heads and a tails.

So, based on this, I drew up a Bayesian network with the following CPTs:

Coin chosen C: P(C): a .33 b .33 c .33

and

coin flip F: P(F|C=a): P(F|C=b): P(F|C=c): heads 0.2 0.6 0.8 tails 0.8 0.4 0.2

From Bayes' Rule, I know that P(C|f1,f2,f3) = P(C,f1,f2,f3) / P(f1,f2,f3), and that P(C,f1,f2,f3) = P(C)*P(f1|C)*P(f2|C)*P(f3|C) because the three flips are dependent upon C, but independent of one another. Also, I know that P(f1,f2,f3) = sum(P(C,f1,f2,f3)) over all values of C

Plugging in the numbers, I get the following:

P(C=a,f1=h,f2=h,f3=t) = P(C=a)*P(f1=h|C=a)*P(f2=h|C=a)*P(f3=t|C=a) = .33*.2*.2*.8 = .01056 P(C=b,f1=h,f2=h,f3=t) = P(C=b)*P(f1=h|C=b)*P(f2=h|C=b)*P(f3=t|C=b) = .33*.6*.6*.4 = .04752 P(C=c,f1=h,f2=h,f3=t) = P(C=c)*P(f1=h|C=c)*P(f2=h|C=c)*P(f3=t|C=c) = .33*.8*.8*.2 = .04224 P(f1=h,f2=h,f3=t) = P(f1=h,f2=h,f3=t|C=a) + P(f1=h,f2=h,f3=t|C=b) + P(f1=h,f2=h,f3=t|C=c) = (.2*.2*.8)+(.6*.6*.4)+(.8*.8*.2) = 0.304

With those values, I compute P(C|h,h,t):

P(C=a|h,h,t) = P(C=a,h,h,t) / P(h,h,t) = 0.01056/0.304 = 0.0347 P(C=b|h,h,t) = P(C=b,h,h,t) / P(h,h,t) = 0.04752/0.304 = 0.1558 P(C=c|h,h,t) = P(C=c,h,h,t) / P(h,h,t) = 0.04224/0.304 = 0.1384

I don't think these numbers make sense, however. Shouldn't the sum of P(C|h,h,t) for all values of C be equal to 1? I think I may have done something wrong in my calculation of P(h,h,t) above, as a value of 0.304 would imply that 90% of the time I would end up with two heads and a tails (as P(h,h,t) would be equal to P(h,t,h) and P(t,h,h))

I believe the issue is with this line:

$P(f1=h,f2=h,f3=t) = P(f1=h,f2=h,f3=t|C=a) + P(f1=h,f2=h,f3=t|C=b) + P(f1=h,f2=h,f3=t|C=c) = (.2*.2*.8)+(.6*.6*.4)+(.8*.8*.2) = 0.304$

Each of these three terms should be multiplied by the original probabilities of the assumed condition. i.e. $P(f1=h,f2=h,f3=t|C=a)*P(C=a)$

This scales the .304 (seemed high intuitively to me) of hht to about 0.10. Using this figure, you should get probabilities which sum to 1. I get 10.5%, 47.4%, and 42.1%.

Use,

$$p(c|2H1T) = \frac{p(2H1T|c)}{\sum_{c} p(2H1T|c)}$$

which is a combination of Bayes' theorem and the law of total probability. With this expression you can obtain the probability of each coin given 2 heads and one tail.

• Welcome to the site, @SNR. This answer is being automatically flagged as 'low quality' because it is so short. Can you add some text to explain what this is, how to use it, why it would solve the OP's issue, etc? – gung - Reinstate Monica Dec 17 '15 at 0:55
• Thanks! Do you have any insight on where I went wrong above regarding my conditional probabilities not summing to 1? I'm not sure if I made a mathematical error, or if I'm just understanding something incorrectly – sven Dec 17 '15 at 21:50
• I agree with @MikeP the summation must be weighted by the corresponding probabilities. Note that, in order to obtain the $\text{Pr} (2H1T)$ you are using the law of total probability, then $\text{Pr} (2H1T) = \sum_{c} \text{Pr} (c) \text{Pr} (2H1T|c)$. – SNR Dec 19 '15 at 15:02