Bayesian Inference


Bayesian Inference

Anna
Today we're exploring Bayesian inference: the process of reaching a conclusion about how likely an event is, or what value an observable might have, using Bayes' theorem.

Michael
The central idea is simple. We begin with a prior belief about an event, incorporate observed data through the likelihood, and obtain an updated belief called the posterior probability.

Anna
So, in shorthand, the posterior is proportional to the likelihood multiplied by the prior. The likelihood tells us how compatible the data are with a possible explanation, while the prior represents what we believed before seeing those data.

Michael
A tennis match gives us an everyday example. When an opponent hits the ball, we predict where it will be so that we can move and return it.

Anna
That prediction initially depends on a prior. We might take into account the time of day, the weather, the lighting, how well we know the opponent, and the opponent's usual tactics.

Michael
Then sensory information arrives as the ball moves toward us. We combine that new evidence with the prior estimate. In the illustration, the prior is represented by a green ellipsoid and the likelihood by a red ellipsoid.

Anna
Their Bayesian combination produces a posterior estimate, shown as an ellipsoid with thick dark lines. This posterior is not the end of the process, because it becomes the prior for the next moment.

Michael
Exactly. At the next time point, the previous posterior is carried forward as the new prior and combined with fresh sensory data, or a new likelihood. This repeated process is called Bayesian belief updating.

Anna
Some theories of brain function, including predictive coding and the Bayesian brain theory, suggest that Bayesian inference may also be involved in how neurons fire and how we perceive the world.

Michael
In that setting, predictions and likelihoods are combined to calculate errors and minimize them. The aim is to form efficient models of the world that predict sensory input well and produce stable neural representations through iterative updating.

Anna
Before going further, let's distinguish correlation from the kind of probabilistic reasoning Bayesian inference supports. A famous example asked, 'Does chocolate make you clever?'

Michael
The graph compared chocolate consumption per person in different countries with the number of Nobel laureates per ten million inhabitants. It showed a clear correlation: countries consuming more chocolate also appeared to have more Nobel laureates.

Anna
But correlation alone does not establish that eating more chocolate increases a country's chances of producing Nobel Prize winners. That question concerns a possible cause and a possible conclusion, so it requires hypotheses, estimates, and probabilities rather than deductive logic.

Michael
This is where Bayesian inference is useful. It lets us quantify uncertainty about a conclusion based on particular premises, such as observed data or assumptions.

Anna
Let's step back and define probability. In the frequent-trial sense, probability is the ratio of the number of times a particular event is observed to the total number of trials covering all possible outcomes.

Michael
For a fair die, the probability of getting one particular face is one out of six. For a coin, the probability of heads or tails is fifty percent.

Anna
More rigorously, the frequent-trial definition considers the limit as the number of trials approaches infinity. Of course, we cannot actually repeat an experiment infinitely many times, and sometimes we have only one trial, such as asking whether it will rain or snow tomorrow.

Michael
That motivates a distinction between frequentist and Bayesian probabilities. Frequentist probability quantifies the variability or frequency of an outcome across an imagined infinite ensemble of repeated trials.

Anna
Bayesian probability quantifies uncertainty. It asks how certain we are that a conclusion or hypothesis is true given some premises or assumptions. The distinction between premises and conclusions is crucial.

Michael
Both types of probability are defined over random variables. A random variable is a function that assigns a real number to an outcome in a sample space associated with a random process.

Anna
For example, flipping a coin is a random process. Its sample space contains heads and tails, and the outcome on each flip is represented by a random variable. The outcomes are mapped to real-number probabilities, such as one-half for heads and one-half for tails.

Michael
Random variables can be discrete or continuous. In brain applications, connectivity between areas can be treated as a random variable. For instance, we might define a variable representing how strongly a frontal area communicates with a parietal area.

Anna
Suppose we record brain data, denoted by Y, and want to infer brain connectivity, denoted by theta. This is an inverse problem: starting with observed data and trying to recover the underlying connectivity that generated it.

Michael
A Bayesian probability such as the probability that theta has a particular value given Y expresses exactly that question. The vertical bar means 'given,' so the data are the premise and the connectivity value is the hypothesis.

Anna
In an EEG example, the recorded signals Y come from activity generated by neural sources. Several connected brain areas may produce the activity measured by sensors on the scalp, and theta describes how those sources are connected.

Michael
In causal language, the connectivity is a possible cause and the EEG recording is an effect. We observe the effect and ask which cause, or which connectivity configuration, could have produced it.

Anna
But inverse problems like this are often ill-posed. Multiple causes can produce the same effect, so a particular pattern of brain data may be compatible with several different neural configurations.

Michael
The random variable can also be multidimensional. Instead of one connection, we might estimate a forward connection theta one and a backward connection theta two between two areas, with separate means and uncertainties. Then probability is defined over the vector containing both parameters.

Anna
Now let's build Bayes' theorem from three basic probability rules. The first is normalization: when we add the probabilities of all mutually possible outcomes, the total is one, or one hundred percent.

Michael
For tomorrow's weather, the possible outcomes might include rain, snow, sunshine, or cloudy conditions. The probabilities of all those possible outcomes must sum to one.

Anna
The second rule is the sum rule, also called marginalization. If A represents what clothes I wear and B represents whether I go to work, then the probability of B is found by summing the joint probabilities of B with every possible value of A.

Michael
In other words, the probability of going to work includes going to work wearing jeans, going to work wearing different clothes, and every other clothing outcome. Summing over A removes A from the description and leaves the probability of B.

Anna
The third rule is the product rule, or conditioning rule. The joint probability of A and B equals the probability of A given B multiplied by the probability of B.

