Value Function Methods
What if we drop the actor entirely? Levine shows that an arg max over the advantage is itself a policy — at least as good as whatever policy produced the advantage — and builds the whole value-based family from it: policy iteration, value iteration, fitted Q iteration, and online Q-learning. The lecture ends with the honest theory: with neural networks these methods are not gradient descent and are not guaranteed to converge, because a Bellman backup followed by a projection is not a contraction.
Can we skip learning a policy entirely?
Actor-critic, as covered last lecture, still carries a policy network: sample from the current policy, fit a value function , form advantage estimates , and push them through the policy gradient. The question that opens this lecture: “can we maybe omit the policy gradient entirely?” The value function already tells us which states are better than which other states — so just select the actions that lead to the better states.
The formal version runs through the advantage. measures how much better is than the average action the policy would have taken. Then is the best action available from if you follow thereafter.
This slots into the usual three-box anatomy with one box gutted: the orange box still generates samples and the green box fits or , but the blue box no longer does any learning — it just sets the policy to the arg max. Alternating the two steps — evaluate , then set — is policy iteration. Step two is trivial with discrete actions (check every action’s advantage); continuous actions wait for the next lecture. The whole puzzle is step one: how do you evaluate ? It suffices to evaluate .
Dynamic programming when you know everything
Suspend the model-free setting for a moment: assume known transition probabilities and state and action spaces small enough to enumerate — a grid world with 16 states and 4 actions is the mental picture. Then is literally a table of 16 numbers and the transitions are a tensor; this is what “tabular RL” means. The bootstrapped update from lecture 6 can now be computed exactly, expectations and all:
using the current table entry for . And since the arg max policy is deterministic, the outer expectation collapses:
Repeating this recursion is policy evaluation; it provably converges to a fixed point, which is the true . (Levine’s aside for the mathematically inclined: the fixed-point condition is a system of linear equations in the table entries, solvable directly with any linear solver — “a good exercise to make sure that you really understand dynamic programming.”)
Policy iteration can then be short-circuited. Since subtracting — a term that doesn’t depend on the action — can’t change an arg max over actions, . Picture the Q-function as a table with a row per state and a column per action: the arg max finds the biggest entry in each row (the policy), and evaluating that policy just plugs the index back in to read off the same entry (the value). So skip the indices and take the values directly. That is value iteration:
No explicit policy ever appears — it lives implicitly inside the max. Plug step two into step one and you don’t even need to store : only the Q-table remains.
Neural networks and fitted value iteration
Why not always use a table?
So represent with a neural network and fit it the way lecture 6 fit the critic — least-squares regression onto target values. Using the value-iteration targets gives fitted value iteration:
A reasonable algorithm — but step one still requires the dynamics, in two ways: the expectation over , and, “perhaps more importantly,” evaluating the max requires trying every action from the same state, which you cannot do by running policies in the world unless you can teleport back to a state and try again.
Trading V for Q makes it model-free
Return to policy iteration and write the policy-evaluation recurrence for the Q-function instead of the value function:
The change looks cosmetic but is “a very very important one”: the distribution being sampled is conditioned on the tuple you already have, so as changes, the samples you need do not. The policy appears in exactly one place — as an argument to the Q-function at — not in the simulator. Any bucket of transitions, collected by any policy, can fit for every . “This is the basis of most value-based model-free RL algorithms.”
Applying the max trick to this recurrence gives the workhorse of the lecture.
What is this optimizing? Step three minimizes the Bellman error — the squared difference between and the targets. If that error is driven to zero, then , which is an optimal Q-function corresponding to the optimal policy. In the tabular case the error does go to zero and you recover . If it is not zero, “most guarantees are lost when we leave the tabular case.”
Online Q-learning and exploration
Set the hyperparameters to their smallest values — one transition, one target, one gradient step — and fitted Q iteration becomes classic online Q-learning (Watkins): take an action, observe , compute , then
where the parenthesized quantity is the temporal difference error. It is off-policy: the action in step one need not come from the latest greedy policy. And it had better not, at least not exactly. The greedy arg max policy is deterministic, and if the initial Q-function is bad — not random, arbitrary — it will commit to the same poor action every time it enters a state, potentially “in perpetuity,” never discovering that better actions exist. So inject randomness:
- Epsilon-greedy: take the greedy action with probability , and each other action with probability . Simple, ubiquitous, and what you implement in homework 3; a common refinement anneals from large (bad early Q-function) to small (trustworthy late Q-function).
- Boltzmann (softmax) exploration: . Two advantages over epsilon-greedy: two nearly-equal actions get nearly-equal probability instead of one hogging the greedy mass, and an action already known to be terrible is almost never wasted exploration.
More sophisticated exploration gets its own lectures in the second half of the course.
The sad theory: why none of this converges with neural nets
Does value iteration converge, and to what? Define the Bellman operator on the value table (a vector with one entry per state):
— the value function of the optimal policy, satisfying — is a fixed point of , and it always exists, is always unique, and always yields the optimal policy through the arg max. So the question is whether the fixed point iteration reaches it.
Fitted value iteration adds a second operator. Supervised learning searches a hypothesis set — all neural nets of your architecture — for the element closest to the targets, and since the targets are exactly , step two is a projection: . Fitted value iteration in one line is . Geometrically: steps off the manifold of representable functions, and drops it back down at a right angle, in the norm. is itself a contraction in — projecting two points onto a line can only bring them closer.
So: value iteration converges in the tabular case; fitted value iteration does not converge in general — and often doesn’t in practice. The same story holds verbatim for fitted Q iteration ( with the max moved after the transition operator), for online Q-learning, and — a sad corollary — for the actor-critic value fitting of last lecture, which also composes a bootstrap backup with a projection.
One seeming contradiction remains: step three looks like regression, and regression converges — isn’t this just gradient descent? No. “Q-learning is not actually gradient descent”: the target values themselves depend on , but no gradient flows through them, so the update is not the gradient of any well-defined objective. You could differentiate through the targets — the result is the residual algorithm, which is guaranteed to converge but has such poor numerical properties that plain, unguaranteed Q-learning “tends to work much much better” in practice. The next lecture is about making it work.
Check yourself
Derivation and calculation exercises in the lecture’s spirit — work them on paper.
Levine notes that tabular policy evaluation is really a system of linear equations. Take a two-state MDP with a deterministic policy : from the policy’s action moves to with probability 1 and earns reward 0; from it stays in with probability 1 and earns reward 1. With , write the fixed-point equations , solve them exactly, and confirm that repeated application of the bootstrapped update converges to the same answer from .
Show solution
The equations are and . The second gives ; substituting gives . In matrix form this is with and , solvable by any linear solver. Starting the recursion from : after one sweep , then , then , …; each sweep adds -scaled corrections, and the iterates converge geometrically to — exactly the contraction-by- behavior of the Bellman backup, here for a fixed policy.
Show that the implicit policy that puts probability 1 on satisfies for every state, computing the right-hand side explicitly. Why does the argument make no assumption about the quality of ?
Show solution
First the right-hand side: , since is by definition the expectation of under the policy’s own action distribution. The left-hand side is , and a maximum is always at least the mean: . So the greedy action is at least as good, in advantage terms, as the average action takes — with equality only when already concentrates on maximizing actions. Nothing in the chain used any property of beyond the definitions of , , and ; that is why even an arbitrary random policy improves under the arg max construction, which is the engine of policy iteration.
Consider the two policy-evaluation recurrences from the lecture: and . You have a fixed buffer of transitions collected by an old policy, and keeps changing as policy iteration proceeds. Which recurrence can you keep fitting from the buffer without collecting new data, and exactly why does the other one fail?
Show solution
The Q recurrence works. Its sampling distribution is conditioned on the stored pair, which is fixed data — when changes, the distribution the stored were drawn from does not change, so the samples remain valid forever. The policy appears only as an argument to the Q-function, , which is a network evaluation, not an environment interaction. The V recurrence fails because sits on the right of the conditioning bar: the expectation is over , so when the policy changes its action at , you need next-state samples for the new action — which requires returning to and trying a different action, impossible without teleportation. This one-symbol difference is why fitted Q iteration is a model-free, off-policy algorithm and is “the basis of most value-based model-free RL algorithms.”
A state has three actions with current Q-values . Compute the action probabilities under epsilon-greedy with and under Boltzmann exploration . Which of Levine’s two arguments for Boltzmann over epsilon-greedy do the numbers illustrate?
Show solution
Epsilon-greedy: the greedy action gets ; the other two split evenly, each. So . Boltzmann: , , ; the sum is , giving probabilities . Both of Levine’s arguments appear at once. First, actions 1 and 2 are nearly equally good, and Boltzmann explores them nearly equally ( vs ), while epsilon-greedy gives the marginal winner eighteen times the probability of the runner-up. Second, action 3 is already known to be terrible, and Boltzmann essentially never wastes a sample on it (), while epsilon-greedy insists on trying it a full of the time.
is a contraction with coefficient in the infinity norm, and the projection onto the hypothesis set is a contraction (coefficient 1) in the norm. (a) If both were contractions in the same norm, what could you conclude about fitted value iteration ? (b) Explain, via the lecture’s geometric picture, how the composition can nonetheless move further from . (c) What does this imply about the actor-critic algorithm of lecture 6?
Show solution
(a) Contraction coefficients compose multiplicatively within a single norm: . The composition would be a -contraction, would have a unique fixed point, and fitted value iteration would converge to it — the tabular convergence argument would go through. (b) The guarantees live in different geometries. The backup shrinks the largest per-state gap to ; the projection then moves the point back onto along the shortest Euclidean path — but “as close as possible in ” to can be far from in either norm. In the lecture’s picture, steps toward the star, off the line representing , and the right-angle projection lands at a point on the line further from the star than was; iterating can drift away indefinitely. Neither step ever violates its own contraction property. (c) The critic update in actor-critic is exactly a bootstrap backup followed by an regression — the same composition — so fitted bootstrapped policy evaluation inherits the same failure: it is not guaranteed to converge with function approximation either.