# Compute probability given a Bayesian Network

Having the following Bayesian Network:

A -> B, A -> C, B -> D, B -> F, C -> F, C -> G


$$\begin{array}{l} A&\to&B&\to& D\\\downarrow &&\downarrow \\ C&\to&F\\\downarrow\\G \end{array}$$

With the following probabilities:

$$P(+a)=...$$ $$P(+a|+b)=..., P(+a|¬b)=...$$ $$P(+b|+a)=..., P(+b|¬a)=...$$ $$P(+d|+b)=..., P(+d|¬b)=...$$ $$P(+f|+b,+c)=..., P(+f|¬b,+c)=..., P(+f|¬b,¬c)=...$$ $$P(+g|+c)=..., P(+g|¬c)=...$$

I have to compute this $$P(+d, +f, \neg g)$$, that I think is:

$$P(+d, +f, \neg g) = P(+a, +d, +f, \neg g) + P(\neg a, +d, +f, \neg g).$$

My question is: how can I compute each addend?

I think is: $$P(+a, +d, +f, \neg g) = P(+a)·P(+d|+b)·P(+f|+b,+c)·P(\neg g,+c)$$

But I'm using $$b$$ and $$c$$ that there aren't in $$P(+a, +d, +f, \neg g)$$.

NOTE: This question is related to this one: Calculate probability using brute-force method.

You need to marginalize all the variables from the joint distribution: $$p(a,d,f,g) = \sum_{b,c}p(a,b,c,d,f,g) = \sum_{b,c} p(a)p(b|a)p(d|b)p(f|b,c)p(g|c).$$
You plug in $$+d$$, $$+f$$, and $$\neg g$$ and you sum for all combinations of $$\pm b$$ and $$\pm c$$. When you plug in $$+ a$$ you get $$p(+a,+d,+f,\neg g)$$. When you plug in $$\neg a$$, you get $$p(\neg a, +d,+f,\neg g)$$. Finally, you sum these two together and you get the required marginal: $$p(+d,+f,\neg g) =\sum_{a,b,c}p(a)p(b|a)p(c|a)p(+d|b)p(+f|b,c)p(\neg g|c).$$ The sum now runs over all combinations of $$\pm a$$, $$\pm b$$, and $$\pm c$$. Hope this helps!
• You missed a term $$\mathsf P({+}d,{+}f,{\lnot}g)=\sum_{a,b,c} \mathsf P(a)~\mathsf P(b\mid a)~\mathsf P(c\mid a)~\mathsf P({+}d\mid b)~\mathsf P({+}f\mid b, c)~\mathsf P({\lnot} g\mid c)$$ – Graham Kemp May 6 '19 at 6:27
• Thanks, but if I'm trying to compute $P(a| +d, +f, \neg g) = \frac{P(a,+d,+f,\neg g)}{P(+d,+f,\neg g)}$, and both terms, the numerator and denominator will be the same term. Numerator: $P(+a, +d, +f, \neg g) = \sum_{b,c} P(+a, b, c +d, +f, \neg g)$. Denominator: $P(+a, +d, +f, \neg g) = \sum_{a,b,c} P(a, b, c +d, +f, \neg g),$ I will get that $P(a| +d, +f, \neg g) = 1$, isn't it? – VansFannel May 6 '19 at 8:32
• No, at the numerator the sum only runs over $b$ and $c$; at the denominator it runs over $a$, $b$, and $c$. – Riccardo Sven Risuleo May 6 '19 at 8:35
• Basically $\mathsf P(+A\mid \text{theRest})=\dfrac{\mathsf P(+A,\text{theRest})}{\mathsf P(+A,\text{theRest})+\mathsf P(\lnot A,\text{theRest})}$ – Graham Kemp May 6 '19 at 8:43