# Derive Probabilities from Bayesian Network

I have given the following Bayesian network.

I already know the fundamentals, for example, pairwise dependencies and how to calculate the total joint probability:

$$P(M,B,S,C,H) = P(M)\cdot P(S|M)\cdot P(B|M)\cdot P(C|S,B)\cdot P(H|B)$$

But now I want to calculate $$P(M|S,C,H)$$. I can easily apply Bayes Theorem to get:

$$P(M|S,C,H) = \frac{P(M,S,C,H)}{P(S,C,H)}$$

But I do not know how to calculate $$P(M,S,C,H)$$ and $$P(S,C,H)$$. I tried to solve it and got $$P(M|S,C,H) = 0.5$$. I strongly doubt that my calculations are correct because from sampling from the network with $$1.000.000$$ I got a relative frequency of about $$0.2$$.

EDIT: The sampling was performed incorrectly. It just proved that $$P(M=1) = 0.2$$. When performed correctly, it can be shown that the correct solution can be approximated with the sampled data from the network.

Your formulae are correct. Furthermore: \begin{align} P(M, S, C, H) &= \sum_{B} P(M, B, S, C, H)\\ P(S, C, H) &= \sum_{B, M} P(M, B, S, C, H), \end{align} are just the marginalizations. And you already have the formula for $$P(M, B, S, C, H)$$.
• This would mean that I get a result of $\frac{0.02432}{0.0448} \approx 0.5429$. Why does it not match with the values I got from sampling? Commented Jul 22, 2022 at 14:19
• You should get not just one conditional probability, but $2^3=8$, one for each combination of $S, C, H$: $P(M|S=0, C=0,H=0), P(M|S=0, C=0, H=1), ..., P(M|S=1, C=1, H=1)$. Commented Jul 22, 2022 at 14:24
• Yeah, I know but I assumed $P(M|S,C,H)=P(M=1|S=1,C=1,H=1)$ and $P(\overline{M}|\overline{S},\overline{C},\overline{H})=P(M=0|S=0,C=0,H=0)$ Commented Jul 22, 2022 at 14:35
• I don't understand. The expression $P(M|S,C,H)$ is a function with four variables, and you need to know the value for all combinations. You can use $P(M=1|S,C,H) = 1-P(M=0|S,C,H)$ because $M$ is binary, so you only have to compute eight values $P(M=0|S,C,H)$ for each combination of binary values for $S,C,H$. Commented Jul 22, 2022 at 14:57
\begin{align} P(M=1|HCS=1)\overset{Bayes' law}= &\frac{P(HCS|M)\cdot P(M)}{P(HCS)}\\ =& \frac{P(S|M) \cdot P(C|M) \cdot P(H|M) \cdot P(M)}{P(H) \cdot P(C) \cdot P(S)}\\ \text{with:}\\ P(S|M) =& 0.2\\ P(C|M) =& 0.8 \cdot 0.8 + 0.8 \cdot 0.2\\ P(H|M) =& 0.8 \cdot 0.8 + 0.6 \cdot 0.2\\ P(M) =& 0.2\\ \text{and:}\\ P(H) =& 0.8 \cdot 0.8 + 0.2 \cdot 0.6\\ P(C) =& 0.2 \cdot 0.8 \cdot 0.8 +\\ & 0.8 \cdot 0.8 \cdot 0.8 +\\ & 0.2 \cdot 0.2 \cdot 0.8 +\\ & 0.8 \cdot 0.2 \cdot 0.05\\ P(S) =& 0.2 \cdot 0.2 + 0.8 \cdot 0.05 \end{align} With that you get $$P(M=1|HCS=1) \approx 0.588$$.