Part 6 - Graphical Models I

Introduction

In this part, we will introduce Bayesian networks, which are probabilistic graphical models that represent a set of variables and their conditional dependencies via a directed acyclic graph (DAG). Bayesian networks are powerful tools for modeling complex systems and reasoning under uncertainty. We will discuss some fundamental theory and their applications.

Graphical Models

Intuition (Graphical Models)

Graphical models are a powerful framework to represent and learn structured probability models.

The main idea behind graphical models is that they capture a way in which a joint distribution can be factorized into product of factors, each depending only on a subset of variables. They are generally useful for, visualizing the structure of a probabilistic model, encoding structural information (i.e., dependencies) about involved random variables, and provide structure in computations, i.e., provide graph-based algorithms for computations, inference, and prediction.

There are three main types of graphical models,

  1. Bayesian Networks (or Bayes nets) which are DAGs 1Directed Acyclic Graphs (DAGs) are graphs with directed edges and no cycles.. They represent a set of random variables and their conditional dependence structure.

  2. Markov Random Fields which are undirected graphs. They represent a set of random variables and their Markov structure (i.e., conditional independence structure).

  3. Factor Graphs. Which are more convenient for the purposes of inference and learning.

Bayesian Networks

Definition 1 (Bayesian Networks)

In a Bayesian network, we have two types of elements.

  1. Nodes represents the random variables and more specifically, an empty node is an unobserved variable, while a shaded node is an observed variable.

  2. Edges represents the relationships between the random variables.

Further, the bayesian netowrk encodes a factorization of a join distribution.

Assume we have KK random variables {x1,x2,,xK}\{\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K\} with join probability distribution p(x1,x2,,xK)p(\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K), we know by the chain rule of probability that,

p(x1,x2,,xK)=p(x1)p(x2x1)p(x3x1,x2)p(xKx1,x2,,xK1)=i=1Kp(xip(xi))\begin{align*} p(\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K) & = p(\mathsf{x}_1) p(\mathsf{x}_2 \mid \mathsf{x}_1) p(\mathsf{x}_3 \mid \mathsf{x}_1, \mathsf{x}_2) \cdots p(\mathsf{x}_K \mid \mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_{K-1}) \newline & = \prod_{i=1}^{K} p(\mathsf{x}_i \mid p(\mathsf{x}_i)) \newline \end{align*}

To build a Bayesian network we need,

  1. Introduce a node for each x\mathsf{x} and associate the node with p(x)p(\mathsf{x} \mid \cdot).

  2. For each p(x)p(\mathsf{x} \mid \cdot), draw a directed edge to node x\mathsf{x} from nodes corresponding to RVs on which the distribution is conditioned.

  3. Edge from node x\mathsf{x} to node x~\tilde{\mathsf{x}}, x\mathsf{x} parent of x~\tilde{\mathsf{x}}, x~\tilde{\mathsf{x}} child of x\mathsf{x}.

Example Bayesian Network
Example Bayesian Network
Example 1 (Bayesian Network Example)

Consider the network in Figure 1, the corresponding joint distribution is given by,

p(x1,x2,x3,x4,x5)=p(x1)p(x2)p(x3x1)p(x4x1,x3)p(x5x2,x3,x4)p(x_1, x_2, x_3, x_4, x_5) = p(x_1) p(x_2) p(x_3 \mid x_1) p(x_4 \mid x_1, x_3) p(x_5 \mid x_2, x_3, x_4)
Definition 2 (Bayesian Networks (Continued))

A Bayesian network is a directed acyclic graph (DAG) whose nodes represents random variables {x1,x2,,xK}\{\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K\} with an associated joint distribution that factorizes as,

p(x1,x2,,xK)=k=1Kp(xkxP(xk)),p(\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K) = \prod_{k = 1}^{K} p(\mathsf{x}_k \mid \mathsf{x}_{\mathcal{P}(\mathsf{x}_k)}),

where P(xk)\mathcal{P}(\mathsf{x}_k) denotes the set of parents of node xk\mathsf{x}_k in the graph.

Note

