1. Home
  2. Explore
  3. Statistics
  4. Bayesian Inference

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bayesian Inference

Bayesian Inference: Concepts, Mathematics, and Applications

1. Inference and Bayesian Inference

Inference is the process of drawing a conclusion about:

  • The likelihood that an event will occur.

  • The value an observable may have.

  • The hidden causes that could have generated observed data.

Inference is often necessary because the quantity of interest cannot be observed directly. Instead, conclusions must be based on evidence, assumptions, and uncertainty.

Bayesian inference performs this process using Bayes’ theorem. It combines an existing belief with newly observed data to produce an updated belief.

The central relationship is:

P(A∣B)=P(B∣A)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)P(A)​

where:

  • P(A)P(A)P(A) is the prior probability: the initial belief about hypothesis or event AAA.

  • P(B∣A)P(B \mid A)P(B∣A) is the likelihood: the probability of observing data BBB if AAA is true.

  • P(B)P(B)P(B) is the model evidence or marginal probability of the data.

  • P(A∣B)P(A \mid B)P(A∣B) is the posterior probability: the updated belief about AAA after observing BBB.

Bayesian inference can therefore be summarized as:

Posterior∝Likelihood×Prior\text{Posterior} \propto \text{Likelihood} \times \text{Prior}Posterior∝Likelihood×Prior

The posterior combines prior knowledge with sensory or experimental evidence.

Bayesian inference updates beliefs using data. The posterior belief from one stage can become the prior belief for a later stage.


2. Bayesian Belief Updating in Tennis

Playing tennis provides an intuitive example of Bayesian inference.

When a tennis opponent hits the ball, the player must predict where the ball will arrive and move accordingly. This prediction changes continuously as more information becomes available.

2.1 Formation of the prior

Before the ball is hit, the player has an initial prediction about its likely trajectory. This prior belief may be influenced by:

  • The opponent’s previous behavior and playing style.

  • The opponent’s tactics and body position.

  • The time of day.

  • Weather conditions.

  • Wind.

  • Lighting conditions.

  • The player’s prior experience with the opponent.

  • The general situation in the game.

This prior is a prediction formed before the most recent sensory evidence is processed.

2.2 Sensory evidence and likelihood

As the ball moves toward the player, visual and other sensory information becomes available. This information provides a likelihood: evidence about where the ball is likely to be based on its current position, speed, and direction.

The likelihood changes as the ball approaches because each moment supplies new data.

2.3 Combining prior and likelihood

The player combines:

  • The prior prediction, representing long-term knowledge and expectations.

  • The likelihood, representing current sensory evidence.

The result is a posterior estimate of the ball’s location.

The source describes these beliefs using ellipsoids:

  • A green ellipsoid represents the prior.

  • A red ellipsoid represents the likelihood.

  • A dark-outlined ellipsoid represents the posterior.

The posterior is the player’s best current estimate after integrating prior expectations with sensory data.

2.4 Iterative Bayesian updating

Bayesian inference is not performed only once. It occurs repeatedly over time.

For example:

  1. At an early time point, the player combines an initial prior with early sensory evidence.

  2. This produces a posterior estimate.

  3. At the next time point, that posterior becomes the new prior.

  4. The player combines the new prior with newly arriving sensory evidence.

  5. A new posterior is generated.

  6. The process continues until the ball is received.

Symbolically:

Posterior at time t=Prior at time t×Likelihood from data at time t\text{Posterior at time } t = \text{Prior at time } t \times \text{Likelihood from data at time } tPosterior at time t=Prior at time t×Likelihood from data at time t

Then:

Prior at time t+1=Posterior at time t\text{Prior at time } t+1 = \text{Posterior at time } tPrior at time t+1=Posterior at time t

This process is called Bayesian belief updating.


3. Bayesian Inference in Perception and Neural Processing

Some theories of brain function propose that neural systems use Bayesian principles.

Two theories mentioned are:

  • Predictive coding

  • Bayesian brain theory

According to these approaches, the brain continuously generates predictions about sensory input and compares those predictions with incoming data.

3.1 Combining predictions and sensory evidence

The brain may combine:

  • Prior predictions about the world.

  • Likelihood information from current sensory input.

The difference between predicted and observed sensory input produces a prediction error. Neural systems may then update their internal models to reduce this error.

3.2 Efficient models of the world

