Bellman Equations
V(s), Q(s,a), optimality equations, contraction mapping, curse of dimensionality
Consider a 4×4 grid world with γ = 0.9. You want to know: what is the expected total reward — the value — of being at position (2,3) if you follow the optimal policy? To answer this, you need to know the value of neighboring positions, because your value here depends on where you can move next. But those values depend on their neighbors too. The circular dependency seems impossible to resolve — yet this is exactly what the Bellman equations do: they express the value of a state as a function of the values of its successors, turning a circular problem into a recursive one with a guaranteed fixed point.
The state value function under a policy π is V^π(s) = E_π[R_{t+1} + γ V^π(S_{t+1}) | S_t = s]. The value of a state equals immediate expected reward plus discounted expected value of the next state. This is the Bellman expectation equation — self-consistent, recursive, and for a fixed policy, linear enough to solve directly.
The optimal value function is V*(s) = max_a [R(s,a) + γ Σ_{s'} P(s'|s,a) V*(s')]. The value of the best possible policy equals the action that maximizes immediate reward plus discounted future value. The action-value function Q*(s, a) = R(s,a) + γ Σ_{s'} P(s'|s,a) max_{a'} Q*(s', a') is more practically useful: it tells you the value of taking action a in state s and then acting optimally, which means you can select actions directly via argmax_a Q*(s, a) without needing to model transitions.
Value iteration starts with an arbitrary value estimate and repeatedly applies the Bellman operator until convergence. Contraction mapping theory guarantees this converges to V* for finite MDPs. Policy iteration alternates between evaluating the current policy exactly and then improving it greedily. Both are guaranteed to find the optimal policy — but only in the tabular case.
NOT this: you need to know the transition model T(s, a, s') to use Bellman equations. Model-based RL uses the equations directly with a known or learned T. Model-free RL — Q-learning, TD learning — uses samples to estimate the Bellman updates without ever modeling T explicitly. The Bellman structure guides both approaches by telling you what quantity to estimate.
Key points
- Learn the Q-function Q*(s, a), not V*(s), for most RL applications. Q*(s, a) tells you which action to take directly — argmax_a Q*(s, a) — without needing transition probabilities. V*(s) tells you how good a state is but not what to do, so unless you have a model of transitions, V alone cannot produce a policy.
- Tabular Q-learning is infeasible for large or continuous state spaces — this is not a performance issue, it is a physical impossibility. A robot with 6 joint angles discretized at 100 positions per joint has 10^12 states. Storing a Q-table for this requires ~8 TB even at 8 bytes/entry — technically storable today, but wildly impractical to fill from experience (you would need to visit and revisit trillions of state-action pairs), and it only gets worse as joints or precision increase. The moment the state space is too large to enumerate, you need function approximation — neural networks — which breaks the convergence guarantee.
- If Q-values grow without bound during training, the Bellman backup is diverging due to a feedback loop between the prediction and the target. The target y = R + γ max Q_θ(s') depends on the same θ being updated, so each gradient step shifts both the prediction and the target. Fix this with a target network: freeze θ^- for K steps so the target is stationary, then copy θ into θ^-.
The Bellman equation turns the circular problem of value estimation into a recursive fixed point: the value of a state equals immediate reward plus discounted value of the best next state — and iterating this update is guaranteed to find the answer.
Recap
- Bellman turns circular value estimation into a recursive fixed point.
- Expectation eq: $V^\pi(s) = E_\pi[R_{t+1} + \gamma V^\pi(S_{t+1})]$ — linear for a fixed policy.
- Optimality eq is nonlinear because of the `max` operator: $V^*(s) = \max_a[R + \gamma \sum P(s'|s,a)V^*(s')]$.
- Learn $Q^*(s,a)$, not $V^*$: `argmax_a Q` gives the action with no transition model needed.
- Value/policy iteration converge via contraction mapping — but only in the tabular case.
- Tabular is a physical impossibility at scale: 6 joints × 100 positions = $10^{12}$ states. Need function approximation.
- Unbounded $Q$ during training = diverging Bellman backup. Fix with a frozen target network.
Check your understanding
Q1. Write the Bellman optimality equation for Q*(s,a) and explain what makes it "nonlinear," unlike the Bellman expectation equation.
- A) Q*(s,a) = R(s,a) + γ Σ_{s'} P(s'|s,a) max_{a'} Q*(s',a') is nonlinear purely because P(s'|s,a) is itself a nonlinear stochastic function of the underlying state and action, independent of any max or expectation operator appearing anywhere in the equation
- B) The Bellman optimality equation is nonlinear because Q*(s,a) appears on both the left and right sides simultaneously, creating a circular self-referential dependency that ordinary matrix algebra and Gaussian elimination cannot resolve without iterative approximation
- C) The max_{a'} operator makes it nonlinear; the Bellman expectation equation instead uses Σ_{a'} π(a'|s') Q^π(s',a') — a linear weighted sum solvable directly as V^π = (I-γP^π)^{-1}R^π
- D) The Bellman optimality equation is nonlinear because the discount factor γ multiplies Q* by itself recursively across every future timestep, producing an infinite geometric series whose closed form requires specialised nonlinear numerical solvers
Q2. In policy iteration, why is policy improvement guaranteed to produce a policy at least as good as the current one? What is the formal argument?
- A) Policy improvement is guaranteed because at each iteration the algorithm exhaustively enumerates every possible deterministic policy over the full state space and selects whichever attains the highest expected return, so a worse policy can mathematically never be selected
- B) Because π'(s) = argmax_a Q^π(s,a) gives V^π(s) ≤ Q^π(s,π'(s)), inducting this bound through all future steps shows V^{π'}(s) ≥ V^π(s) everywhere
- C) Policy improvement is guaranteed to be non-decreasing because the greedy policy directly minimises the mean-squared Bellman error across all states, and the contraction mapping theorem guarantees that minimising this error implies the resulting policy's true value is at least as high
- D) The guarantee follows purely from the fact that Q^π(s,a) is always greater than or equal to V^π(s) for every action a in every state, so any policy derived by taking the argmax of the Q-function is mathematically guaranteed to have a value at least as high as the current policy
Q3. You are implementing Q-learning with a neural network and notice Q-values growing unboundedly during training. Which two fixes directly address the bootstrapping instability that causes this?
- A) Freeze a target network θ^- for K steps so the TD target y = R + γ max_{a'} Q_{θ^-}(s',a') stays stationary while θ is updated, breaking the positive feedback loop
- B) Clip gradients and rewards and lower the learning rate, so each individual update shifts θ (and therefore the target) by a much smaller amount
- C) Increase the network's parameter count so the function approximator can represent Q* exactly, which removes all bootstrapping error by construction
- D) Widen the reward scale to be unbounded so the max_{a'} operator saturates numerically and stops the values from growing further
Q4. How many states does a simplified Atari game environment like Pong have, and why does this make tabular DP completely impractical?
- A) Pong has approximately 10^6 states after discretising pixel values into coarse bins, which is borderline tractable computationally but far too slow for real-time online training without dedicated specialised tensor-processing hardware clusters
- B) Pong has roughly 10^20 states once the full preprocessing pipeline is applied, which is an enormous number but could in principle still be handled by a sufficiently large distributed computing cluster spanning an entire data centre
- C) Pong has exactly 84×84×3 = 21,168 states after standard DQN preprocessing, which makes tabular dynamic programming tractable in theory but impractically slow in practice purely because of the size of the discrete action space
- D) Pong at 84×84 with binary (on/off) pixels already has 2^{7056} states — vastly more than atoms in the observable universe (~2^{266}); storing V*(s) for every one is impossible, so DQN compresses the value function into ~1.7M parameters instead (the standard Nature-2015 conv+fc architecture)
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →