# Calculating $P(C=F|B=F, G=-2.9)$ in a Bayesian network

I have a network of the following form:
$$[B:{\rm Binary}]\rightarrow [C:{\rm Binary}]\rightarrow [G:{\rm Gaussian}]$$ $[]$ is a node and the arrows show dependency. In this situation, the Gaussian node is a mixture of two Gaussian's since it has a binary parent. I have some training data and use it to learn the parameters of the model. I can do this by hand, and also using a toolbox in MATLAB. The results I get with both are the exact same.

Probability tables: \begin{align} \newcommand{\mean}{{\rm mean}} \newcommand{\cov}{{\rm cov}} B({\rm True}) &= 0.5 \\ C(T|B=T) &= 0, &C(T|B=F) &= 1 \\ C(F|B=T) &= 0.5, &C(F|B=F) &= 0.5 \\ G(C=F) &= \mean + \cov = 0.5667 + -7.8789 \\ G(C=T) &= \mean + \cov = -3.2 + -0.01 \end{align}

However when I'm performing inference, the MATLAB toolbox gives me a different result than what I do by hand.

I'm trying to calculate $P(C=F|B=F,\ G=-2.9)$. I use the following:

1. (Bayes' law)
$$P(C=F|B=F, G=-2.9) = \frac{P(B,G|C)P(C)}{P(B,G)}$$

2. (Marginalization over $C$)
$$\ldots= \frac{P(B,G|C)P(C)}{\sum C(P(B,G|C))}$$

3. $$\ldots= \frac{P(B,G|C)P(C)}{(P(B,G|C)P(C)+P(B,G|\neg C)P(\neg C))}$$

4. (Conditional Independence between $F$ and $G$ given $C$)
$$\ldots= \frac{P(B|C)P(G|C)P(C)}{(P(B|C)P(G|C)P(C)+P(B|\neg C)P(G|\neg C)P(\neg C))}$$

5. (due to the direction of dependence in the graph, therefore it cancels out of the equation)
$$\ldots\ P(B|C) = P(B)$$

6. $$\ldots = \frac{P(G|C)P(C)}{(P(G|C)P(C)+P(G|\neg C)P(\neg C))}$$

7. We can calculate $P(G|C)$ from the specific PDF, and $P(C)$ from marginalization using $\sum F(P(C|B))$.

\begin{align} P(C=F) &= 0.75, &P(C=T) &= 0.25 \\ P(G=-2.9|C=F) &= 0.0663, &P(G=-2.9|C=T) &= 0.0443 \end{align}

My final solution is: $0.0663\times 0.75/(0.0663\times 0.75 + 0.0443\times 0.25) = 0.8178$
The solution that the MATLAB program is giving me is: $0.5993$.

The MATLAB program is the BNET toolbox, so I'm more inclined to think I'm doing something wrong in my calculation. But I just can't figure out what it is.

• I also figured out what the Matlab program ends up with as the calculation - 0.0663/(0.0663+0.0443) = 0.5995. So for some reason the P(C) drops out. – Sacha Gunaratne Jun 28 '17 at 16:30
• Thanks @gung I didn't realize I could use Latex commands. Everything looks good. I will use Latex in the future to make sure everything is clear. – Sacha Gunaratne Jun 28 '17 at 16:51

My assumption on Step 5 was incorrect:

$$\ldots\ P(B|C) = P(B)$$

I can calculate it using Bayes law: $$P(B|C) = \frac{P(C|B)P(B)}{P(C)}$$

$$P(B=F|C=F) = \frac{P(C=F|B=F)P(B=F)}{P(C=F)}$$

$$P(B=F|C=F) = \frac{0.5\times0.5}{0.75} = \frac{1}{3}$$

and

$$P(B=F|C=T) = \frac{0.5\times0.5}{0.25} = \frac{1}{1} = 1$$

Therefore my final equation is:

$$P(C=F|B=F,G=-2.9)=\frac{P(B|C)P(G|C)P(C)}{P(B|C)P(G|C)P(C)+P(B|\neg C)P(G|\neg C)P(\neg C)}$$

$$= \frac{\frac{1}{3}\times0.0663\times 0.75}{\frac{1}{3}\times0.0663\times 0.75+ 1\times 0.0443\times 0.25} = 0.5995$$

Which is the exact same answer as the MATLAB program.