The proposed goal is to construct efficient internal models that:

  • Predict sensory input accurately.

  • Explain observations using stable neural representations.

  • Minimize prediction errors.

  • Update iteratively as new evidence arrives.

This resembles the tennis example: a prior prediction is repeatedly combined with new evidence to generate increasingly stable estimates.

The presentation does not develop predictive coding or Bayesian brain theory in detail, but uses them to illustrate the broader possibility that Bayesian inference may play a role in perception and neural activity.


4. Correlation, Hypotheses, and Uncertainty

A correlation can reveal a relationship between variables, but it does not by itself establish a causal relationship.

4.1 Chocolate consumption and Nobel laureates

One example compares:

  • Annual per-capita chocolate consumption in different countries.

  • The number of Nobel laureates per 101010 million inhabitants.

The graph shows a positive correlation: countries consuming more chocolate tend to have more Nobel laureates.

This leads to a possible hypothesis:

Greater chocolate consumption increases a country’s chances of producing Nobel Prize winners.

However, the correlation alone cannot establish that eating chocolate causes Nobel Prizes.

4.2 Presumptions and conclusions

The example distinguishes between:

  • A presumption or possible cause: chocolate consumption.

  • A hypothesis or conclusion: obtaining a Nobel Prize.

The question concerns a probability, such as the probability of obtaining a Nobel Prize given a certain level of chocolate consumption.

This type of question cannot be answered through deductive logic alone. It requires:

  • Hypotheses.

  • Estimates.

  • Probabilities.

  • Evidence.

  • Assumptions about possible causal relationships.

Bayesian inference is designed for reasoning under this type of uncertainty.

4.3 Correlation does not prove causation

A correlation may arise because:

  • Chocolate consumption directly affects intellectual performance.

  • Wealthier countries both consume more chocolate and support more scientific research.

  • Educational systems differ between countries.

  • Other social, economic, nutritional, or cultural factors affect both variables.

  • The direction of causation is different from the proposed explanation.

Bayesian inference can quantify how plausible a hypothesis is given the evidence, but the quality of the conclusion still depends on the model and the assumptions used.


5. Mathematical Probability

Probability quantifies uncertainty or variability concerning possible outcomes.

For a particular event, a basic frequentist definition is:

P(event)=number of times the event occurstotal number of trialsP(\text{event}) = \frac{\text{number of times the event occurs}} {\text{total number of trials}}P(event)=total number of trialsnumber of times the event occurs​

5.1 Basic examples

For a fair six-sided die:

P(one particular side)=16P(\text{one particular side}) = \frac{1}{6}P(one particular side)=61​

For a fair coin:

P(heads)=12P(\text{heads}) = \frac{1}{2}P(heads)=21​

and:

P(tails)=12P(\text{tails}) = \frac{1}{2}P(tails)=21​

Probabilities may also be expressed as percentages. For example, 12\frac{1}{2}21​ is equivalent to 50%50\%50%.

5.2 Infinite-trial definition

A more rigorous frequentist definition considers the limiting relative frequency as the number of trials approaches infinity:

P(A)=lim⁡N→∞number of occurrences of ANP(A) = \lim_{N \to \infty} \frac{\text{number of occurrences of } A}{N}P(A)=limN→∞​Nnumber of occurrences of A​

This definition assumes that the experiment can be repeated indefinitely. In practice, however:

  • Experiments cannot literally be repeated infinitely many times.

  • Some events can occur only once.

  • Some questions concern future events that have not yet happened.

For example, the probability that it will rain tomorrow cannot be directly estimated by repeating the exact same tomorrow infinitely many times.


6. Frequentist and Bayesian Probability

Two important interpretations of probability are frequentist probability and Bayesian probability.

6.1 Frequentist probability

Frequentist probability is based on repeated trials or an imagined infinite ensemble of trials.

It quantifies the variability or frequency of outcomes. For example, if a fair coin is flipped many times, the proportion of heads should approach 12\frac{1}{2}21​.

Key features include:

  • Probability is associated with repeatable random processes.

  • Long-run frequencies are central.

  • The probability describes variation across hypothetical or actual repeated trials.

  • Parameters are often treated as fixed but unknown quantities.

6.2 Bayesian probability

Bayesian probability quantifies uncertainty about a proposition, hypothesis, or conclusion based on premises or evidence.

