MDPs and the Bellman Equation
The five parts of a Markov decision process, why a policy beats a plan under uncertainty, and the self-consistency condition every utility must satisfy.
Search assumed your actions do what you intend. Drop that assumption - let an action succeed most of the time and slip occasionally - and a fixed sequence of moves stops being a useful answer. What you need instead is a rule that tells you what to do from wherever you actually end up.
The five parts
A Markov decision process is a sequential decision problem with a fully observable, stochastic environment. It is specified by:
| Part | Symbol | What it supplies |
|---|---|---|
| States | The situations the agent can be in | |
| Actions | What it may attempt from state | |
| Transition model | Probability of landing in | |
| Reward | What being in is worth | |
| Discount | How much a future reward is worth now |
Two of these carry more weight than they first appear to.
The transition model is where uncertainty lives. is a distribution, not an outcome. Attempting to move right might take you right with probability and leave you where you are with probability . The agent does not choose ; it chooses only .
The Markov property is the assumption that makes this tractable. The next state depends on the current state and action alone - not on how you arrived. That is a real restriction, and it is what lets you attach one number to each state instead of to each possible history.
Reward on the state. This course follows Russell & Norvig, where the reward attaches to the state you are in, written . Much of the literature attaches it to the transition instead, . The theory is the same either way, but the equations look different, so expect the discrepancy when comparing sources.
Why the answer is a policy
Because outcomes are stochastic, a plan like "right, right, up" is worthless: the first slip puts you somewhere the rest of the sequence no longer addresses.
The answer is a policy - an action recommended for every state. It never runs out of applicability, because whatever happens, you are in some state and the policy has an answer for it. An optimal policy is one that maximises expected utility.
What the best policy depends on. The figure below is Russell & Norvig's 4x3 world: four squares by three with one blocked by a wall, and two exits worth and . Its transition model is a little richer than the one above: each move goes as intended with probability and to either side with , and there is no discounting. The one thing you move is the living reward R, the every non-terminal square pays, and the optimal policy is a step function of it: at eight thresholds, one square's arrow turns over. The button the textbook -0.04 brings it back to the value Russell & Norvig use.
Interactive: the policy as a step function of the living reward
The 4x3 world, 0.8 intended, 0.1 each side, discount 1.
- Utility of square (1,1)
- 0.705308
- Policy interval
- 7 of 9
- Squares unlike the textbook
- 0
- Value iteration vs exact
- 5.4e-15
At R = -0.04 the optimal policy is the one that holds for every living reward between -0.044833 and -0.027357, and U(1,1) is 0.705308. At (3,1) the agent goes left, the long way round, as far from the pit as it can keep.
The Bellman equation
Suppose you already knew , the utility of every state. Then the value of being in decomposes into what you collect now and what you can expect afterwards:
Read it slowly, because every piece is doing work:
- - collected for being in , regardless of what you do next.
- - you choose the action, so you take the best one available.
- - you do not choose the outcome, so the future is an average weighted by the transition model.
- - discounts that future relative to the present.
The order matters: maximise over what you control, average over what you do not.
This is a condition, not a recipe. It says nothing about how to find ; it says only that the true must satisfy it at every state simultaneously. With states you get equations in unknowns - but they are nonlinear, because is not a linear operator, so you cannot simply solve them with linear algebra. Getting from this condition to actual numbers is the next lesson.
The order of operations is the part a formula cannot show, so the figure below takes it apart. Each action gets its own line with its own average over the outcomes it does not control, and the maximum is taken visibly between the lines rather than inside a symbol. Drag the discount to watch the future term grow from nothing: at zero the agent sees only the living cost, and near one it is dominated by a reward several steps away.
Interactive: one Bellman backup, opened up
Maximise over what you control. Average over what you do not.
Each action, averaged over what it cannot choose
- right0.8 x 0.7972 (B) + 0.2 x 0.6512 (A) = 0.7680
- stay1.0 x 0.6512 (A) = 0.6512
- Collected now
- -0.0400
- Discounted future
- 0.6912
- U at this state
- 0.6512
- Action taken
- right
From A at a discount of 0.90, the reward collected now is -0.0400 whatever you do - that is R(s), and it does not depend on the action. Then each action averages over outcomes it does not control: going right is worth 0.7680 on average and staying 0.6512. The max picks right, and U works out at 0.6512. Drag the discount: the chosen action never changes on this problem, because B is always nearer the reward than A. What changes is the value, from a myopic -0.0400 that is nothing but the living cost to a far-sighted number a reward several steps away dominates.
Why discounting
With , a reward steps away is worth times its face value. Two reasons this matters:
- It bounds the total. An infinite run of bounded rewards would otherwise sum to infinity, and infinities cannot be compared.
- It expresses genuine preference. Sooner is usually better.
At the agent is myopic, caring only about . As it becomes far-sighted, willing to accept a long unrewarding stretch for a large payoff at the end.
Try it live. Watch occupancy probabilities evolve from the transition rates alone, with no policy involved yet. This one is a continuous-time chain with an absorbing failure state, so it never settles: over the printed horizon the mass drains steadily into failed.
Runs in your browser. The first run downloads the Python runtime (~10 MB), then it is cached.
Before the quiz
Be able to list the five parts, state what the Markov property forbids, explain why a policy beats a plan under uncertainty, and point at which term in the Bellman equation is a maximisation and which is an expectation - and why they are not interchangeable. The companion article Markov Decision Processes derives the same material at more length.
References & further reading
- Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library
Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.
Unlock the full path
This first lesson is free. Enrol to take the mastery quiz, earn XP, and unlock every module, with more interactive, runnable examples throughout.