Note that xP(xk)\mathsf{x}_{\mathcal{P}(\mathsf{x}_k)} accounts for statistical dependence of xk\mathsf{x}_k with all the preceding variables {x1,,xk1}\{\mathsf{x}_1, \ldots, \mathsf{x}_{k-1}\} according to selected order. The corresponding Bayesian network encodes,

xk{x1,,xk1}P(xk)xP(xk)\mathsf{x}_k \perp \{\mathsf{x}_1, \ldots, \mathsf{x}_{k-1}\} \setminus \mathcal{P}(\mathsf{x}_k) \mid \mathsf{x}_{\mathcal{P}(\mathsf{x}_k)}
Example 2 (Bayesian Polynomial Regression)

Consider the joint distribution condtioned on input data and model parameters,

p(yD,wxD,α,σ2)=p(wα)i=1Np(yixi,w,σ2)p(y_{\mathcal{D}}, \mathbf{w} \mid x_{\mathcal{D}}, \alpha, \sigma^2) = p(\mathbf{w} \mid \alpha) \prod_{i=1}^{N} p(y_i \mid \mathbf{x}_i, \mathbf{w}, \sigma^2)
Bayesian Polynomial Regression Network
Bayesian Polynomial Regression Network

Causal Relationships

Intuition (Causal Relationships)

Bayesian networks are especially useful for modeling causal relationships between variables.

If we can identify causal relationships among random variables, this must mean there is a natural order on variables, i.e., random variables that appear later caused by a subset of preceding variables.

Causing random variables for random variable xk\mathsf{x}_k are included in P(xk)\mathcal{P}(\mathsf{x}_k). Which means conditioning on xP(xk)\mathsf{x}_{\mathcal{P}(\mathsf{x}_k)}, xk\mathsf{x}_k is independent of all other preceding variables.

Intuition (Ancestral Sampling)

However, we usually have a problem when dealing with causal relationships, i.e., obtaining marginals is not a trivial task.

But we can approximate exact distribution by an empirical one built from samples and perfect task for Bayesian networks.

Algorithm (Ancestral Sampling)

Assume,

p(x1,x2,,xK)=k=1Kp(xkxP(xk)),p(\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K) = \prod_{k = 1}^{K} p(\mathsf{x}_k \mid \mathsf{x}_{\mathcal{P}(\mathsf{x}_k)}),

i.e., ordered variables {x1,x2,,xK}\{\mathsf{x}_1, \mathsf{x}_2, \ldots, \mathsf{x}_K\}, with no arrow from any node to any lower numbered node.

  1. Draw sample for x1\mathsf{x}_1 from p(x1)p(\mathsf{x}_1).

  2. Draw sample for x2\mathsf{x}_2 from p(x2x1)p(\mathsf{x}_2 \mid \mathsf{x}_1).

  3. \ldots

  4. Draw sample for xK\mathsf{x}_K from p(xKxP(xK))p(\mathsf{x}_K \mid \mathsf{x}_{\mathcal{P}(\mathsf{x}_K)}).

Thus, we have obtained a sample from the joint distribution.

To sample from a marginal distribution we,

  • Take sampled values for required nodes and ignore those remaining ones.

  • p(x2,x4)p(\mathsf{x}_2, \mathsf{x}_4): sample from p(x1,,xK)p(\mathsf{x}_1, \ldots, \mathsf{x}_K), retain x^2\hat{\mathsf{x}}_2 and x^4\hat{\mathsf{x}}_4 and discard {x^j2,4}\{\hat{\mathsf{x}}_{j \neq 2,4}\}.

Definition 3 (Conditional Independence)

We know from classical probability theory that two random variables aa and bb are conditionally independent given a third random variable cc if,

p(a,bc)=p(ac)p(bc)p(a, b \mid c) = p(a \mid c) p(b \mid c)

When dealing with graphical models, we denote conditional independence as,

abca \perp b \mid c

This can also be written as,

p(ab,c)=p(a,b,c)p(b,c)=p(a,bc)p(bc)=p(ac)p(bc)p(bc)=p(ac)p(a \mid b, c) = \frac{p(a, b, c)}{p(b, c)} = \frac{p(a, b \mid c)}{p(b \mid c)} = \frac{p(a \mid c) p(b \mid c)}{p(b \mid c)} = p(a \mid c)
The three basic structures for conditional independence
The three basic structures for conditional independence
Intuition (Types of Connections)