Michael
It can also be written the other way around: the probability of B given A multiplied by the probability of A. So the probability of wearing jeans and going to work can be expressed from either conditional direction.

Anna
Rearranging that product rule gives Bayes' theorem. The probability of A given B equals the probability of B given A multiplied by the probability of A, divided by the probability of B.

Michael
Here, P of A is the prior, P of B given A is the likelihood, and P of A given B is the posterior. The denominator, P of B, normalizes the result so that the possible posterior probabilities form a valid probability distribution.

Anna
Using the sum rule, that denominator can be written as a sum over all possible values of A of the joint probability P of A and B. Using the product rule again, it becomes the sum over A of P of A multiplied by P of B given A.

Michael
That denominator is sometimes described as the probability of the data, or the evidence. It accounts for every possible value of A that could have generated the observed B.

Anna
Returning to chocolate and Nobel prizes, we first have to decide what we regard as the cause and what we regard as the effect. If chocolate consumption is the cause and winning a Nobel prize is the effect, then the likelihood could describe the probability of that chocolate consumption given a Nobel prize, while the prior describes the relevant prior probability of Nobel achievement.

Michael
The important point is that Bayesian reasoning requires clearly identifying the variables and their direction in the question. Once the cause, effect, prior, likelihood, and observed data are specified, Bayes' rule provides the framework for updating the probability.

Anna
The presentation then applies this idea to a simple Gaussian model. Imagine that beta represents a true temperature, while a thermometer records an approximation of it.

Michael
The measurement can be written as the true value beta plus a random error, often denoted by e. The prior belief about beta is Gaussian, with a prior mean and variance, and the likelihood of observing a measurement y given beta is also Gaussian, with mean beta and variance determined by the observation noise.

Anna
When both prior and likelihood are Gaussian, the posterior is Gaussian as well. Its mean is a precision-weighted combination of the prior mean and the observed data mean.

Michael
Precision is the inverse of variance. So an estimate with smaller variance has greater precision and receives greater weight. The posterior precision is the sum of the prior precision and the observation-noise precision.

Anna
The result matches the tennis example mathematically: a prior Gaussian is updated by a likelihood Gaussian to produce a posterior Gaussian. The posterior incorporates both the previous belief and the new measurement, weighted according to their uncertainties.

Michael
The next example uses a general linear model, or GLM. The data are represented by Y, and the model predicts them as the design matrix X multiplied by a parameter vector beta, plus a random noise term epsilon.

Anna
In the illustrated two-dimensional case, each observation has an X coordinate and a Y coordinate. The linear part X times beta defines a line, while epsilon represents the distance or deviation of each data point from that line.

Michael
The noise is assumed to be normally distributed with mean zero and variance sigma squared. The parameter vector contains beta one and beta two, and the design matrix includes a column of ones for an overall mean and another column containing a covariate, such as a demographic variable.

Anna
For the Bayesian model, the prior over the beta vector is a normal distribution with mean zero. Its covariance is diagonal, with variance one for each parameter and no interaction between the parameters.

Michael
The likelihood is also normal. Its mean is the model prediction X times beta, and its variance reflects sigma squared for the data points. In plain language, the model predicts the data through the linear term, while the likelihood represents uncertainty around those predictions.

Anna
For this linear Gaussian case, pen-and-paper calculations are possible. But for nonlinear models, such as dynamic causal models involving biophysical neural networks, the denominator of Bayes' theorem includes an integral that is difficult or impossible to calculate explicitly.

Michael
That denominator is the model evidence. It requires marginalizing the parameters out of the joint density. When this calculation is intractable, we use approximate Bayesian inference, including variational inference.

Anna
Variational methods introduce a tractable density, often written q of beta, to approximate the true posterior. The computation also uses the logarithm of the model evidence, which is mathematically more convenient.

Michael
A lower bound on the log model evidence is called free energy. Free energy is useful for model comparison, including comparing alternative neural architectures or different neurobiological mechanisms that might have generated brain data.

Anna
SPM implements approximate Bayesian inference for these kinds of problems. One routine highlighted in the presentation is SPM NLSI with the GN variant, where NLSI refers to nonlinear system identification.

Michael
The routine needs a model, data, priors, and prior covariance information. In the GLM example, the model is based on the design matrix multiplied by the parameter vector, with a random noise term added.

Anna
The simulated example uses twenty observations and two parameters. The design matrix has a column of ones and a second column of randomly generated covariates, while the parameter vector begins with a prior guess.

Michael
The algorithm then updates those beliefs iteratively. The output includes approximate posterior values for the model parameters and the free energy, which approximates the model evidence.

Anna
The iterative procedure is described as a form of variational Bayes, specifically using an expectation-maximization algorithm. Each step reports the current free energy and its change, and the process ends when the updates become sufficiently small and the algorithm converges.

Michael
In the example, the approximate posterior parameter values are minus 0.2595 and 0.6128. These are not simply the original prior guesses; they result from combining the priors with the likelihood supplied by the data.

Anna
SPM also displays the results graphically. One plot compares the data with the model prediction, and the two lines converge after the iterative updates.

Michael
A second plot shows the posterior values for the two beta parameters. The bars indicate how the posterior estimates differ from their prior values.

Anna
So the overall story is consistent from tennis to brain connectivity to software. Start with a prior, combine it with sensory or experimental evidence through the likelihood, and obtain a posterior.

Michael
When the equations can be solved directly, Gaussian examples show exactly how that updating works. When models become nonlinear and the evidence integral cannot be computed explicitly, variational Bayesian algorithms provide an approximation, with free energy serving as an approximation to model evidence and supporting model comparison.

Ask anything
We've read this whole study set, so questions about it get the best answers.