It is especially useful when:

  • There is only one relevant observation.

  • The event cannot be repeated under identical conditions.

  • Prior knowledge is important.

  • The goal is to compare possible explanations.

  • The cause is hidden and must be inferred from effects.

Bayesian probability distinguishes between:

  • Premises: what is assumed or observed.

  • Conclusions: what is inferred from those premises.

For example:

  • Premise: observed brain data YYY.

  • Conclusion: a particular brain connectivity value θ\thetaθ.

The relevant probability is:

P(θ∣Y)P(\theta \mid Y)P(θ∣Y)

This means the probability of the connectivity value θ\thetaθ given the observed data YYY.

Frequentist probability emphasizes long-run frequency; Bayesian probability emphasizes uncertainty about hypotheses given evidence.


7. Random Variables and Sample Spaces

Probabilities are defined over random variables.

A random variable is a function that assigns a numerical value to each possible outcome of a random process.

7.1 Random processes and sample spaces

A random process produces uncertain outcomes. For example:

  • Flipping a coin.

  • Rolling a die.

  • Measuring temperature.

  • Recording brain activity.

The sample space, usually denoted by Ω\OmegaΩ, is the set of all possible outcomes.

For one coin flip:

Ω={heads,tails}\Omega = \{\text{heads}, \text{tails}\}Ω={heads,tails}

A random variable maps these outcomes to numerical values or probabilities. In a fair coin example:

P(heads)=12P(\text{heads}) = \frac{1}{2}P(heads)=21​

and:

P(tails)=12P(\text{tails}) = \frac{1}{2}P(tails)=21​

7.2 Discrete and continuous random variables

Random variables may be:

  • Discrete: take separate, countable values, such as the result of a die roll.

  • Continuous: take values across a continuous range, such as temperature, time, or brain connectivity strength.

A continuous random variable is typically described using a probability density rather than probabilities assigned to individual points.


8. Brain Connectivity as a Random Variable

In applications such as dynamic causal modeling, brain connectivity is treated as a random variable.

Let:

  • YYY represent observed brain data.

  • θ\thetaθ represent parameters describing connectivity between neural sources.

A parameter θ\thetaθ may describe, for example:

  • The strength of a connection from a frontal region to a parietal region.

  • The strength of a connection from a subcortical region to a cortical region.

  • How one neural source influences another.

The relevant Bayesian quantity is:

P(θ∣Y)P(\theta \mid Y)P(θ∣Y)

This is the probability distribution over possible connectivity values given the observed brain data.

The source gives a normal distribution as an example:

P(θ∣Y)=N(θ;μ,σ2)P(\theta \mid Y) = \mathcal{N}(\theta; \mu, \sigma^2)P(θ∣Y)=N(θ;μ,σ2)

where:

  • μ\muμ is the mean connectivity estimate.

  • σ2\sigma^2σ2 is the variance.

  • The distribution expresses uncertainty about the estimated connectivity.

The random variable is θ\thetaθ, not the probability itself. The probability distribution is defined over possible values of θ\thetaθ.


9. Causes, Effects, and the Inverse Problem

In biological systems, observed data and hidden neural mechanisms can be interpreted as effects and causes.

9.1 Neural sources and recorded data

Electroencephalography records electrical activity at sensors placed around the scalp. The recorded signals are represented by YYY.

The observed activity is generated by hidden neural sources, such as interacting brain regions. These sources may be connected by directed influences.

The model therefore contains:

  • Neural sources: possible causes.

  • Connectivity parameters θ\thetaθ: relationships among the causes.

  • Recorded data YYY: observable effects.

The inference problem asks:

Given the observed data YYY, what connectivity configuration θ\thetaθ most plausibly generated it?

This is represented as:

P(θ∣Y)P(\theta \mid Y)P(θ∣Y)

9.2 Forward and inverse probabilities

The forward probability describes how data are generated from causes:

P(Y∣θ)P(Y \mid \theta)P(Y∣θ)

It answers:

If the connectivity is θ\thetaθ, how likely is the observed data YYY?

The inverse probability describes causes inferred from effects:

P(θ∣Y)P(\theta \mid Y)P(θ∣Y)

It answers:

Given the observed data YYY, how likely is the connectivity θ\thetaθ?

Bayes’ theorem connects these two directions.

9.3 The inverse problem is ill-posed

