- Bellman Expectation Backup and Policy Evaluation answer the prediction question: given a policy , how good is it?
- In Policy Improvement, acting greedily on gave a better policy, and after a few rounds the policy stopped changing. This section takes up the control question: which policy is best ?
Optimal value functions
The optimal value functions are the best values that any policy achieves: is the largest expected return you can get starting from state . is the largest expected return if you start in , take action , and act optimally afterwards. The max in these definitions is over every policy, and there are deterministic policies alone. The Bellman optimality equations replace it with a max over the few actions available in a single state. The next section shows why that is allowed.From policy improvement to optimality
The greedy step connects the two questions. Evaluate a policy to get , then switch to the greedy policy , which takes the action with the largest in every state. The policy improvement theorem (Sutton & Barto, 2018) guarantees that in every state. If you repeat the two steps, the policy keeps improving until the greedy step no longer changes it. At that point is greedy with respect to its own action values. More specifically, evaluate to get its action values . In every state, the action that takes has the largest of these values: The values must come from itself. Every deterministic policy is greedy with respect to some value function, but only a policy that is greedy with respect to its own is optimal. Taking a different action once and then following cannot do better. If it could, that action would have a larger , and the greedy step would have switched to it. The final policy of the Policy Improvement example, , shows the condition. Its values are , and its action values are:
For example, . In every state the action that takes has the larger value, so the greedy step returns unchanged.
The earlier policy fails the test. Its values are and , so in moving right is worth , more than the 0 of staying. That is why round 2 of the example switches to right.
Every policy satisfies the Bellman expectation equation for the state value,
For this deterministic policy, for the action and for every other action. The sum keeps only the term , which is the largest action value in state :
A stochastic policy can satisfy the same equation. If spreads its probability only over actions that tie for the largest , the weighted sum still equals the max. If it gives any probability to an action with a smaller value, the sum falls below the max, and the greedy step improves the policy. So an optimal policy can be stochastic only by splitting its probability among equally good actions, and a deterministic optimal policy always exists.
This is the Bellman optimality equation. Its solution is . So the Bellman optimality equation is the Bellman expectation equation of a policy that is greedy with respect to its own action values.
Compare the equation with the definition of in Optimal value functions:
The first max runs over whole policies, which choose an action in every state. The second runs over the few actions in state . They are equal because the action taken in only affects what happens from onward, and already assumes the best choices in every later state. So an optimal policy can be built one state at a time, by taking the action with the largest in each state.
The max over actions as a backup tree
The figure draws the equation from the previous paragraph as a backup tree. The prediction tree for from Bellman Expectation Backup is drawn on the left for comparison.Code
Code
The Bellman optimality equations
Substituting each of the two equations into the other gives the Bellman optimality equations:A worked example
Suppose a backup at state sees two actions, with action values 1 and 3. The prediction backup for the uniform random policy averages them, . The control backup takes the better one, , and records that the second action is the one to take. Repeating the control backup in every state until the values stop changing is value iteration. The DP gridworld demo shows the same difference on a whole grid. Its policy evaluation button runs the prediction backup for the current policy, and its value iteration button runs the control backup.Reading off the optimal policy
Once you know , an optimal policy takes the best action in each state: This needs no model of the environment. If you only have , you need one more step of lookahead through the model, .Solving the equations
The max makes the optimality equations nonlinear, so they have no closed-form solution like the linear system of policy evaluation. When the model is known, dynamic programming solves them iteratively. Policy Iteration alternates policy evaluation with greedy improvement, and Value Iteration applies the optimality backup directly. Both reuse the values of successor states instead of recomputing them, which is the idea behind dynamic programming. Without a model, Q-learning estimates from sampled transitions.References
- Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link
- (2020). Markov Decision Processes 1 - Value Iteration | Stanford CS221: AI (Autumn 2019). Link
Found an error on this page? Report an issue.

