Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Today’s value is today’s reward plus tomorrow’s value
How good is it to stand at a crossroads? It is whatever you collect on the next step, plus how good the place you end up in is. If you always pick the road whose next step plus next place is best, you are playing perfectly. This simple idea, applied to every place at once, is the Bellman equation, and almost every reinforcement learning method is built on it.
Richard Bellman named the method ‘dynamic programming’ partly because the name sounded impressive enough to protect his research budget.
- 1. The value of a place is the next reward plus…
- 2. Always picking the best next step plus next place gives…
- 3. The Bellman equation is applied…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Bellman expectation equation: V^π(s) = Σ_a π(a|s) [R(s, a) + γ Σ_s’ P(s’|s, a) V^π(s’)].
- Bellman optimality equation: V*(s) = max_a [R(s, a) + γ Σ_s’ P(s’|s, a) V*(s’)]; for actions, Q*(s, a) = R(s, a) + γ Σ_s’ P(s’|s, a) max_a’ Q*(s’, a’).
- Operators: T^π and T* map a value vector to the right-hand side; V^π and V* are their fixed points.
- Greedy policy: π(s) = argmax_a [R(s, a) + γ Σ_s’ P(s’|s, a) V(s’)]. Greedy with respect to V* is optimal.
- Contraction: ||TV − TU||∞ ≤ γ ||V − U||∞, so repeated application converges to the unique fixed point.
- Bellman residual: ||TV − V||∞, computable without knowing V.
- 1. V* is the fixed point of…
- 2. A policy greedy with respect to V* is…
- 3. The Bellman operator shrinks distances by a factor…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Bellman operators in code
Exercise 1.
- The machine MDP (working or broken, run or repair) with γ = 0.9.
- Check that the exact value of ‘run when working, repair when broken’ is a fixed point of its Bellman equation.
- Iterate the optimality operator from zero, read off the greedy policy, and test the contraction inequality on two value vectors.
Practice.
- Write one function for one-step lookahead Q(s, a) = R + γ P V; both operators and the greedy policy use it.
- Use the residual as a stopping rule, but remember that it bounds the error only up to a factor 1/(1 − γ).
- Judge values by the policy they produce: a constant offset in V leaves the greedy policy unchanged.
- Use the Q form when the model P is unknown: the greedy action is argmax_a Q(s, a), with no model needed.
- Tools: NumPy einsum for tabular operators; deep RL replaces the table by a network but keeps the same targets.
def q_values(P, R, V, gamma):
return R + gamma * np.einsum("sat,t->sa", P, V)
T_star = lambda V: q_values(P, R, V, gamma).max(1)
greedy = lambda V: q_values(P, R, V, gamma).argmax(1)- 1. Without a model, the greedy action is found from…
- 2. A constant offset added to V…
- 3. A small Bellman residual guarantees small error only up to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Contraction. For any V, U and state s, |max_a f(a) − max_a g(a)| ≤ max_a |f(a) − g(a)|, so |(TV)(s) − (TU)(s)| ≤ γ max_a Σ_s’ P(s’|s, a) |V(s’) − U(s’)| ≤ γ ||V − U||∞. By the Banach fixed-point theorem, T* has a unique fixed point V*, and iterating it from any start converges geometrically.
Residual bounds error. ||V − V*|| ≤ ||V − TV|| + ||TV − TV|| ≤ ||TV − V|| + γ||V − V||, so ||V − V*|| ≤ ||TV − V|| / (1 − γ). The bound is tight: for V = V + c the residual is (1 − γ)c while the error is c.
Greedy policies from approximate values (Singh and Yee 1994). If ||V − V*||∞ ≤ ε, the greedy policy π satisfies V^π ≥ V* − 2γε/(1 − γ). Errors in values matter only insofar as they change the ranking of actions.
- 1. The Banach fixed-point theorem gives…
- 2. For V = V* + c the residual is…
- 3. The greedy-policy loss bound is…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How well do the Bellman residual and the value error predict the quality of a policy? Test the classical bounds on random MDPs at three discount factors.
History.
- R. Bellman (1957) stated the principle of optimality and the equations that bear his name.
- D. Blackwell (1965) and E. V. Denardo (1967) framed them as contraction mappings.
- R. J. Williams and L. C. Baird (1993) and S. P. Singh and R. C. Yee (1994) bounded the loss of greedy policies from approximate values.
- D. P. Bertsekas and J. N. Tsitsiklis (1996) built approximate dynamic programming on these bounds.
Exercise 2.
- 20 random MDPs with 20 states and 4 actions (each action leads to 3 random states; rewards uniform on 0 to 1), γ = 0.5, 0.9 and 0.99.
- V* by iterating T*; then V = V* plus uniform noise of size ε (10 draws per ε), and V = V* + 1 (a constant shift).
- Measured: error / residual, and the loss V* − V^π of the greedy policy, against the bounds.
Seed 0:
| γ | error/residual, random noise (max) | constant shift | bound 1/(1 − γ) |
|---|---|---|---|
| 0.5 | 1.33 | 2 | 2 |
| 0.9 | 1.19 | 10 | 10 |
| 0.99 | 1.45 | 100 | 100 |
| γ | greedy loss, ε = 0.01 (mean / max / bound) | ε = 0.1 | ε = 1 |
|---|---|---|---|
| 0.5 | 0.0001 / 0.0044 / 0.02 | 0.0117 / 0.063 / 0.2 | 0.358 / 0.999 / 2 |
| 0.9 | 0.0011 / 0.0155 / 0.18 | 0.048 / 0.332 / 1.8 | 1.65 / 6.87 / 18 |
| 0.99 | 0.0009 / 0.041 / 1.98 | 0.265 / 3.84 / 19.8 | 13.4 / 57.9 / 198 |
- Every case respected both bounds.
- The residual bound was reached exactly by a constant shift, yet a shift never changed the greedy policy: the error that makes the bound tight is harmless for control.
- For random noise the error was only 1.1 to 1.5 times the residual, so in practice the residual is a much better guide than the worst-case bound suggests.
- The greedy-policy loss grew with γ for the same noise: at ε = 0.1 the worst loss rose from 0.063 to 3.84 as γ went from 0.5 to 0.99, still a fifth of the bound or less.
- Seeds 1 and 2: at γ = 0.99 and ε = 1 the worst losses were 66.2 and 43.2 (bound 198); at γ = 0.9 and ε = 0.1, 0.27 and 0.39 (bound 1.8).
Bellman equations in practice
- Every value-based method uses a Bellman target: dynamic programming (next topic), TD learning, Q-learning and DQN.
- With function approximation the projected Bellman operator need not be a contraction, which is the root of the instability of off-policy learning with networks (the deadly triad).
- Bellman residual minimisation is an alternative to fitting Bellman targets, with different bias.
- Model-based planning applies the same lookahead with a learned model.
References
- R. Bellman (1957). Dynamic Programming. Princeton University Press.
- E. V. Denardo (1967). “Contraction mappings in the theory underlying dynamic programming.” SIAM Review.
- S. P. Singh and R. C. Yee (1994). “An upper bound on the loss from approximate optimal-value functions.” Machine Learning.
- D. P. Bertsekas and J. N. Tsitsiklis (1996). Neuro-Dynamic Programming. Athena Scientific.
- R. S. Sutton and A. G. Barto (2018). Reinforcement Learning: An Introduction, 2nd edition. MIT Press.