A central difficulty is that multiple causes may produce similar effects.

For example:

  • Different neural configurations may generate similar EEG patterns.

  • Different combinations of frontal, parietal, and subcortical activity may produce similar recordings.

  • Similar activity patterns may arise from different connectivity strengths.

Consequently, the inverse problem may not have a unique solution.

An ill-posed problem is one in which the available data do not determine a single, unique explanation. Bayesian inference addresses this by assigning probabilities to competing explanations rather than claiming certainty about one exact cause.


10. Multidimensional Random Variables

The connectivity example can involve several parameters simultaneously.

Suppose:

  • θ1\theta_1θ1​ represents a forward connection between two regions.

  • θ2\theta_2θ2​ represents a backward connection between the same regions.

The parameters may have means μ1\mu_1μ1​ and μ2\mu_2μ2​. Together, they form a multidimensional parameter vector:

θˉ=[θ1θ2]\bar{\theta} = \begin{bmatrix} \theta_1 \\ \theta_2 \end{bmatrix}θˉ=[θ1​θ2​​]

The probability distribution is then defined over the joint parameter space:

P(θˉ∣Y)P(\bar{\theta} \mid Y)P(θˉ∣Y)

This distribution describes uncertainty about both connections at the same time. It can represent:

  • The uncertainty in each parameter.

  • Relationships or dependencies between parameters.

  • Different combinations of connectivity values that are consistent with the data.

Multidimensional continuous random variables are essential for realistic models because biological systems contain many interacting parameters rather than a single unknown quantity.


11. Three Fundamental Rules of Probability

Bayes’ theorem can be derived from three basic probability rules:

  1. The normalization rule.

  2. The sum rule, or marginalization.

  3. The product rule, or conditioning rule.

These rules provide the mathematical foundation for Bayesian inference.

11.1 Normalization rule

The probabilities of all mutually exclusive and collectively exhaustive outcomes must sum to one:

∑AP(A)=1\sum_A P(A) = 1∑A​P(A)=1

For example, possible weather outcomes might include:

  • Rain.

  • Snow.

  • Sunshine.

  • Cloudiness.

If these outcomes cover all possibilities, then:

P(rain)+P(snow)+P(sun)+P(cloud)=1P(\text{rain}) + P(\text{snow}) + P(\text{sun}) + P(\text{cloud}) = 1P(rain)+P(snow)+P(sun)+P(cloud)=1

Normalization ensures that the probability distribution represents all possible outcomes.

11.2 Sum rule or marginalization

The probability of one variable can be obtained by summing over all possible values of another variable.

For variables AAA and BBB:

P(B)=∑AP(A,B)P(B) = \sum_A P(A,B)P(B)=∑A​P(A,B)

Here, P(A,B)P(A,B)P(A,B) is the joint probability that both AAA and BBB occur.

For continuous variables, summation is replaced by integration:

P(B)=∫P(A,B) dAP(B) = \int P(A,B)\,dAP(B)=∫P(A,B)dA

This process is called marginalization because the values of AAA are summed or integrated out, leaving the marginal distribution over BBB.

For example, if:

  • AAA is the clothing worn.

  • BBB is the event of going to work.

Then P(B)P(B)P(B) is obtained by summing the probabilities of going to work while wearing every possible type of clothing.

11.3 Product rule or conditioning

The joint probability can be written as a conditional probability multiplied by a marginal probability:

P(A,B)=P(A∣B)P(B)P(A,B) = P(A \mid B)P(B)P(A,B)=P(A∣B)P(B)

It can also be written in the reverse direction:

P(A,B)=P(B∣A)P(A)P(A,B) = P(B \mid A)P(A)P(A,B)=P(B∣A)P(A)

For example, the probability of wearing jeans and going to work can be expressed as:

P(jeans,work)=P(jeans∣work)P(work)P(\text{jeans},\text{work}) = P(\text{jeans}\mid\text{work})P(\text{work})P(jeans,work)=P(jeans∣work)P(work)

or:

P(jeans,work)=P(work∣jeans)P(jeans)P(\text{jeans},\text{work}) = P(\text{work}\mid\text{jeans})P(\text{jeans})P(jeans,work)=P(work∣jeans)P(jeans)

The product rule shows that the same joint probability can be decomposed in two different conditional directions.


12. Derivation and Interpretation of Bayes’ Theorem

