# Probabilistic Graphical Models

The goal of causal inference is to figure out a causal relationship, or the lack thereof, between two sets of variables; causes and outcomes. It is thus only natural to think of how we determine whether any particular variable is a cause or an outcome. It is often relatively more straightforward to determine what an outcome variable is, as this determination is done based on our subjective interest. For instance, a typical outcome variable in medicine is a disease-free survival rate within some years since diagnosis or treatment. This choice is natural, since this variable, or its quantity, is what we want to maximize. It is however much less clear how to determine which variable should be considered a cause. For instance, in the classical example of ‘smoking causes lung cancer’, what makes us choose ‘whether someone smokes ciagarettes’ as a cause variable rather than ‘a mutation in a particular gene’? It becomse even more mind-boggling once we realize that this choice of ‘smoking’ as a cause meant that we decided to ignore many variables, such as ‘whether a farmer decided to grow tobacco’. It is thus an important, if not the most important, job for practitioners of causal inference to convincingly argue why some variables are included and others were omitted. They also must argue why some of the included variables are considered potential causes and why they chose a particular variable as an outcome. This process can be thought of as defining a small universe in which causal inference must be performed. There are many different ways to define and describe such a universe, and in this lecture note, we largely stick to using a probabilistic graphical model, or a corresponding structural causal model, as a way to describe each universe, which is the main topic of this chapter.

## Probababilistic Graphical Models

In this course, we rely on probabilistic graphical models quite extensively in order to describe their statistical and causal relationships among random variables. A probabilistic graphical model, which is also referred as a Bayesian graphical model, is a directed graph $G=(V,E)$, where $V$ is a set of vertices/nodes and $E$ is a set of directed edges. Each node $v \in V$ corresponds to a random variable, and each edge $e = (v_s, v_e)$ represents the dependence of $v_e$ on $v_s$. Let us for now assume that this graph is acyclic, that is, there is no cycle within this graph. In other words, $G$ is a directed acyclic graph, throughout the rest of this course. For each node $v \in V$, we define a probability distribution $p_v(v | \mathrm{pa}(v))$ over this variable conditioned on all the parent nodes

[] \begin{align} \mathrm{pa}(v) = \left\{ v' \in V | (v', v) \in E \right\}. \end{align} []

We can then write a joint distribution over all the variables as

[] \begin{align} p_V (V) = \prod_{v \in V} p_v(v | \mathrm{pa}(v)), \end{align} []

following the chain rule of probabilities. When $\mathrm{pa}(v) = \emptyset$, i.e. $v$ does not have any incoming edges, we call the associated distribution $p_v(v)$ a prior distribution. With $P$ a set of all conditional probabilities $p_v$'s, we can denote any probabilistic graphical model as a triplet $(V, E, P)$. From this joint distribution, we can derive all kinds of conditional distributions by marginalizing variables and applying the definition of a conditional probability. If we are not interested in a particular node $\bar{v} \in V$, we can marginalize out this variable by

[] \begin{align} p(V \backslash \{\bar{v}\}) = \sum_{\bar{v}} p_V (V). \end{align} []

If $\bar{v}$ is a continuous random variable, we replace $\sum$ with $\int$. We can always turn a joint probability into a conditional probability by

[] \begin{align} p(V \backslash \{\tilde{v}\} | \tilde{v}) = \frac{p_V(V)}{p_{\tilde{v}}(\tilde{v})}. \end{align} []

Using the definition of the conditional probability, we can write marginalization in the following way:

[] \begin{align} p(V \backslash \{\bar{v}\}) = \sum_{\bar{v}} \frac{p_V(V)}{p_{\tilde{v}}(\tilde{v})} p_{\tilde{v}}(\tilde{v}) = \sum_{\bar{v}} p(V \backslash \{\bar{v}\}) p_{\tilde{v}}(\tilde{v}). \end{align} []

