# Bayesian and Markovian Networks: How do we obtain the probabilities at each node in a Bayesian or Markovian network

I just have a very basic 2 part question about Bayesian and Markovian networks. I suppose my confusion stems by trying to learn about these things through blog posts and videos, and not being able to ask someone direct clarifying questions, but hopefully someone here can ally my confusion.

The 2 questions are explained below. But here are the questions for easy reference.

1. How are the probabilities computed at each node in a Bayesian or Markovian network.
2. Can we, or how can we use continuous distributions at different nodes?

Say I have a Bayesian network like the one pictured below. I would like to understand how the probability distribution is setup at each node in the network. That is, usually the probability distribution at each node is setup as a simple table with a discrete probability distribution. Now, if I have a dataset and I want to create the distribution for each node, do I just subset the table and then compute the simple frequencies? For example in the table to compute the distribution over "Congestion" would I just subset my dataset and manually compute the number of times someone has congestion given that the have the flu, over the total number of people with congestion. And then compute the total number of times that someone has congestion given hayfever, divided by the total number of people with congestion. I am not sure if I might need to renormalize the probabilities, but would it just be that simple to obtain the discrete distribution for each node? I might just be overthinking it because I am used to applying multivariate control on things like this--but the graphical structure of the model seems to be handling the multivariate control that I would use in some regression. I mean, some of the people who have Hayfever might have the Flu at the same time, so how do we deal with this?

The second question is what to do with continuous distributions. Is it possible to use a continuous distribution for the node? Technically I could discretize the continuous distribution but I was just wondering if something like that is possible, and how we would again estimate the distribution from data. Again, it is just creating a distribution from the table, or is there anything more than that.

Thanks for any assistance with clarifying how Bayesian and Markov networks work.

• I've completed my answer, so let me know if anything isn't clear. Commented Jul 9, 2021 at 22:45
• @mhdadk thanks so much for the answer. The only thing I was still not clear on what how the probabiltiies are assigned at each node. Is it just as simple as getting the frequencies from the table of data? Is multivariate control applied through the structure of the network? Commented Jul 10, 2021 at 15:44
• "the table of data" could you be more specific? Commented Jul 10, 2021 at 16:36
• @mhdadk Ahh, sorry. I come from Statistics so usually think in terms of estimating parameters. In my naive mind, I should be estimating the conditional probabilities using some likelihood function. But in the Koller book and other places, they just show a table of the discrete values of P(Congestion | Hayfever, Flu). So is it just as simple as calculating the conditional probability at each node from a table, or is there an algorithm to calculate those conditional probabilities. That is why I was a bit confused about multivariate control, since say season can affect both hayfever and flu. Commented Jul 10, 2021 at 17:51
• Just use Bayes' rule to compute P(Congestion | Hayfever, Flu). To do this, you would need to compute P(Congestion,Hayfever, Flu) in the numerator P(Hayfever, Flu) in the denominator. Both of these can be computed using belief propagation. Commented Jul 10, 2021 at 19:26

The purpose of both Bayesian networks and Markov networks is to represent conditional independencies, although each of them have slightly different ways of doing so. In a Bayesian network, conditional independencies can be understood using the Markov condition. It states that for each node in a Bayesian network, the random variable in this node is conditionally independent of its non-descendants given its parents.