Starting with the two versions of the product rule:

P(A,B)=P(A∣B)P(B)P(A,B) = P(A \mid B)P(B)P(A,B)=P(A∣B)P(B)

and:

P(A,B)=P(B∣A)P(A)P(A,B) = P(B \mid A)P(A)P(A,B)=P(B∣A)P(A)

Because both expressions equal the same joint probability, they can be equated:

P(A∣B)P(B)=P(B∣A)P(A)P(A \mid B)P(B) = P(B \mid A)P(A)P(A∣B)P(B)=P(B∣A)P(A)

Solving for P(A∣B)P(A \mid B)P(A∣B) gives Bayes’ theorem:

P(A∣B)=P(B∣A)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)P(A)​

The denominator can be expanded using marginalization:

P(B)=∑AP(A,B)P(B) = \sum_A P(A,B)P(B)=∑A​P(A,B)

Using the product rule:

P(B)=∑AP(B∣A)P(A)P(B) = \sum_A P(B \mid A)P(A)P(B)=∑A​P(B∣A)P(A)

Therefore, Bayes’ theorem can also be written as:

P(A∣B)=P(B∣A)P(A)∑AP(B∣A)P(A)P(A \mid B) = \frac{P(B \mid A)P(A)} {\sum_A P(B \mid A)P(A)}P(A∣B)=∑A​P(B∣A)P(A)P(B∣A)P(A)​

For continuous variables, the denominator becomes an integral:

P(A∣B)=P(B∣A)P(A)∫P(B∣A)P(A) dAP(A \mid B) = \frac{P(B \mid A)P(A)} {\int P(B \mid A)P(A)\,dA}P(A∣B)=∫P(B∣A)P(A)dAP(B∣A)P(A)​

12.1 Interpretation of the terms

In Bayesian belief updating:

  • P(A)P(A)P(A) is the prior.

  • P(B∣A)P(B \mid A)P(B∣A) is the likelihood.

  • P(A∣B)P(A \mid B)P(A∣B) is the posterior.

  • P(B)P(B)P(B) is the evidence or normalization term.

Thus:

Posterior=Likelihood×PriorEvidence\text{Posterior} = \frac{\text{Likelihood}\times\text{Prior}} {\text{Evidence}}Posterior=EvidenceLikelihood×Prior​

The denominator ensures that the posterior distribution is properly normalized.

12.2 Applying Bayes’ theorem to chocolate and Nobel Prizes

The variables must first be assigned a clear direction.

For example:

  • AAA: a country has a particular level of chocolate consumption.

  • BBB: the country produces a Nobel Prize winner.

Possible Bayesian quantities include:

P(B∣A)P(B \mid A)P(B∣A)

the probability of producing a Nobel laureate given chocolate consumption, and:

P(A∣B)P(A \mid B)P(A∣B)

the probability of observing that level of chocolate consumption given that a country produces a Nobel laureate.

These probabilities are not interchangeable. Bayes’ theorem provides the mathematical relationship between them.


13. Bayesian Updating with Gaussian Distributions

A useful special case occurs when the prior and likelihood are Gaussian distributions.

Suppose a measurement model is:

y=β+ey = \beta + ey=β+e

where:

  • yyy is the observed measurement.

  • β\betaβ is the unknown true value.

  • eee is random observation noise.

For example, β\betaβ may represent the true temperature, while yyy is the imperfect thermometer reading.

13.1 Gaussian prior

Assume that the prior belief about β\betaβ is Gaussian:

P(β)=N(β;μp,1αp)P(\beta) = \mathcal{N} \left( \beta;\mu_p,\frac{1}{\alpha_p} \right)P(β)=N(β;μp​,αp​1​)

where:

  • μp\mu_pμp​ is the prior mean.

  • 1αp\frac{1}{\alpha_p}αp​1​ is the prior variance.

  • αp\alpha_pαp​ is the prior precision.

Precision is the inverse of variance:

precision=1variance\text{precision} = \frac{1}{\text{variance}}precision=variance1​

Thus, a larger precision represents lower uncertainty.

13.2 Gaussian likelihood

Assume that the measurement noise is Gaussian. The likelihood is:

P(y∣β)=N(y;β,1αe)P(y \mid \beta) = \mathcal{N} \left( y;\beta,\frac{1}{\alpha_e} \right)P(y∣β)=N(y;β,αe​1​)

