# Calculating marginals in multiply connected network

I am stuck with an excercise which is similar to this one. The idea is to calculate the probability mass function $$p(g)$$ from the joint probability that a given bayesian network implies.

This graph implies the factorization $$p(a,b,c,d,e,f,g) = p(a)*p(b|a)*p(d|b)*p(f|d)*p(g|f)*p(c|a)*p(e|c)*p(g|e)$$ and i know that I can calculate $$p(g)$$ by marginalizing out the other variables, i.e. : $$p(g) = \sum_{a,b,c,d,e,f} p(a)*p(b|a)*p(d|b)*p(f|d)*p(g|f)*p(c|a)*p(e|c)*p(g|e).$$ The excercise is to do the calculation by hand but I don't think the idea is too sum up the 2^64 terms so I'm guessin that there is some way to simplify the problem. All the other examples about calculations in bayesian networks had some singly connected components but I can't find a way to simplify the given distribution. I found out that "every variable that is not an ancestor of a query variable or evidence variable is irrelevant to the query", but as all the other variables are ancestors of g I don't think I can simplify this term by pulling in the summation. So any hint on how to solve this is appreciated, thanks! Edit: I'm given exactly the conditional probabilities that appear in the summation.

• Just a minor correction: could it be $p(d|b)$ instead of $p(d|a)$? Commented Nov 6, 2016 at 21:44
• yes, definitely, sorry for the mistake. Commented Nov 6, 2016 at 22:12