TL;DR
The Bellman equation says that the value of a state is the best immediate reward you can get there, plus the discounted value of the state you move into next. It is a one-step rule that holds for the whole future. Writing the value of a long decision sequence this way lets you solve it one step at a time.
Where you'll see it: in value iteration and Q-learning, in the update rules that turn a reward into a learned value, and in optimal control problems from inventory planning to route finding.
Intuition
Suppose you are deciding how to get out of a maze. You do not need to plan the whole route at once. You only need to know, from each junction, which neighbouring junction is worth the most. If you already know the value of every neighbour, the value of your current junction is just the best step plus what you expect from there.
That recursion is the whole idea. A long-horizon problem becomes a set of local consistency conditions. Each state's value must agree with its neighbours' values, after one step of reward and one step of discounting. A value function that satisfies all these conditions is the right answer, and the Bellman equation is the list of those conditions.
It exists because looking ahead by brute force is hopeless. A game with 20 moves and 3 choices per move has 3^20, about 3.5 billion, paths. The Bellman equation avoids enumerating paths: it reuses the answers already computed for the next state.
- gamma = 0.9
- gamma = 0.5
The math
Setting
The environment is a Markov decision process. There are states , actions , transition probabilities for the chance of landing in after taking in , and expected immediate rewards . The discount factor lies between 0 and 1 and says how much a reward one step later is worth compared with one now.
A policy gives the probability of each action. The value function is the expected discounted return from under . The optimal value function is the best any policy can do:
Bellman expectation equation
For a fixed policy, the value of is the average over actions of the reward plus the discounted value of the next state:
This is the same equation as in the value function lesson. It is linear in the unknown values, so it can be solved directly or iterated.
Bellman optimality equation
The optimal value function satisfies the same kind of equation, except that the average over actions becomes a maximum. The agent is free to choose the best action, so
This is the Bellman equation proper. It is a fixed-point equation. The true is the one function that makes both sides equal for every state.
The same idea works for the action-value function , which fixes the first action and then acts optimally:
Once you have , the optimal policy is simply to pick the action with the largest in each state.
Why the discount factor matters
The discount factor makes the infinite sum finite. If the reward is bounded by , the discounted return is at most , so the fixed-point equation has a unique solution. Values stay finite, and iterating the equation converges. Smaller makes the agent short-sighted; close to 1 makes it plan far ahead, and the numbers can take many iterations to settle.
Value iteration
Turning the optimality equation into an algorithm gives value iteration. Start with any guess , and repeat
for every state. Each pass is a Bellman backup. Because the backup shrinks the error between guesses by a factor of each time, the values converge to .
- Set for every state .
- For each state , compute the backup and store it as the new .
- Stop when no value changes by more than a small threshold.
- For each state, choose the action that achieves the maximum. That action is optimal.
Worked examples
Take a state with a policy that always takes action . Action gives reward . From there the environment goes to state with probability 0.8 and to state with probability 0.2. Suppose and . Let .
- Expected next value: .
- Discount it: .
- Add the immediate reward: .
So . The number reads as: starting in , you expect to collect 9.2 in discounted reward, counting the immediate 2 and the discounted future.
State has two actions. Action "stay" gives reward 1 and returns to with certainty. Action "leave" gives reward 0 and moves to a state with certainty, where the optimal value is . Let .
The optimality equation for is
- Guess that "stay" is best, so . Solving: , so .
- Check the other branch: , which is less than . The guess is consistent.
- So and the optimal action is "stay".
Now run value iteration from to see the values climb:
| Iteration | Backup for | Value |
|---|---|---|
| 0 | start | 0 |
| 1 | 3.6 | |
| 2 | 4.24 | |
| 3 | 4.816 |
The values rise steadily toward 10. Once the "stay" branch wins, the gap to 10 shrinks by a factor of per iteration (5.76, then 5.184, and so on), so convergence is geometric.
Three states: , and a terminal goal with value 0. From the only action moves to with reward 0. From the only action moves to with reward 10. Take .
- Value of : .
- Value of : .
The reward of 10 is worth 10 at but only 5 at , because is one step further away and each step of delay halves its weight. Working backwards from the goal, one backup per state, gives the answer without enumerating any paths.
Tradeoffs and failure modes
The Bellman equation is exact when you know and . Its cost grows with the number of states, because each backup sums over all next states and all actions. In problems with millions of states, you approximate the value function with a neural network or with samples instead.
| Situation | Problem | Better choice |
|---|---|---|
| Model is known, state space is small | Full sweeps are cheap and exact | Value iteration or policy iteration |
| Model is unknown | Cannot compute or | Sample-based updates such as [[q-learning |
| Very large or continuous state space | Table of values does not fit | Function approximation, such as a neural network |
| close to 1 | Values converge slowly and can be large | Use more iterations, or an algorithm that accelerates the backup |
Two failure modes come up often. First, an approximate value function with small errors can produce a policy that is far from optimal, because the max amplifies errors where two actions are close in value. Second, sample-based backups can be unstable when the approximation and the bootstrapping interact, which is a known problem with off-policy training.
History
Richard Bellman worked at the RAND Corporation in the 1950s on multistage decisions where a choice now affects costs later. He called the general approach dynamic programming and published the core ideas in his 1957 book of that name. The principle that an optimal policy's remaining choices must themselves be optimal, which underlies the recursion, is known as the principle of optimality.
The equation was named after him later. Ronald Howard developed policy iteration around 1960, and the approach spread through operations research and control theory. In the late 1980s, Chris Watkins and others connected the Bellman recursion to learning from experience, which led to Q-learning and the wider use of the equation in reinforcement learning.
Check yourself
QuestionRecall: state the Bellman optimality equation for in words.Show answer
QuestionComputation: a state has reward 1 for every action and always returns to itself. Find the optimal value for using .Show answer
QuestionWhy: why does the discount factor need to be less than 1 for the Bellman equation to have a unique solution in an infinite-horizon problem?Show answer
QuestionApplied scenario: a robot in state S can stay and collect reward 1 every step forever, or move to a charger that pays a single reward of 5 and then ends the episode. With , which should it choose?Show answer
Sources
- Sutton and Barto, Reinforcement Learning: An Introduction (2nd ed., 2018), Chapter 3: http://incompleteideas.net/book/the-book-2nd.html
- Bellman equation (Wikipedia): https://en.wikipedia.org/wiki/Bellman_equation
- Richard E. Bellman (Wikipedia): https://en.wikipedia.org/wiki/Richard_E._Bellman