where:

  • The mean of the measurement distribution is the true value β\betaβ.

  • 1αe\frac{1}{\alpha_e}αe​1​ is the observation-noise variance.

  • αe\alpha_eαe​ is the observation-noise precision.

The likelihood describes how probable the observed measurement yyy is for each possible value of β\betaβ.

13.3 Gaussian posterior

Combining the Gaussian prior and Gaussian likelihood produces another Gaussian posterior:

P(β∣y)=N(β;μ,1α)P(\beta \mid y) = \mathcal{N} \left( \beta;\mu,\frac{1}{\alpha} \right)P(β∣y)=N(β;μ,α1​)

The posterior precision is:

α=αp+αe\alpha = \alpha_p + \alpha_eα=αp​+αe​

The posterior mean is a precision-weighted combination of the prior mean and the observation:

μ=1α(αey+αpμp)\mu = \frac{1}{\alpha} \left( \alpha_e y + \alpha_p\mu_p \right)μ=α1​(αe​y+αp​μp​)

Equivalently:

μ=αey+αpμpαe+αp\mu = \frac{\alpha_e y+\alpha_p\mu_p} {\alpha_e+\alpha_p}μ=αe​+αp​αe​y+αp​μp​​

13.4 Interpretation

The posterior mean is pulled toward whichever source of information has greater precision:

  • If the prior is more precise, the posterior remains closer to μp\mu_pμp​.

  • If the measurement is more precise, the posterior moves closer to yyy.

  • If both have equal precision, the posterior mean lies between them.

  • The posterior is more precise than either source alone because it combines both sources of information.

This is the mathematical form of Bayesian belief updating.


14. The General Linear Model

The Gaussian example extends naturally to the general linear model.

The general linear model is:

Y=Xβˉ+ϵY = X\bar{\beta}+\epsilonY=Xβˉ​+ϵ

where:

  • YYY is the vector or matrix of observed data.

  • XXX is the design matrix.

  • βˉ\bar{\beta}βˉ​ is the vector of model parameters.

  • ϵ\epsilonϵ is random noise.

For a two-dimensional example, each observation contains an XXX coordinate and a YYY coordinate. The model predicts the data using a line:

XβˉX\bar{\beta}Xβˉ​

The noise term represents the deviation of each observed point from the model prediction.

14.1 Noise distribution

The noise is assumed to follow a Gaussian distribution:

ϵ∼N(0,σ2)\epsilon \sim \mathcal{N}(0,\sigma^2)ϵ∼N(0,σ2)

where:

  • The mean is zero.

  • σ2\sigma^2σ2 is the noise variance.

The observed data are therefore modeled as:

Y∼N(Xβˉ,Σ)Y \sim \mathcal{N}(X\bar{\beta},\Sigma)Y∼N(Xβˉ​,Σ)

where Σ\SigmaΣ is the covariance matrix of the observation noise.

If all observations have independent noise with equal variance, Σ\SigmaΣ has σ2\sigma^2σ2 along its diagonal.

14.2 Design matrix

The design matrix may contain:

  • A first column of ones representing an overall mean or intercept.

  • Additional columns containing covariates or predictors.

For example, the second column could contain:

  • Age.

  • A demographic measure.

  • A behavioral score.

  • Another experimental variable.

The parameter vector may contain two coefficients:

βˉ=[β1β2]\bar{\beta} = \begin{bmatrix} \beta_1\\ \beta_2 \end{bmatrix}βˉ​=[β1​β2​​]

Here:

  • β1\beta_1β1​ represents the contribution of the intercept or overall mean.

  • β2\beta_2β2​ represents the effect of the second covariate.


15. Prior and Likelihood in the General Linear Model

Bayesian estimation requires a prior distribution over the parameters and a likelihood for the observed data.

15.1 Prior over parameters

A simple prior is:

P(βˉ)=N(0,I)P(\bar{\beta}) = \mathcal{N}(0,I)P(βˉ​)=N(0,I)

where:

  • The prior mean is zero for each parameter.

  • III is the identity covariance matrix.

  • Each parameter has variance 111.

  • The diagonal covariance indicates no prior interaction or covariance between the parameters.

More generally, the prior could be written as:

P(βˉ)=N(βˉ;μp,Σp)P(\bar{\beta}) = \mathcal{N}(\bar{\beta};\mu_p,\Sigma_p)P(βˉ​)=N(βˉ​;μp​,Σp​)

where μp\mu_pμp​ and Σp\Sigma_pΣp​ specify the prior mean and covariance.

15.2 Likelihood of the data

The likelihood is:

P(Y∣βˉ)=N(Y;Xβˉ,Σ)P(Y\mid\bar{\beta}) = \mathcal{N}(Y;X\bar{\beta},\Sigma)P(Y∣βˉ​)=N(Y;Xβˉ​,Σ)

This states that the predicted mean of the observations is XβˉX\bar{\beta}Xβˉ​, with uncertainty described by Σ\SigmaΣ.

The likelihood answers:

How probable are the observed data if the parameters have the value βˉ\bar{\beta}βˉ​?

15.3 Posterior distribution

The posterior is:

P(βˉ∣Y)=P(Y∣βˉ)P(βˉ)P(Y)P(\bar{\beta}\mid Y) = \frac{P(Y\mid\bar{\beta})P(\bar{\beta})}{P(Y)}P(βˉ​∣Y)=P(Y)P(Y∣βˉ​)P(βˉ​)​

The evidence term is:

P(Y)=∫P(Y∣βˉ)P(βˉ) dβˉP(Y) = \int P(Y\mid\bar{\beta})P(\bar{\beta})\,d\bar{\beta}P(Y)=∫P(Y∣βˉ​)P(βˉ​)dβˉ​

For Gaussian linear models, this integral can be evaluated analytically. However, more complicated nonlinear models generally make this calculation difficult or impossible to perform exactly.


16. Approximate Bayesian Inference

In nonlinear models, the evidence integral may be intractable, meaning that it cannot be calculated explicitly using ordinary analytical methods.

Approximate inference methods are then used.

16.1 Variational Bayes

Variational Bayes approximates the true posterior using a more manageable probability density, often denoted by qqq:

q(βˉ)≈P(βˉ∣Y)q(\bar{\beta}) \approx P(\bar{\beta}\mid Y)q(βˉ​)≈P(βˉ​∣Y)

The approximating density is selected from a tractable family of distributions.

This approach is useful for:

  • Nonlinear models.

  • Large parameter spaces.

  • Biophysical neural models.

  • Dynamic causal models.

  • Situations where direct integration is computationally impractical.

16.2 Variational Laplace

One form of variational inference is variational Laplace. In this approach, the posterior is approximated around its most probable region, often using a Gaussian approximation.

The method may hold certain parameters or hyperparameters fixed while estimating the approximate posterior over the remaining parameters.

16.3 Log model evidence and free energy

Computations are often performed using the logarithm of the model evidence:

log⁡P(Y)\log P(Y)logP(Y)

The logarithm is mathematically convenient because it converts products into sums and improves numerical stability.

An approximation to the log model evidence is commonly called variational free energy, denoted by FFF:

F≈log⁡P(Y)F \approx \log P(Y)F≈logP(Y)

The free energy provides a lower bound on the log model evidence:

F≤log⁡P(Y)F \leq \log P(Y)F≤logP(Y)

It is useful for:

  • Comparing competing models.

  • Selecting among alternative neural architectures.

  • Evaluating different neurobiological mechanisms.

  • Comparing dynamic causal models.

A model with greater free energy generally has greater approximate evidence, although model comparison must account for both explanatory accuracy and model complexity.


17. Bayesian Inference in SPM

SPM can implement approximate Bayesian inference numerically, including for nonlinear system-identification problems.

A nonlinear system-identification routine can estimate:

  • Posterior distributions over model parameters.

  • Approximate model evidence.

  • Free energy.

  • Iterative changes in the inferred solution.

The same general procedure can be applied to:

  • General linear models.

  • Nonlinear models.

  • Dynamic causal models.

  • Biophysical neural-network models.

17.1 Defining the model

A model must specify:

  • The data YYY.

  • The design matrix XXX.

  • The parameter vector.

  • The equation relating parameters to predicted data.

  • The noise model.

  • The prior mean.

  • The prior covariance.

For a general linear model:

Y=Xβˉ+ϵY = X\bar{\beta}+\epsilonY=Xβˉ​+ϵ

The design matrix includes the predictors, while βˉ\bar{\beta}βˉ​ contains their unknown effects.

17.2 Defining priors