Observe Figure 3, in the case of a tail-to-tail connection,

p(a,bc)=p(a,b,c)p(c)=p(ac)p(bc)p(c)p(c)=p(ac)p(bc)    abcp(a, b \mid c) = \frac{p(a, b, c)}{p(c)} = \frac{p(a \mid c) p(b \mid c) p(c)}{p(c)} = p(a \mid c) p(b \mid c) \implies a \perp b \mid c

i.e., aa and bb are independent if node in between is observed.

In the case of a head-to-tail connection,

p(a,bc)=p(a,b,c)p(c)=p(a)p(ca)p(bc)p(c)=p(ac)p(bc)    abcp(a, b \mid c) = \frac{p(a, b, c)}{p(c)} = \frac{p(a) p(c \mid a) p(b \mid c)}{p(c)} = p(a \mid c) p(b \mid c) \implies a \perp b \mid c

i.e., aa and bb are independent if node in between is observed.

In the case of a head-to-head connection,

p(a,b)=p(a,b,c) dc=p(ca,b)p(a)p(b) dc=p(a)p(b)    abp(a, b) = \int p(a, b, c) \ dc = \int p(c \mid a, b) p(a) p(b) \ dc = p(a) p(b) \implies a \perp b \mid \emptyset

i.e., aa and bb are independent if node in between and any of its descendants are not observed.

dd-Separation

Are  and  conditionally independent given ?
Are and conditionally independent given ?
Intuition (d-Separation)

This leads to asking a more general question. Are aa and bb conditionally independent given cc? (see Figure 4)

Or, in more general, isa given subset of variables A\mathcal{A} independent of another set B\mathcal{B} conditioned on a third subset C\mathcal{C}? (xAxBxC\mathsf{x}_{\mathcal{A}} \perp \mathsf{x}_{\mathcal{B}} \mid \mathsf{x}_{\mathcal{C}}) Thus, the goal is to determine independencies directly from the directed acyclic graph.

We can define the concept of dd-separation as. If all paths from any node in A\mathcal{A} to any node in B\mathcal{B} given the nodes in C\mathcal{C} are blocked, then ABC\mathcal{A} \perp \mathcal{B} \mid \mathcal{C}.

Or more formally as.

Let GG be a directed graph and A\mathcal{A}, B\mathcal{B}, and C\mathcal{C} disjoint sets of nodes. Then, if all paths from any node in A\mathcal{A} to any node in B\mathcal{B} given the nodes in C\mathcal{C} are blocked, A\mathcal{A} and B\mathcal{B} are said to be dd-separated by C\mathcal{C} and ABC\mathcal{A} \perp \mathcal{B} \mid \mathcal{C}.

A path between A\mathcal{A} and B\mathcal{B} is blocked if the path includes either,

  • A head-to-tail or tail-to-tail node which is in C\mathcal{C}, or,

  • A head-to-head node, and neither the node nor any of its descendants in C\mathcal{C}.

So, to answer our question to Figure 4.

Path from aa to bb are not blocked by ff, since a tail-to-tail node and ff is unobserved.

Path not blocked by ee, as a head-to-head node with an observed descendant.

Thus, abfa \perp b \mid f does not hold from the DAG.

Are  and  conditionally independent given ?
Are and conditionally independent given ?

Are aa and bb conditionally independent given ff?

Path from aa to bb are blocked by ff, since a tail-to-tail node and ff is observed. Path blocked by ee, as a head-to-head node and neither the node nor any of its descendants are observed.

Hence, abfa \perp b \mid f holds from the DAG.

Note (Markov Blanket)

In a directed graphical model, a node is conditionally independent of all other nodes given its parents, children and co-parnets.

The Markov blanket of node xi\mathsf{x}_i is the minimal set of nodes that isolates xi\mathsf{x}_i from the rest of the graph.

Note (Structured Learning)

What if the Bayesian network is not known? (i.e., we do not know the structure of the graph)

Bayesian networks can be learned from data without a pre-specified structure.

  • Different algorithms can be employed to learn network structure by analyzing the data and inferring most likely graph structure that best fits observed dependencies.

  • Once structure and parameters are learned, the Bayesian network can be used for prediction.