To better understand this, consider the Flu random variable in the Bayesian network in your question. Its descendants are Muscle-Pain and Congestion. This means that Season and Hayfever form its set of non-descendants. However, Season is also Flu's parent, and so we don't include it in Flu's set of non-descendants. Therefore, $$\text{Flu} \perp \text{Hayfever} \ \mid \ \text{Season}$$ which reads as "Flu is independent of Hayfever given Season". Now suppose that we are interested in computing $$p(\text{Flu})$$. Using the law of total probability, $$p(\text{Flu}) = \sum_{\text{Season},\text{Hayfever},\\ \text{Congestion},\\ \text{Muscle-Pain}} p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain})$$ Using Bayes' rule $$p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain}) = \\ p(\text{Muscle-Pain} \mid \text{Season},\text{Hayfever},\text{Congestion},\text{Flu}) \times \\ p(\text{Congestion} \mid \text{Hayfever},\text{Season},\text{Flu}) \times \\ p(\text{Flu} \mid \text{Season},\text{Hayfever}) \times \\ p(\text{Hayfever} \mid \text{Season}) \times \\ p(\text{Season})$$ However, we know that Flu is independent of Hayfever given Season, and so the term $$p(\text{Flu} \mid \text{Season},\text{Hayfever})$$ becomes $$p(\text{Flu} \mid \text{Season})$$ We can then use the Markov condition to deduce other conditional independencies from the Bayesian network. These are $$\text{Season} \perp \emptyset \ \mid \ \emptyset \\ \text{Hayfever} \perp \text{Flu},\text{Muscle-Pain} \ \mid \ \text{Season} \\ \text{Muscle-Pain} \perp \text{Hayfever},\text{Congestion},\text{Season} \ \mid \ \text{Flu} \\ \text{Congestion} \perp \text{Season},\text{Muscle-Pain} \ \mid \ \text{Flu},\text{Hayfever} \\$$ where $$\emptyset$$ indicates no parents or no non-descendants. We can use these to simplify the expression for $$p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain})$$ even further, such that $$p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain}) = \\ p(\text{Muscle-Pain} \mid \text{Flu}) \times \\ p(\text{Congestion} \mid \text{Hayfever},\text{Flu}) \times \\ p(\text{Flu} \mid \text{Season}) \times \\ p(\text{Hayfever} \mid \text{Season}) \times \\ p(\text{Season})$$ What did we gain from this simplification? More generally, what did we gain from representing these conditional independencies using a Bayesian network? Notice that if we want to compute $$p(\text{Flu}) = \sum_{\text{Season},\text{Hayfever},\\ \text{Congestion},\\ \text{Muscle-Pain}} p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain})$$ which actually consists of 4 summations: $$p(\text{Flu}) = \sum_{\text{Season}} \sum_{\text{Hayfever}} \sum_{\text{Congestion}} \sum_{\text{Muscle-Pain}} p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain})$$ Let us substitute $$p(\text{Flu},\text{Season},\text{Hayfever},\text{Congestion},\text{Muscle-Pain}) = \\ p(\text{Muscle-Pain} \mid \text{Flu}) \times \\ p(\text{Congestion} \mid \text{Hayfever},\text{Flu}) \times \\ p(\text{Flu} \mid \text{Season}) \times \\ p(\text{Hayfever} \mid \text{Season}) \times \\ p(\text{Season})$$ into this summation, such that $$p(\text{Flu}) = \sum_{\text{Season}} \sum_{\text{Hayfever}} \sum_{\text{Congestion}} \sum_{\text{Muscle-Pain}} \\ p(\text{Muscle-Pain} \mid \text{Flu}) \times \\ p(\text{Congestion} \mid \text{Hayfever},\text{Flu}) \times \\ p(\text{Flu} \mid \text{Season}) \times \\ p(\text{Hayfever} \mid \text{Season}) \times \\ p(\text{Season})$$ Notice that we can re-arrange and distribute the summations such that $$p(\text{Flu}) = \\ \left[\sum_{\text{Muscle-Pain}} p(\text{Muscle-Pain} \mid \text{Flu}) \\ \left[\sum_{\text{Congestion}} \sum_{\text{Hayfever}} p(\text{Hayfever} \mid \text{Season}) \cdot p(\text{Congestion} \mid \text{Hayfever},\text{Flu}) \\ \left[\sum_{\text{Season}} p(\text{Season}) \cdot p(\text{Flu} \mid \text{Season})\right]\right]\right]$$ This a bit messy, so let us clean it up by letting: \begin{align} \phi_1(\text{Flu}) &= \sum_{\text{Season}} p(\text{Season}) \cdot p(\text{Flu} \mid \text{Season}) \\ \phi_2(\text{Season},\text{Flu}) &= \phi_1(\text{Flu}) \cdot \sum_{\text{Congestion}} \sum_{\text{Hayfever}} p(\text{Hayfever} \mid \text{Season}) \cdot p(\text{Congestion} \mid \text{Hayfever},\text{Flu}) \\ \phi_3(\text{Season},\text{Flu}) &= \phi_2(\text{Season},\text{Flu}) \cdot \sum_{\text{Muscle-Pain}} p(\text{Muscle-Pain} \mid \text{Flu}) \\ p(\text{Flu}) &= \phi_3(\text{Season},\text{Flu}) \end{align} So, computing $$p(\text{Flu})$$ now involves a sequence of recursive calculations. Additionally, we have drastically reduced the number of additions and multiplications that we need to perform by

1. Making use of the conditional independencies induced by the Bayesian network
2. Re-arranging and distributing the summations.

This two-step process is encapsulated by the Belief Propagation algorithm. To summarize: Why are probabilistic graphical models useful? Because they allow us to model conditional independencies, which in turn allow us to compute probabilities very efficiently.