The prior parameter values may be initialized with a mean of zero. A unit covariance or variance may be used as a simple default:

μp=0\mu_p = 0μp​=0

and:

Σp=I\Sigma_p = IΣp​=I

A prior covariance matrix determines the initial uncertainty and any assumed relationships between parameters.

17.3 Simulated data example

A simulated dataset may include:

  • 202020 observations or participants.

  • Two model parameters.

  • A design matrix with an intercept column and a covariate column.

  • Random noise around the model prediction.

The model prediction is:

XβˉX\bar{\beta}Xβˉ​

The observed data equal the prediction plus random error:

Y=Xβˉ+ϵY = X\bar{\beta}+\epsilonY=Xβˉ​+ϵ

The inference routine uses the specified prior and the observed data to estimate the posterior parameter values.


18. Iterative Estimation and the EM Algorithm

Variational Bayesian methods are typically iterative.

One implementation uses an expectation-maximization, or EM, style algorithm. The process repeatedly updates the approximate posterior and related quantities until convergence.

18.1 Iterative procedure

A general iterative process is:

  1. Initialize the model parameters and prior-related quantities.

  2. Evaluate how well the current model explains the data.

  3. Update the approximate posterior distribution.

  4. Recalculate the model evidence or free energy.

  5. Measure the change in free energy.

  6. Repeat until the change becomes sufficiently small.

The algorithm may display:

  • The iteration number.

  • The current free-energy value.

  • The change in free energy between iterations.

  • The current approximate posterior estimates.

18.2 Convergence

The algorithm is considered to have converged when:

  • The free energy changes very little between iterations.

  • The change falls below a predefined threshold.

  • Further updates no longer substantially alter the posterior.

At convergence, the estimated parameter values are treated as the approximate posterior solution.

For the example discussed, the posterior parameter estimates were approximately:

β1≈−0.2595\beta_1 \approx -0.2595β1​≈−0.2595

and:

β2≈0.6128\beta_2 \approx 0.6128β2​≈0.6128

These values reflect the combination of:

  • The prior assumptions.

  • The observed data.

  • The likelihood model.

  • The approximate Bayesian inference procedure.


19. Graphical Interpretation of the Results

The software output can display the fit and the posterior parameter estimates graphically.

19.1 Data and model prediction

One plot displays:

  • The observed data.

  • The model prediction.

  • The evolution of the prediction across iterations.

The prediction should increasingly approach the observed data as the algorithm updates the parameter estimates.

In the example, the model and data curves eventually coincide closely after sufficient iterations, indicating that the model has reached a stable fit.

19.2 Posterior parameter bars

A second plot displays the posterior estimates for the model parameters.

For two parameters, the graph contains two bars. The bars indicate the deviation of each posterior parameter estimate from its prior value.

This visualization helps show:

  • Which parameters changed substantially from their priors.

  • The direction of each parameter update.

  • The relative magnitude of the inferred effects.

The graphical output is another representation of the posterior distribution obtained through approximate Bayesian inference.


20. Main Applications and Conclusions

Bayesian inference provides a general framework for reasoning about uncertain causes, effects, and predictions.

Its central operations are:

  1. Start with a prior belief.

  2. Specify a likelihood describing how data arise under each possible hypothesis.

  3. Combine the likelihood and prior using Bayes’ theorem.

  4. Normalize using the model evidence.

  5. Obtain a posterior belief.

  6. Use that posterior as a future prior when new evidence arrives.

The framework applies to:

  • Everyday prediction, such as receiving a tennis ball.

  • Perception and neural theories such as predictive coding.

  • Scientific questions involving uncertain causal relationships.

  • Brain connectivity estimation.

  • EEG and other neural data.

  • General linear models.

  • Nonlinear system identification.

  • Dynamic causal modeling.

  • Model comparison using approximate evidence or free energy.

The most important conceptual distinction is between the direction of prediction and the direction of inference:

  • The forward model predicts effects from causes using P(Y∣θ)P(Y\mid\theta)P(Y∣θ).

  • The inverse model infers causes from effects using P(θ∣Y)P(\theta\mid Y)P(θ∣Y).

Because several causes may generate the same observations, inverse inference is often ill-posed. Bayesian methods address this uncertainty by combining evidence with prior assumptions and expressing the result as a probability distribution rather than as a single certain answer.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent