Markov chains & Gibbs sampling
This lecture builds Markov chains from the Markov property and the restaurant state model. It then builds samplers from accept-reject to MCMC and Gibbs. After this page you can compute mu1 equals mu0 T, check a stationary distribution, apply the accept-reject ratio, and trace Gibbs conditional steps.
Markov propertySearch on YouTube
A stochastic process has the Markov property when the future depends only on the present. Past states give no extra information once the current state is known. The process has no memory beyond the current state.
is the state at time . is the current state. is the next state. The left side conditions on the full history. The right side uses only .
Tomorrow depends only on today. Last week does not matter once today is known.
Markov chainSearch on YouTube
A Markov chain is a sequence of random variables that satisfies the Markov property. Its state set is finite or countable. The slides write .
The chain moves by transition probabilities. The value is the chance to move from state to state . Each row of the transition matrix sums to 1.
is the transition matrix. is the entry in row and column . A homogeneous chain keeps the same at every time step.
Markov chain versus hidden Markov modelSearch on YouTube
A Markov chain assumes direct access to the state. A hidden Markov model assumes hidden states plus visible outputs. The hidden states follow a Markov chain. Each hidden state emits an observation with an emission probability.
| Model | State | Observation |
|---|---|---|
| Markov chain | Future state depends only on current state | State itself is visible |
| Hidden Markov model | Hidden states follow a Markov chain | Only emissions are visible, states stay hidden |
The slides name parts of speech as hidden states and words as observations. Transition probabilities link the hidden states. Emission probabilities link each hidden state to its words.
Types of Markov modelsSearch on YouTube
The slides list four extensions of the discrete-time base model. The base model is a plain Markov chain. Each extension adds one component.
- Base model: discrete-time Markov chain.
- Base model plus rewards plus actions: decision process with control.
- Base model plus rewards: evaluation of long-run return.
- Base model plus hidden states plus observations: hidden Markov model.
Restaurant exampleSearch on YouTube
The slides model a restaurant with seats. Each seat is vacant () or occupied (). The state on one day is an -dimensional binary vector. One example is for three seats.
The number of seating patterns grows fast. Each seat has 2 options. The full state count is therefore .
is the number of seats. Each seat takes value or . The transition matrix has size .
Under the Markov assumption, tomorrow depends only on today. Regulars may reuse the same seats. Last week adds nothing once today is known. For each current pattern, the model stores transition probabilities to every next pattern.
State distribution over timeSearch on YouTube
The initial distribution stores the chance of each state on day 0. The distribution after one step is . The update is a row-vector times matrix product.
is the row distribution at time . is the transition matrix. Entry of equals .
After many days, the distribution may stop changing. That limit is the stationary distribution . It satisfies its own fixed-point equation. It gives the long-run share of each seating pattern.
is the stationary distribution. It reproduces itself through . The slides illustrate the idea as full on 70 percent of days, half-full on 20 percent, and empty on 10 percent.
Two-seat worked exampleSearch on YouTube
Two seats give states. Order them as , , , . Use a homogeneous with rows and columns that each sum to 1.
Setup. Initial distribution and transition matrix.
Step 1. Multiply . Each entry sums one column weighted by .
Step 2. Check the sum.
The mass moves toward the centre. State drops from 0.40 to 0.30 after one day.
Stationary checkSearch on YouTube
The same has uniform column sums. Each column adds to 1. The uniform distribution must therefore reproduce itself.
Claim. The uniform row is stationary.
Step 1. Multiply . Factor out 0.25 from each column sum.
Step 2. Compare.
The check passes. A further step changes nothing. In the long run each of the four patterns occurs on one quarter of days.
Exam check: verify each row of sums to 1 before you multiply. Then verify sums to 1. For a stationary check, show all four entries of and state the equality.
Sampling techniquesSearch on YouTube
Sampling selects a small subset from a population. A sound method makes the subset represent the whole. Conclusions from the subset then carry over. Sampling also speeds up work when full measurement is infeasible.
| Method | Idea | When to use it |
|---|---|---|
| Deterministic | Rule-based or systematic choice | The rule covers the population well |
| Random | Draws follow a uniform probability law | Direct draws from the target are feasible |
| Monte Carlo | Draws approximate a complex or high-dimensional distribution | Bayesian inference and generative models |
| Accept-reject | Propose from an easy law, keep some draws | A bound exists and proposals are cheap |
| Markov chain Monte Carlo | Build a chain whose limit is the target | Direct sampling is infeasible |
Monte Carlo sampling splits into accept-reject and Markov chain Monte Carlo. Gibbs sampling is one Markov chain Monte Carlo method.
D R M A G: Draws Run Many And Gather
Deterministic · Random · Monte Carlo · Accept-reject · Gibbs (an MCMC method). MCMC then warns T C S C: Trapped modes, Correlated draws, Slow mixing, Complex conditionals.
Accept-reject samplingSearch on YouTube
Accept-reject generates draws from a hard target . It uses an easy proposal . A constant scales so it covers at every . Candidates come from . Each candidate survives with a ratio chance.
is the target distribution. is the easy proposal distribution. is a constant that lifts above .
Draw from Uniform. Accept when . Else reject and draw again.
The method treats each candidate alone. It ignores past accepted draws. Regions with high likely hold more good points nearby, but accept-reject does not use that fact. The next candidate starts afresh from .
Setup. Target on . Proposal on . Bound .
Candidate .
Draw . Since , accept .
Candidate .
Draw . Since , reject .
Small values rarely survive. Many proposals go to waste near 0. That waste motivates MCMC.
Do not pick too small. The bound must hold at every . A violated bound gives a wrong sampled distribution.
Markov chain Monte CarloSearch on YouTube
MCMC fixes the waste of accept-reject. It exploits a simple fact: high-density regions sit near other high-density regions. A draw near an accepted point has a strong chance of acceptance. So MCMC builds a chain of dependent draws instead of fresh independent draws.
The chain has transition law . It moves toward denser points of . Its equilibrium equals the target . More steps bring the sample histogram closer to the target.
is the -th sample in the chain. is the move chance. The chain limit matches the target distribution.
Burn-in phaseSearch on YouTube
Sampling starts at . Early draws through do not yet match the target. That early stretch is burn-in. The chain reaches the target near . Keep as samples. Discard the burn-in draws.
Gibbs samplingSearch on YouTube
Gibbs sampling draws from a joint law of two or more variables. It is an MCMC method, so its draws are dependent. It replaces one hard joint draw with easy conditional draws. For fixed , acts as a constant. The sampler needs only relative chances, not the full normalizer .
is the joint chance. sums the joint over . No full joint normalizer is needed for the conditional step.
Fix and sample from this law. Then fix and sample . Alternate the two steps to form the chain.
The chain stationary state equals the joint target. Samples before that state count as burn-in. Discard them for the same reason as in MCMC.
Gibbs conditional traceSearch on YouTube
Use a binary pair with a known joint table. The trace below derives the conditionals and then runs three Gibbs steps.
Joint table. Rows are , columns are .
| Y=0 | Y=1 | |
| X=0 | 0.10 | 0.20 |
| X=1 | 0.30 | 0.40 |
Margins. Sum rows and columns.
Conditionals for given .
Conditionals for given .
Trace from . Use uniform draws and at each half-step.
The chain visits , then , then . Treat the first visits as burn-in. Keep the later states for estimates.
Limits of Gibbs samplingSearch on YouTube
Gibbs sampling handles high-dimensional targets that defeat direct sampling. Its dependence is also its weakness. The slides list five linked failure modes.
- Trapping: the chain sticks in one local high-probability region.
- Bias: poor exploration misrepresents the full distribution.
- Slow convergence: high correlation between variables slows mixing.
- Complex conditionals: irregular shapes make each hard to derive.
- High dimensions: many dependent conditionals reduce accuracy.
Do not keep burn-in draws. Early samples reflect the start point, not the target. Also check mixing when variables show strong correlation. A chain trapped in one mode gives biased estimates.
Quick self-testSearch on YouTube
1. State the Markov property in one formula and one sentence.
. The future depends only on the present state.
2. Differentiate a Markov chain and a hidden Markov model.
A Markov chain shows its state directly. A hidden Markov model hides the Markov states and shows only emissions. Transitions link hidden states, emissions link hidden states to observations.
3. A restaurant has 3 seats. How many states exist, and what is the size of T?
states. has size , with 64 entries. Each of the 8 rows sums to 1.
4. With mu0 equals [0.10 0.20 0.30 0.40] and the lecture T, compute mu1 for state 01.
. Full .
5. Check whether [0.25 0.25 0.25 0.25] is stationary for the lecture T.
Yes. Each column of sums to 1, so each entry gives . Hence .
6. Target f(x) equals 3x squared on [0,1], proposal g(x) equals 1, c equals 3. Candidate x equals 0.5: find the accept chance. Draw u equals 0.10: accept or reject?
. Accept chance . Since , accept .
7. Why does MCMC explore high-probability regions better than accept-reject?
Accept-reject draws each candidate afresh from and ignores past draws. MCMC chains the draws and proposes near the current point. A point near a good draw has high density and a strong accept chance.
8. In Gibbs sampling with variables X and Y, which two conditional steps alternate?
Sample from with fixed. Then sample from with fixed. Repeat until the chain reaches its stationary state.
9. Joint chances: P(0,0) equals 0.10, P(0,1) equals 0.20, P(1,0) equals 0.30, P(1,1) equals 0.40. Find P(X equals 1 given Y equals 0).
. .
10. Name two Gibbs failure modes and the fix the slides advise.
Trapping in a local mode and slow mixing from correlated variables. Tune the sampler with care and run convergence and mixing checks. Discard burn-in draws.
- The Markov property keeps only the present: the future given the full history equals the future given .
- A Markov chain is a memoryless sequence with state set and transition matrix .
- A hidden Markov model hides Markov states and shows only emissions through emission chances.
- The restaurant with seats has binary states and a transition matrix.
- Distributions evolve by . The stationary limit obeys .
- Two-seat check: gives . Uniform is stationary.
- Sampling ladder: deterministic, random, Monte Carlo, accept-reject, MCMC with Gibbs.
- Accept-reject needs and keeps with chance . Example gives 0.49 at .
- MCMC builds with . Its limit is the target. Discard burn-in before .
- Gibbs sampling alternates and . It avoids the joint normalizer .
- Gibbs pitfalls: trapped modes, biased samples, slow mixing, complex conditionals, high dimensions.
Markov Stationary Distribution
Markov Chains Stationary
MCMC Explained
Gibbs Sampling Explained