Clare Lyle

Posted on November 11, 2018 by Clare

Graphical Models

Graphical models are a useful tool in machine learning, as they give us a natural means of expressing complex probability distributions in the language of graph theory. For example, after deciding that graduate student life is no longer for me, I may decide to start up a coffee business in Oxford. Now, in order to be able to tailor my supply purchases to the town’s demand, I find myself in need of a good model of the distribution of coffee preferences across the citizens of Oxford.

I start off simply serving people coffee and taking notes on who comes in to my coffee shop. I then observe that the population can be broken down into two groups: university students, and normal people. I notice that university students on average drink 3 cups of coffee per day, whereas normal people drink 1. I also notice that that people who buy more coffee provide a tip on a smaller fraction of their purchases. However, when I take a closer look I realize that this is actually caused by the fact that students are much less likely than normal people to tip. In fact, students who buy more coffee don’t tip any more or less frequently than students who buy less, and the same goes for normal people. Thus I observe that tipping frequency and coffee consumption are conditionally independent given that I know whether the person is a student.

I’ll provide the following definitions now for clarity:

Conditional independence: We say that a is conditionally independent of b given c if p(a ∣ b, c) = p(a ∣ c). The following shorthand notation is common:
$$\newcommand{\bigCI}{\perp\mkern-10mu\perp} a \bigCI b \mid c $$

Graphical Model: A graphical model is a graph G(V, E) representing a probability distribution on a set of random variables for which each v ∈ V represents a subset of the random variables and the set E captures the conditional independence structure of the distribution. The edges may be directed or undirected, corresponding to directed and undirected graphical models.

For example, a graphical model describing coffee consumption and tipping frequency would look something like this:

Note that there’s no arrow between tipping and coffee, because they’re both conditionally independent of each other given that we know whether we’re dealing with a student. This particular graphical model is an example of a Bayes network.

Bayesian network: A Bayesian network is a special class of graphical model for which the edges form a DAG (directed acyclic graph).

Inference in graphical models

After a few weeks in the coffee business, I observe that the number of customers I receive on any given day seems to depend only on the number of customers I received the day before. I am able to deduce that the citizens of Oxford engage in a bizarre process of coffee shop selection by which every night, each person chooses one other townsperson at random, and then goes to the coffee shop that person had visited during the day. I need to order coffee beans three days in advance, so on Monday I would like to know what the distribution of coffee purchasers will be on Thursday. To do this I will exploit the structure of markov chains to perform inference on the graphical model.

Now, I want to figure out the marginal distribution p(x3), where x3 represents the amount of coffee that will be bought that day. On day zero, I had 500 customers. I could sum over all of the possible values for x1, x2, x3 and compute p(x1|x0)p(x2|x1, x0)p(x3|x2, x1, x0) to find the distribution over values for x3, but if we suppose there are 100000 potential customers and each xi can take on any integral value between 0 and 100,000, that would involve computing 100, 0003 different probabilities.

Fortunately, having studied probability before entering the coffee business, I know that the conditional probability of xi given xi − 1 follows a binomial distribution. I also know that since p(x3|x2, x1, x0) = p(x3|x2), I don’t really need to compute the probability of every possible combination of x3, x2, x1 in order to compute the marginal p(x3). Instead I can use a dynamic programming approach. That is, I compute p(x1|x0) (100,000 numbers). Then I compute p(x2|x1) (I perform (100, 000)2 computations but only need to save the probabilities for x2). Then for x3 I need only used my saved values for x2 and compute p(x3|x2) for each value of x2. This means that I save on about 9.99 × 1014 computations that I didn’t have to perform because I took advantage of the graph structure of my data.

Inference becomes more complicated when the Bayesian network doesn’t form a chain, but the principle is still the same. In fact, even when the network is no longer acyclic, we can still perform “loopy belief propagation”, in which we run the algorithm that works for the acyclic case and hope it eventually converges (spoiler alert: it doesn’t always do so). In the future, I’ll try to add to this post and summarize some work in approximate inference in graphical models, and also highlight how they tie in to the deep learning world.