Value Functions and Optimality
A value function scores how good a state (or state–action pair) is under a policy: the expected return from there onward. Its defining property is the Bellman equation, a self-consistency condition linking a state's value to its successors' values, which we derive from the return and the dynamics.
╌╌╌╌
A Markov decision process
gives us the machinery of interaction — states, actions, rewards, the dynamics
— and the return that an agent tries
to maximize. What it does not yet give us is a way to act. To choose well an
agent needs to know, before it moves, how good its situation is; and how good
can only mean one thing here — how much return it can expect from here on. That
number, attached to every state, is a value function, and almost every
reinforcement-learning algorithm is a scheme for estimating one.1
Value is always relative to a way of behaving. A policy is a mapping from states to probabilities over actions: is the probability of taking action when in state . (The bar is ordinary conditioning notation; is a distribution over for each .) A different policy makes different states good. So a value function is defined with respect to a policy, and a change of policy changes the values.
Two value functions
The state-value function for policy , written , is the expected return when the agent starts in and follows thereafter:
Here is the expected value of a random variable given that the agent follows , and is any time step (the definition does not depend on which one, because the process is stationary). The value of a terminal state, if there is one, is always zero.
Alongside it we define the action-value function for , written : the expected return from starting in , taking action now, and following afterward.
The difference is one committed first action. averages over the action would choose; pins the first action to and only then defers to . The two are tied together by that averaging in both directions,
In words: a state's value is the policy-weighted average of its action-values, and an action's value is the immediate reward plus the discounted value of the state it leads to. These two relations lead directly to the Bellman equation.
These functions are not given; they are estimated. If an agent follows and, for each state it meets, averages the actual returns that followed, those averages converge to as the state is visited more and more often — the idea behind Monte Carlo methods. Keep separate averages per action and they converge to . But raw averaging ignores a structural fact about these functions that makes them far cheaper to compute: they are recursive.
The Bellman equation
The intuition: a state's value equals the expected reward on the next step plus the discounted value of the next state. The derivation below carries that idea through the expectation carefully.
The returns at successive time steps are related — — and that single algebraic fact propagates all the way up into the value function, turning a definition into a recursion. Take the definition of and unfold it.
Read the middle line as an explicit expectation over three random variables. To be in and act under is to draw an action with probability , then draw a next-state–reward pair with probability . For each such triple the quantity in brackets is what you collect — the immediate reward plus the discounted value of the successor — and the sums weight each possibility by how likely it is. The last line merges the two inner sums (over and over ) into one sum over all pairs, a compaction we will use constantly. The inner expectation is — the same function we started with, evaluated at the successor. That coincidence is what makes the equation a recursion rather than a definition.
The equation is a consistency condition: it says the value assigned to and the values assigned to 's possible successors cannot be set independently — looking one step ahead and averaging must reproduce the value we started with.
A picture like this is a backup diagram. Each open circle is a state, each solid dot a state–action pair. Starting from the root at the top, the branches to the solid dots are the actions the policy might select; from each dot the branches to the next open circles are the responses the environment might make, each labelled by its reward and successor . The name is literal: these diagrams show value information being backed up, transferred back to a state (or state–action pair) from its successors. The Bellman equation averages over one full level of this tree, nothing more. Note that, unlike a transition graph, the nodes need not be distinct states — a state can be its own successor.
The action-value function has its own backup and its own Bellman equation, rooted at a state–action pair instead of a state. From the environment first branches on ; from each successor the policy then branches on the next action , and satisfies
The two Bellman equations are the same self-consistency read from two roots. Their central property, proved in later chapters, is uniqueness: for a finite MDP the equation for has exactly one solution, so the consistency condition alone determines the value function.
Solving the Bellman equations on a 3-state MDP
The Bellman equation is a linear system in the unknowns , so for a small MDP we can solve it by hand and watch the values fall out. Take three states and . In the policy is a coin flip between two actions: action moves to for reward , action moves to for reward . States and each have a single action: returns to for reward , and returns to for reward .
Write out the Bellman equation for each state. The transitions are deterministic, so the inner sum collapses to one term per action:
Substitute the last two into the first. With and ,
so and . Back-substitute: and . Every equation now checks — for instance .
That last line also exposes the action-values hidden in the average: and . The state value is exactly their equiprobable average, as requires. Action is the better of the two (), which foreshadows the next section: an optimal policy would drop the coin flip and always take . Doing so (and re-solving with a in place of the average) gives the larger optimal values , , — the payoff of never averaging in the inferior action.
Gridworld: a value function you can read
Consider a grid. In each cell the agent may go north, south, east, or west; each move is deterministic and shifts the agent one cell. An action that would leave the grid instead keeps the agent in place and pays reward . All other moves pay — with two exceptions. From the special cell , every action pays and teleports the agent to ; from the special cell , every action pays and teleports it to .2
Now fix the policy to be uniformly random — each of the four actions with probability everywhere — and discount at . Solving the linear Bellman equations (one per state, unknowns) gives the value function below.
Two features carry the whole intuition. State is the best state under this policy, yet its value () is less than its immediate reward of : taking any action sends the agent to in the bottom row, from which the random policy is likely to run into the edge and lose reward. State , worth , is valued above its immediate reward of : it sends the agent to , which sits in safer interior territory, so the expected penalty from future edge-collisions is more than offset by the guaranteed gain of landing in or . The negative values along the border are the accumulated cost of a policy that keeps blundering into walls. Every one of these numbers satisfies the Bellman equation exactly: the center cell's value equals the average of times its four neighbors' values.
Optimal policies and optimal value functions
Solving a reinforcement-learning task means, roughly, finding a policy that earns a lot of reward over the long run. Value functions let us make this precise. They induce a partial order on policies: iff for all states . A policy that beats or ties every other policy in every state is an optimal policy. For a finite MDP at least one always exists (there may be several); they all share the same state-value function, the optimal state-value function :
Optimal policies also share the same optimal action-value function :
For a state–action pair, is the expected return from taking in and thereafter following an optimal policy. So can be written in terms of :
The Bellman optimality equations
The one change from before is this: an optimal agent does not average over its actions — it takes the best one. So wherever the ordinary Bellman equation averaged over the policy's action choices, the optimality equation puts a . Everything else is the same.
Because is the value function for a policy, it must satisfy the Bellman equation. But because it is the value function for an optimal policy, its self-consistency condition takes a special form that mentions no policy at all. Under an optimal policy the value of a state must equal the expected return of the single best action available there — not a policy-weighted average, but a maximum:
The last line is the Bellman optimality equation for . The only change from the Bellman equation for is that the outer has become a : an optimal agent does not average over its actions, it takes the best one. The corresponding equation for the action-value function is
where the max now sits inside, at the successor: after the environment responds, the optimal agent again picks the best next action.
Their backup diagrams are the same trees as before, with one addition: an arc across the branches at the choice point marks that the , not an average, is taken there. In the diagram the arc sits at the agent's action choice; in the diagram it sits at the successor state's action choice.
Why the optimal value function is enough
The payoff of is that it collapses a hard long-term problem into an easy short-term one. Once you have , an optimal policy falls out almost for free. For each state, there is at least one action that attains the max in the Bellman optimality equation; any policy that puts all its probability on such actions is optimal. That is, any policy greedy with respect to is an optimal policy.
The word greedy usually carries a warning in computer science: a greedy procedure chooses by immediate appeal and can miss a better path that requires short-term sacrifice. With the warning does not apply. Because already folds the full discounted consequences of all future behavior into a single number per state, acting greedily on it — a one-step lookahead, no deeper — is optimal in the full long-term sense. The long-run optimization has been baked into the values in advance; the runtime search is one step deep.
With it is easier still — no lookahead at all. For any state the agent simply picks any maximizing . The action-value function has cached the result of the one-step search into each state–action pair, so an optimal action can be chosen with no model of the environment: no need to know the successor states, their values, or the dynamics . This is the practical appeal of learning rather than , and it is the basis of Q-learning.
Why we cannot just solve it
If the Bellman optimality equation hands us an optimal policy, why is the rest of the course not a single chapter on solving it? Because for the tasks we care about, solving it directly is out of reach. The equation for is a system of nonlinear equations in unknowns; in principle, if the dynamics are known, one can solve it with any method for systems of nonlinear equations. In practice that route is rarely useful, because it leans on three assumptions that are seldom all true at once:3
- The dynamics are known. Explicitly solving needs for every transition. An agent learning from interaction usually does not have this model; discovering it is part of the problem.
- The computation is affordable. The solution is akin to an exhaustive lookahead over all possibilities. Backgammon has about states; even granting a perfect model, solving its Bellman equation would take a present-day computer thousands of years. Chess, Go, and any real control problem are worse.
- The Markov property holds. The equation is exact only if the state summarizes everything relevant about the past — which real sensory streams rarely satisfy exactly.
Board games such as chess are a vanishing fraction of human experience, yet the largest custom computers still cannot compute their optimal moves. So the sharp notion of optimality is best read as a reference point — it organizes the theory and lets us reason about how good an algorithm's answers are — not as a target we expect to hit.
Optimality and approximation
Because exact optimality is out of reach, reinforcement learning settles for approximating it — and the two constraints that force the compromise are computation and memory. In small, finite tasks the value function can be stored as an array or table with one entry per state (or per state–action pair). This is the tabular case, and its methods — the subject of the next several lessons — are the tabular methods. When the state set is astronomically larger than any table, the value function itself must be approximated by a compact parameterized function, the topic of the later chapters on function approximation.
Approximation is not purely a concession; it also has a benefit: an agent that meets some states with vanishingly low probability can afford to make poor decisions there, since those states barely touch its total reward. A backgammon player of the caliber of TD-Gammon plays with great skill overall while very possibly misjudging board positions that never arise between experts. The online nature of reinforcement learning lets an agent spend its limited approximation effort on the states it actually encounters often, at the expense of the ones it rarely sees — a bias that distinguishes it from generic schemes for approximately solving MDPs.
This reframing is what the rest of the course elaborates. Many decision-making methods can be read as ways of approximately solving the Bellman optimality equation. Dynamic programming sweeps a known model and turns the optimality equations directly into update rules; Monte Carlo and temporal-difference learning drop the model and use sampled transitions in place of the expected ones. Every one of them is a different way of enforcing the self-consistency condition derived here.
Value functions in deep RL
The Bellman optimality equation is not only a theoretical reference point; its sampled, function-approximated form is what runs inside the systems that made RL famous. Two lines descend directly from the equations of this lesson.
The line turns pick
into an algorithm.
Watkins' Q-learning (1989) updates a tabular estimate toward the
Bellman-optimality target from sampled
transitions, and converges to without a model.4 Replace the
table with a deep network and you get the Deep Q-Network of
Mnih et al. (2015), which learned to play Atari games from raw pixels at or
above human level, using a single architecture and one set of
hyperparameters.5 The two tricks that made the network stable — a slowly
updated target network supplying the term, and a replay
buffer of past transitions — are both patches on the plain Bellman update, which
diverges when the same rapidly-changing network appears on both sides of the
equation. That instability has a name in the next module: the deadly triad of
function approximation, bootstrapping, and off-policy learning together.
The line powers the model-based game players. Tesauro's TD-Gammon (1994) — named earlier in this lesson — trained a neural value function by temporal-difference learning against itself and reached championship backgammon, the first demonstration that approximate value functions scale.6 Silver et al.'s AlphaGo (2016) and its successor AlphaZero (2018) combined a learned value network with Monte-Carlo tree search, using the value estimate to prune a lookahead far shallower than the -over-everything the exact Bellman equation would demand, and defeated the world's strongest Go players.7 These systems are the practical answer to this lesson's closing worry: the state spaces ( for Go) are far past any table, so is approximated by a network and the one-step greedy-in- ideal is replaced by a few-step search on the approximation — the online, encounter-weighted approximation this lesson argued for.
Footnotes
- Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), §3.5 — Policies and Value Functions: the state-value (3.12) and action-value (3.13) as expected returns under a policy, and the Bellman equation (3.14) as the recursive consistency condition they satisfy. ↩
- Sutton & Barto, §3.5, Example 3.5 (Gridworld): the grid with special cells , the equiprobable random policy at , and its state-value function computed by solving the linear system (3.14). ↩
- Sutton & Barto, §3.6–§3.7 — Optimal Value Functions; Optimality and Approximation: the Bellman optimality equations (3.19)–(3.20), greedy policies with respect to and , the three assumptions that make direct solution infeasible, and the tabular-versus-approximate distinction. ↩
- Watkins, C. J. C. H. (1989), Learning from Delayed Rewards, PhD thesis, University of Cambridge; and Watkins, C. J. C. H. & Dayan, P. (1992),
Q-learning
, Machine Learning 8, 279–292 — the Q-learning update toward the Bellman-optimality target and its proof of convergence to in the tabular case. ↩ - Mnih, V. et al. (2015),
Human-level control through deep reinforcement learning
, Nature 518, 529–533 — the Deep Q-Network, reaching human-level play on 49 Atari 2600 games from raw pixels, stabilized by experience replay and a periodically-updated target network. ↩ - Tesauro, G. (1994),
TD-Gammon, a self-teaching backgammon program, achieves master-level play
, Neural Computation 6(2), 215–219 — a neural value function trained by TD learning through self-play to near-championship backgammon, the early proof that approximate value functions scale. ↩ - Silver, D. et al. (2016),
Mastering the game of Go with deep neural networks and tree search
, Nature 529, 484–489; and Silver, D. et al. (2018),A general reinforcement learning algorithm that masters chess, shogi, and Go through self-play
, Science 362(6419), 1140–1144 (AlphaZero) — learned value (and policy) networks combined with Monte-Carlo tree search, defeating top human Go players and superseding hand-crafted engines in chess and shogi. ↩
╌╌ END ╌╌