Marginalization corresponds to computing the weighted sum of the conditional probability of the remaining variables according to the marginal probability of the variable being marginalized. Let's assume we can sample readily from any conditional probability $p_v$ with $v\in V$. We can then draw a sample from the joint distribution readily by breadth-first sweeping of all the variables. That is,

[] \begin{align} \tilde{v} \sim p_v (v | \tilde{\mathrm{pa}}(v)), \end{align} []

where $\tilde{\mathrm{pa}}(v) = \left\{ \tilde{v}' \sim p_{v'}(v' | \tilde{\mathrm{pa}}(v')) | v' \in \mathrm{pa}(v) \right\}$. This procedure is called ancetral sampling and is an exact, unbiased way to sample from this joint distribution. If we set aside efficiency, ancestral sampling is an extremely powerful tool, as it allows us to sample from any marginal distribution as well as any conditional distribution. In the former case, we simply discard the draws that correspond to the uninteresting variables (that are being marginalized). In the latter case, we only keep samples whose values, corresponding to the conditioning variables (that are on the right hand side of $|$), are precisely those that we want the distribution to be conditioned on. Both of these approaches are not efficient, and it is often much better to use a more sophisticated sampling algorithm, often based on the idea of Markov Chain Monte Carlos (MCMC). Any probability distribution can be expressed as a table (though, this table may have infinitely many rows) that consists of two columns. The first column takes the value of interest and the second column its probability (either density or mass). The probability function $p_v$ above works by hashing $v$ into the row index in this table and retrieving the associated probability, i.e. $p_v: \mathbb{V} \to \mathbb{R}_+$. This function satisfies the following normalization property:

[] \begin{align} 1 = \begin{cases} \sum_{v \in \mathbb{V}} p_v (v),&\text{ if } v \text{ is discrete.} \\ \int_{v \in \mathbb{V}} p_v (v) \mathrm{d}v,&\text{ if } v \text{ is continuous.} \\ \end{cases} \end{align} []

This view allows us to effectively turn a set of samples into the original distribution from which these samples were drawn (of course, with some variance.) Let $S = \left( \tilde{v}_1, \tilde{v}_2, \ldots, \tilde{v}_N \right)$ be a multi-set of samples drawn from an unknown distribution over a discrete variable $v$, without loss of generality. We can then recover the original distribution by constructing a table where each row is

[] \begin{align} \left(v, \left. \sum_{n=1}^N \mathds{1}(\tilde{v}_n = v) \right/ N \right), \end{align} []

with $v \in \mathbb{V}$. This corresponds to maximum likelihood learning without any regularization. In this table, we can think of all these rows' contents as the parameters of this model we have built to approximate the underlying distribution from which $S$ was drawn. This view will come handy later when we discuss using a deep neural network instead of an explicit table to represent a probability distribution. A major downside of this explicit table based approach is that $q_v(v) = 0$ for all $v \not \in S$. Such an extreme value (the probability of $0$) should not be used when we estimate these probabilities from a small number of data points, since we cannot rule out the fact that we simply did not see that particular instance just because we did not draw enough samples. Furthermore, this prevents us from properly defining a conditional probability $p_{v'} (v' | v)$, since

[] \begin{align} p_{v'} (v' | v) = \frac{p_{v',v} (v', v)}{p_v(v)}. \end{align} []

If $v$ is set such that $p(v) = 0$, this conditional probability is not well defined. We thus have to regularize maximum likelihood learning. This probabilistic graphical model is a good way to abstract out some of the details on how to implement individual probability distributions for studying causal inference in machine learning, as it frees us from worrying about the aspect of learning until it is absolutely necessary. Learning in this context refers to inferring the underlying distribution from which data points were drawn, and the table-based approach above is the most naive one that is not really useful in practice. We can however for now assume that this table-based approach works well and continue studying causal inference with already inferred conditional distributions.

## Structural Causal Models

Although a directed edge in the probabilistic graphical model looks like it encodes the order in which the variables are generated, it is not necessarily so from the perspective of probability. According to the Bayes' rule,

[] \begin{align} p_v(v | v') = \frac{p_{v'}(v' | v) p_v(v)}{p_{v'}(v')}. \end{align} []

This implies that we can always flip the arrow of the edge between $v$ and $v'$ without altering the joint as well as conditional probabilities.[Notes 1] This lack of direct relevance of the direction of each edge in $G$ to the joint probability raises a lot of confusion, when we try to use the probabilistic graphical model in the context of causal inference and reasoning. Instead, we may want to use a slightly different way to express the same generative process underlying a given probability graphical model $G=(V,E)$. We do so by writing the process of sampling a value associated with each variable $v \in V$ rather than its distribution, as the combination of a deterministic function $f_v$ and external (exogenous) noise $\epsilon_v$:

[] \begin{align} v \leftarrow f_{v}(\mathrm{pa}(v), \epsilon_v). \end{align} []

This says that the value of $v$ is computed based on the values of its parent nodes $\mathrm{pa}(v)$ and external noise $\epsilon_v$ by the deterministic function $f_{v}$. This way is much more explicit about the generating process than before, since the use of the function $f$ clearly suggests that perturbing the output of the function would not change the input to the function, although perturbing the input to the function would change the output. For instance, you can imagine that $f_v$ corresponds to pushing a book on your desk using your hand with force of $v'$ and that $v$ encodes the new position of the book. $\epsilon_v$ can be an unknown level of friction cause by your earlier (but forgotten) choice of your desk. Changing force $v'$ of course affects the new position of the book $v$ together with some changing level of $\epsilon_v$, but changing the position of the book would not change the force I have not applied yet to the book. We call this representation of the generative process a structural causal model. Similarly to the probabilistic graphical model above, we can represent any structural causal model as a triplet $(V, F, U)$, where $V$ is a set of variables, $F$ is a set of corresponding functions and $U$ is a set of corresponding noise variables. Any structural causal model can be turned into a probabilistic graphical model by using the change of variables, i.e., $f_{v}(\mathrm{pa}(v), \cdot)$ and assuming the known prior distribution over the external noise variable $\epsilon_v$. Or, more simply, we can do so because we can find a distribution over $v \sim f_v (\mathrm{pa}(v), \epsilon_v)$. We can draw samples from any given structural causal model, just like with the probabilistic graphical models above, by ancestral sampling. Once we have samples from the joint distribution, we can infer various conditional distributions. Among these, the posterior distribution over the external noise variables is of a particular interest for the purpose of counterfactual reasoning. Let $q(U)$ be a distribution that corresponds to all samples of $\epsilon_v$'s that led to a particular configuration $\hat{V}$. Then the posterior distribution $q(v)$ can be thought of as the distribution over the external (uncontrollable) factors that led to the particular outcome. We then can answer the question what would have happened to a target variable $v$ had some of the variables were set differently, by fixing the external factors to follow $q(v)$ and the rest of the variables to the original values $\hat{V}$. This corresponds to counterfactual reasoning (had I done something differently, what would have happened?)

## Learning and a generative process

Learning, in machine learning, refers to the process by which we configure a black box predictive model to capture the predictive relationship between a set of variables. In the simplest form, let us consider having two variables; input $v$ and output $v'$. $g_\theta$ is a predictive function that models the relationship between $v$ and $v'$ by mapping an instance of $v$ to the corresponding $v'$, i.e., $g_{\theta}(v')$ is the prediction of $v'$ given $v$. $\theta$ is a collection of parameters that a learning algorithm configures to make $g$ as predictive of $v$ given $v'$ as possible. Learning starts from data which is a set of examples drawn from an unknown data generating process $\mathcal{G}$. This data generating process can be described using either a probabilistic graphical model or equivalently a structural causal model. Let $D=\left\{ (v_1, v_1'), \ldots, (v_N, v_N') \right\}$ be our training dataset. The goal is then to use this dataset to infer $\theta$ that would make $g$ highly predictive of $v$ given $v'$. There are many ways to measure how predictive $g$ is given a pair $(v, v')$, but we use here a log probability:

[] \begin{align} r(\theta; v,v') = \log p(v | v'; g_\theta(v')). \end{align} []

This means that $g_{\theta}(v')$ parameterized a conditional distribution over $v$ given $v'$, or equivalently, $g_{\theta}(v')$ outputs a conditional distribution over $v$. If this quantity is large, it means that $v$ is highly probable under the predictive distribution by $g$ given $v'$. Learning is then to solve the following optimization problem:

[] \begin{align} \arg\max_{\theta} \frac{1}{N} \sum_{n=1}^N r(\theta; v_n, v_n'). \end{align} []

Once learning is over, we can readily compute

[] \begin{align} p (v|v') \approx p(v|v'; g_{\theta}(v')) = p(v|v'; \theta). \end{align} []

If we assume that $p(v | v'; \theta)$ is a great approximation of $p(v|v')$, we can use the former in place of the latter without too much worry. In other words, learning corresponds to figuring out a conditional distribution $p(v|v')$ from data. This data was produced from the underlying data generating process $\mathcal{G}$ which may have more variables in addition to $v$ and $v'$. From this description of learning, it is immediately clear how this can be a replacement of the table-based approach from earlier, and that the table-based approach earlier was a special case of this learning-based approach, where $\theta$ corresponded to all the entries within a table. Once we take this learning-based approach, we can free ourselves from having to explicitly construct a large table and can also use various regularization techniques to avoid the issue of $0$ probability as well as benefit from generalization. Let $\mathcal{G}=(V, E, P)$ with $v, v' \in V$ and $\overline{V} = V \backslash \left\{ v, v' \right\}$. Then,

[] \begin{align} p(v | v') = \frac{\sum_{\overline{V}} p(\{v,v'\} \cup \overline{V})}{\sum_{\{v\} \cup \overline{V}} p(\{v'\} \cup V')}. \end{align} []

That is, we marginalize out all variables in $\overline{V}$ and then divide it by the marginal probability of $v'$ to get the conditional probability of $v$ given $v'$. On one hand, this tells us that learning allows us to recover any arbitrary conditional distribution induced by an underlying data generating process as long as we have data produced following the same data generating process. On the other hand, this also tells us that there can be many different data generating processes that result in the exactly same conditional distribution given a pair of variables. In fact, as long as we do not use all variables from the generating process, there will always be ambiguities that cannot be resolved based on the learning procedure laid out above. As an example, consider the following two structural causal models:

Causal Model 1.

[] \begin{align} &v' \leftarrow \epsilon_{v'} \\ &v^l \leftarrow v' + a + \epsilon_{v^l} \\ &v^r \leftarrow v' + b + \epsilon_{v^r} \\ &v \leftarrow v^l + v^r + \epsilon_{v}, \end{align} []

where $\epsilon_{v^l}$ and $\epsilon_{v^r}$ both follow standard Normal distributions ($\mathcal{N}(0, 1^2)$. $\epsilon_{v}$ also follows standard Normal distribution.

Causal Model 2.

[] \begin{align} &v' \leftarrow \epsilon_{v'} \\ &v^c \leftarrow v' + a + b + \epsilon_{v^c} \\ &v \leftarrow v^c + \epsilon_{v}, \end{align} []

where $\epsilon_{v^c} \sim \mathcal{N}(0, 2)$. Then, $p(v|v') = \mathcal{N}(v; v'+a+b, 3)$ for both causal models, although these two models are very different. This ambiguity plays an important role in both causal inference and so-called out-of-distribution generalization. We will study both more carefully later in the course.

## Latent variable models are not necessarily causal models

When we build a predictive model on a pair $(v, v')$, there are variables that are left out from the original data generating process. Those unused variables may be the ones for which we simply threw away observations, because they were not in our interest, or the ones we actually do not observe. These unobserved variables contribute to the complexity of $p(v|v')$ via the process of marginalization. It is not trivial to build a predictive model, or equivalently in our context a deep neural network, that outputs a highly complex predictive distribution, as these complex distributions often do not have easily-parametrizable analytical forms. In these cases, there are two commonly used approaches; (1) autoregressive models and (2) latent variable models. The former relies on the chain rule of probabilities and decomposes the conditional probability as a product of coordinate-wise conditional probabilities:

[] \begin{align} p(v|v'; \theta) = \prod_{i=1}^d p(v_i | v'; \theta), \end{align} []

where $v = [v_1, \ldots, v_d]$. By assuming that each coordinate-wise conditional probability is of a simpler form, we can still use a simple deep neural network to approximate a highly complex joint conditional probability. Because each conditional probability on the right hand side is parametrized with the same set of parameters $\theta$, it is possible to build such an autoregressive model for a variable-sized observation, that is, $\mathrm{dim}(v)$ is not fixed a priori. This approach is behind the recently successful and popular large-scale language models~[1]. Unlike autoregressive modeling, latent variable models explicitly introduce an unobserved variable $u$ that represents the missing portion of the underlying data generating process. Just like the missing (unobserved) portion gave rise to the highly complex predictive distribution via the process of marginalization, the introduced (anonymous) latent variable $u$ does the same:

[] \begin{align} p(v|v'; \theta) = \sum_{u} p_u(u) p(v|v', u; \theta). \end{align} []

If $u$ is continuous, we replace $\sum$ with $\int$. Because this marginalization is difficult almost always, it is natural to resort to sampling-based approximation. Because we are often interested in gradient-based learning, we consider sampling-based gradient approximation:

[] \begin{align} \nabla \log p(v|v'; \theta) &= \sum_u \frac{p_u (u) p(v|v', u; \theta) \nabla \log p(v|v', u; \theta) } {\sum_{u'} p_u(u') p(v|v', u'; \theta)} \\ &= \sum_u p(u | v, v'; \theta) \nabla \log p(v|v', u; \theta) \\ &\approx \frac{1}{M} \sum_{m=1}^M \nabla \log p(v|v', u^m; \theta), \end{align} []

where $u^m$ is the $m$-th posterior sample. It is however as challenging to compute the posterior distribution $p(u | v, v'; \theta)$ nor to sample from it. It is thus more common these days to maximize the lower bound to $p(v|v'; \theta)$ while amortizing approximate posterior inference into a separate neural network. This is called a variational autoencoder~[2]. Despite the seemingly similarity, these latent variables are not closely related to actual variables in the data generating process. They may or may not. If they indeed correspond to actual variables in the data generating process that we simply did not observe nor decided not to use data from, we may be able to derive conditions under which we can identify these unobserved variables and their associated distributions from partial data alone. It is however more common and realistic to think of these latent variables as a means to improving the expressive power of a deep neural network. In other words, latent variables are useful even if there are truly two variables, $v$ and $v'$, in the data generating process, since true $p_v(v|v')$ may be complicated on its own. Nevertheless, it is a useful tool to model any complex distribution, and thus we have spent a little bit of time discussing them.

## Summary

In this chapter, we have established the very foundations on which we can discuss causal inference and its relationships to machine learning in the rest of the course:

• A brief discussion on the necessity of defining a universe over which causal inference is performed;
• Two (equivalent) ways to define a universe, probabilistic graphical models and structural causal models;
• What learning is, once the universe is defined.

Based on these, we begin our journey into causal inference in machine learning.

## General references

Cho, Kyunghyun (2024). "A Brief Introduction to Causal Inference in Machine Learning". arXiv:2405.08793 [cs.LG].

## Notes

1. We will assume from here on that $p(x) \gt 0$ for any $x$ and $p$.

## References

1. "Language models are few-shot learners" (2020). Advances in neural information processing systems 33.
2. "Auto-encoding variational bayes" (2013). arXiv preprint arXiv:1312.6114.