PS 12 Markov chains and information
Previous: PS 11 Bayesian Inference | PS 00 Course Map
A Markov chain models a sequence in which the next state depends only on the current one, and entropy, cross-entropy and KL divergence measure uncertainty and the mismatch between distributions.
These two topics finish the course because robot learning leans on both: decision problems are built on Markov chains, and nearly every loss function is an information quantity.
Part 1: Markov chains
The Markov property
A sequence of random states is a Markov chain when
Given the present, the future is independent of the past. The current state contains everything relevant for predicting what comes next.
Whether this holds depends on what you put in the state. A ball’s position alone is not Markov (you need to know which way it is moving); position and velocity together are. Choosing a state that makes the problem Markov is a central modelling decision.
Transition matrix
For a finite set of states, collect the transition probabilities in a matrix:
Each row sums to 1 (from state you must go somewhere).
Running example. Weather with two states, sunny (S) and rainy (R):
A sunny day is followed by sun with probability 0.9. A rainy day is followed by rain with probability 0.5.
Evolving a distribution
Write the distribution over states at time as a row vector . One step later:
Start sunny, :
The numbers are settling.
Stationary distribution
A distribution is stationary when one more step leaves it unchanged:
For the example, with : the first component gives , so , , and therefore
In the long run it is sunny five days in six, whatever the starting weather.
In the language of LA 08 Eigenvalues and Eigenvectors, is a left eigenvector of with eigenvalue 1. The other eigenvalue here is (trace is ), and it controls the speed of convergence: the distance to stationarity shrinks by a factor of each step. Check: , then , then .
A chain converges to a unique stationary distribution from any start when it is irreducible (every state can reach every other) and aperiodic (it does not cycle with a fixed period).
From chains to decisions
Add actions that influence the transitions, and rewards, and you have a Markov decision process: and . A policy chooses actions; fixing the policy turns the MDP back into a Markov chain. This is the formal setting of 09 Reinforcement Learning, and the Bellman equation is the law of total expectation (PS 04 Expectation and Variance) applied to one step of that chain.
Part 2: Information
Surprise
How surprised should you be by an event of probability ? Define the information content as
Certain events () carry zero surprise; rare events carry a lot. The logarithm makes surprise add for independent events, since their probabilities multiply. With the unit is bits: a fair coin flip is 1 bit.
Entropy
The entropy of a distribution is its average surprise:
It measures uncertainty, and equals the minimum average number of bits needed to encode outcomes.
| Distribution | Entropy (bits) |
|---|---|
| fair coin | |
| coin with | |
| certain outcome | |
| fair 8-sided die |
Compute the second. .
Entropy is largest for the uniform distribution and zero when the outcome is certain. In reinforcement learning, an entropy bonus rewards a policy for staying uncertain, which encourages exploration.
Cross-entropy
Suppose the truth is but you use a model . Your average surprise is the cross-entropy:
It is always at least : using the wrong model can only increase average surprise.
When puts all its mass on the true label (a “one-hot” target), this collapses to : the classification loss from PS 09 Estimation and Maximum Likelihood. A model that assigns probability 0.9 to the right class pays ; one that assigns 0.01 pays . Confident mistakes are punished severely.
KL divergence
The extra surprise caused by using in place of :
Properties:
- , with equality only when .
- It is not symmetric: . So it is not a true distance.
Since does not depend on the model, minimizing cross-entropy, minimizing KL to the data distribution, and maximizing likelihood are the same thing. Three names, one objective.
The asymmetry matters. is huge wherever has mass and has almost none, so minimizing it forces to cover everything the data does. If the data has two modes and is a single Gaussian, the best cover is a wide blob over both, with its peak in the empty middle. The reverse direction, , instead makes lock onto one mode. This is the mathematics behind the mode-averaging problem of PS 07 The Multivariate Gaussian.
Worked example. , , in bits:
Reverse: . Different, as promised.
Mutual information
How much does knowing reduce uncertainty about ?
It is zero exactly when and are independent, and unlike correlation it detects any kind of dependence, not just linear (PS 06 Joint Distributions and Covariance). Contrastive representation learning maximizes a bound on it.
Learn by doing
- For , find the stationary distribution.
- Starting from state 1 in that chain, find the distribution after two steps.
- Compute the entropy in bits of the distribution .
- A classifier gives the correct class probability 0.5. What is the cross-entropy loss in nats? What if it gives 0.99?
- and give .
- . .
- bits.
- and .
Where this shows up
Markov decision processes (09 Reinforcement Learning), KL-constrained policy updates and entropy bonuses (Appendix - PPO SAC and Offline Learning), the diffusion training bound (08 Diffusion and Flow Matching) and distribution shift measured as divergence between training and deployment state distributions (06 Imitation and Distribution Shift).
You have finished the course. Return to the checkpoint questions in PS 00 Course Map.