With 100 samples per state and action at gamma 0.9, theory promises an error in Q of at most 63. The measured error is near 0.1. The promise is loose, but its shape is right: one over root N, times the horizon squared.
Learn what RL theory can prove: why value iteration settles, how error falls with data, and how it grows with the horizon.
Drag the samples per pair N, then the discount gamma. Each warm dot is one model built from N samples. The purple line is the bound. Then we build, piece by piece, the matrix view, contraction, concentration, the simulation lemma and fitted Q-iteration.
You need the Bellman equation and value iteration (Deep RL theory, Chapter 1) and matrix times vector. We build the rest from zero.
A supplement to UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026). It follows Lecture 20, RL theory (PDF), which builds on the RL theory book by Agarwal, Jiang, Kakade and Sun, plus Lecture 8 (PDF) and Lecture 22 (PDF). The words, toys and numbers here are our own.
Illustrative toy: 5 states, 2 actions, a fixed policy, rewards in [0, 1]. Each model counts N draws from the true dynamics for every pair. The bound is Lecture 20's result with our constants: γ/(1−γ)² × √(|S|/N)(1 + √log(|S||A|/δ)), δ = 0.1.
Chapter 0
Ask how much data buys how much accuracy, and see the assumption that makes the question answerable
You fit a Q-function from 100 transitions for each state and action. It is off by some amount. You want half that error. Do you collect 200 transitions, or 400?
RL theory answers questions of that shape. It cannot prove that a deep RL run works; most deep methods do not even have a convergence guarantee. It gives rough rules: how error scales with data and with the discount. The course calls theory at best a rough guide, under strong assumptions.
| Question | What it measures |
|---|---|
| How far is the estimate Q̂k from Q*? | the error of the numbers you hold |
| How good is the greedy policy πk of Q̂k? | the gap between Qπk, its true value, and Q* |
Q* is the best possible Q-function. Chapter 4 links the two rows: the greedy policy loses at most twice the estimate's error.
In the worst case, exploration is the hard part. So theory often removes it. Under oracle exploration, for every state s and action a you draw N next states from the true dynamics P(s′|s,a). Counts divided by N give an empirical model P̂.
Teal outlines are the true chances of each next state. Warm bars are counts over N. Pick N and draw again.
Illustrative pair: state 3, action "right" of the hero's toy. True chances 0.2, 0, 0, 0.2 and 0.6.
At N = 10 the counts wander far from the truth. At N = 1000 they sit close. Chapter 3 says how close, and Chapter 4 says what the gap does to Q.
The failure. A real agent does not get N samples of every pair. It visits some pairs often and others never. Measure the visit count of each pair in your data. The smallest count, not the average, decides what any guarantee can say.
Chapter 1
Write Q-pi for every pair at once, read each matrix by its shape, and find the horizon inside the inverse
The hero's toy has 5 states and 2 actions, so 10 pairs. Stack the 10 Q-values into one vector. The Bellman equation for a fixed policy π then becomes linear algebra.
| Object | Shape | Entry |
|---|---|---|
| r | |S||A| = 10 | the reward r(s,a) of each pair |
| P | |S||A| × |S| = 10 × 5 | the chance of next state s′ after (s,a) |
| Π | |S| × |S||A| = 5 × 10 | the policy: π(a|s) in row s |
| Pπ = PΠ | 10 × 10 | the chance of next pair (s′,a′) after (s,a) |
The Bellman equation for π reads Qπ = r + γPπQπ. Move the Qπ terms to one side and solve.
Q-pi equals the inverse of I minus gamma P-pi, times r.
Build P-pi from the dynamics and the policy. Subtract gamma times P-pi from I, invert, and multiply by r. Policy evaluation is one linear solve.
With made-up numbers: two states, one action each. State 1 pays 1 and moves to either state with chance 0.5. State 2 pays 0 and stays. At gamma 0.9, Q = (1/(1 − 0.45), 0) = (1.82, 0).
How much can that inverse grow a vector? Feed it any vector v, one entry per pair, as if it were a reward.
The infinity norm of the inverse of I minus gamma P-pi, times v, is at most the infinity norm of v over one minus gamma.
Call the output w, so v = w − gamma P-pi w. P-pi w averages entries of w, so it never beats the largest entry of w. So the largest entry of v is at least (1 − gamma) times that of w.
A reward of 1 in every pair gives Q = 1/(1 − 0.9) = 10 everywhere: the bound, exactly. The two-state toy above reaches only 1.82.
Left: the 10 × 10 matrix (I − γPπ)−1, darker for larger entries. Right: Q-pi under the purple cap. Drag gamma toward 1.
The hero's illustrative toy with its fixed policy. The cap is ‖r‖∞/(1 − γ).
Every row of the operator adds up to exactly 1/(1 − γ). That is the course's horizon-like term: about how many steps of reward a value adds up. It appears twice in Chapter 4.
The failure. As gamma nears 1, the operator magnifies errors. At gamma 0.999 a reward error of 0.01 can become an error of 10 in Q. Check 1/(1 − γ) before you trust a value. The fix is a smaller gamma or a finite horizon.
Chapter 2
See why value iteration settles while fitted value iteration can run away, with two states and one weight
Value iteration settles from any start. Deep RL theory, Chapter 1 proves it. The proof measures distance in the infinity norm: the largest gap over states.
The infinity norm of T-V minus T-U is at most gamma times the infinity norm of V minus U.
Back up both guesses V and U. Their largest gap shrinks by at least gamma. The best values V* do not move under T, so every guess closes in on V*.
A first gap of 10 at gamma 0.9 is at most 10 × 0.950 = 0.052 after 50 sweeps.
A network cannot hold every value function. Fitted value iteration backs up, then projects: Π picks the closest function the network can hold, by least squares. Π is a contraction too, but in the ℓ2 norm, the root of the summed squared gaps. Two contractions in different norms need not make a contraction.
Here is a case where the pair diverges (after Tsitsiklis and Van Roy). Two states, and the network holds only V = (w, 2w). Both states move to state 2 with reward 0, so the true value is 0. The backup gives targets (2γw, 2γw). Fit w′ by least squares with equal weight on the two states.
w at k plus one equals six gamma over five, times w at k.
Both targets are 2-gamma-w-k. Least squares on features 1 and 2 gives w-k+1 = (1 × 2γwk + 2 × 2γwk)/(1 + 4).
At gamma 0.9 the factor is 1.08. From w = 1, fifty steps give w = 1.0850 = 46.9. The truth is 0.
The warm line holds every value the network can make. The blue ring is the backup target. Press Step. Then move the data share on state 1 to 0.
A two-state example in the style of Tsitsiklis and Van Roy (1997), as told in Sutton and Barto, section 11.2. The fit weights the two states by the data share.
Put all the data on state 2, where the policy goes, and the factor drops to γ. The data's distribution decides. This is the deadly triad of Deep RL theory, Chapter 7, in one weight. The course draws a sad corollary: a critic with no max is still a projected backup, so fitted policy evaluation can diverge too.
The failure. Q-values climb without limit while returns stay flat. Compare the largest |Q| with rmax/(1 − γ); above it is impossible. Target networks and replay buffers make it less likely. They do not make it safe.
Chapter 3
Bound how far an average of samples can miss its mean, and turn that into a rule for data
You estimate a mean reward from n samples. Each reward lies between 0 and 1. How far off can the average be, and how often? A concentration inequality answers both.
The chance that X-bar-n misses mu by epsilon or more is at most two e to the minus two n epsilon squared, over b-plus minus b-minus, squared.
Set the right side to a failure chance delta and solve for epsilon. You get epsilon = (b-plus − b-minus) times the root of log(2/δ)/(2n). The miss shrinks as one over root n.
Rewards in [0, 1], n = 100, delta 0.05: epsilon = √(ln 40 / 200) = 0.136. With n = 400, epsilon = 0.068. Half the miss costs four times the samples.
Warm bars are the exact chances of each average of n rewards with mean 0.3. Red marks a miss larger than ε. Drag n and ε.
Illustrative: each reward is 1 with chance 0.3, else 0. The miss chance is exact, from the binomial distribution.
Hoeffding must hold for every distribution in [0, 1], so it covers the worst one. For a distribution over |S| next states, the same idea bounds the L1 distance, the sum of the absolute gaps. This lesson uses that sum with no ½ in front.
The L1 norm of P-hat minus P, at s and a, is at most c times the root of size-of-S times log of one over delta, over N.
Count the next states, divide by N, and add the gaps. The sum grows with the root of the number of states and shrinks as one over root N.
The exact form is √(|S|/N)(1 + √log(1/δ)). With |S| = 5, N = 100, delta 0.1: 0.224 × 2.517 = 0.563.
The failure. Each bound holds with chance 1 − δ for one pair. With 10 pairs, one of them can fail. Use δ divided by the number of pairs inside each bound, the union bound: at N = 100 the 0.563 becomes 0.703.
Chapter 4
Trace a gap in chances through policy evaluation, and get the bound in the hero
Evaluate π inside the empirical model: Q̂π = (I − γP̂π)−1r. How far is it from the true Qπ? The simulation lemma writes the error exactly.
Q-pi minus Q-hat-pi equals gamma, times the inverse of I minus gamma P-hat-pi, times P minus P-hat, times V-pi.
Weight the true values V-pi by the gap in chances P minus P-hat: that is the one-step error. The evaluation operator then adds it up over the horizon.
At N = 100 each row of P − P̂ has L1 gap at most 0.703. V-pi is at most 1/(1 − 0.9) = 10. One step: 0.703 × 10 = 7.03. The operator multiplies by at most 10: 0.9 × 10 × 7.03 = 63.3.
= γ(I − γP̂π)−1(Pπ − P̂π)Qπ
Bound each factor with the tools of Chapters 1 and 3 and the hero's line appears.
The infinity norm of Q-pi minus Q-hat-pi is at most gamma over one minus gamma, squared, times c root of size-of-S log one over delta, over N.
Take the per-pair gap in chances. Multiply by gamma and by the horizon twice. That bounds the worst error in Q-pi, with chance at least 1 − δ.
The horizon factor is 90 at gamma 0.9 and 9,900 at 0.99. To push the toy's bound to 0.1 at gamma 0.9 takes N = 40 million per pair. The hero measures 0.1 near N = 100.
Warm dots are the median error of 50 models at each horizon 1/(1 − γ). Dashed lines grow like the horizon and like its square. Pick N.
Illustrative: the hero's toy and its sampled models. The reference lines start at the first measured point.
In this toy the error grows about like the horizon, not its square. The bound uses ‖Vπ‖∞ in full. But each row of P − P̂ sums to 0, so a constant part of V cancels, and the toy's values are close to each other.
Now plan. Solve for the best Q̂* in the model, act greedily with π̂, and add and subtract Q̂π̂. Each gap is a same-policy error of at most ε:
‖Q* − Qπ̂‖∞ ≤ ‖Q* − Q̂*‖∞ + ‖Q̂π̂ − Qπ̂‖∞ ≤ 2ε
The failure. A long-horizon planner in a learned model chases model errors. The model's Q sits far above real returns. Run the greedy policy in the real system and compare. Shorter horizons and more data on visited pairs help; see model-based RL.
Chapter 5
Split each round's miss into sampling and fitting, and see how the misses add up
Fitted Q-iteration (FQI) builds no model. Each round regresses Q̂k+1 onto targets r + γ maxa′ Q̂k(s′,a′) from the data. Regression averages the transitions of each pair, so it acts like an empirical r̂ and P̂. The course calls that backup T̂, the approximate Bellman operator.
| Error | Where it comes from | What shrinks it |
|---|---|---|
| Sampling: T̂ ≠ T | targets from finite data | more data, as one over root N |
| Approximation: Q̂k+1 ≠ T̂Q̂k | the fit misses its targets | a better function class or fit |
Call round k's total miss εk = ‖Q̂k+1 − TQ̂k‖∞, sampling plus fitting. How does it build up?
The infinity norm of Q-hat-k minus Q-star is at most epsilon k minus one, plus gamma times the infinity norm of Q-hat k minus one minus Q-star.
Add and subtract TQ̂k−1. The first gap is this round's miss. The second is a backup of last round's error, shrunk by gamma, because TQ* = Q*.
With made-up numbers: miss 0.05 per round, gamma 0.9, first error 10. The bound runs 9.05, then 8.20, then 7.43.
The limit, as k goes to infinity, of the error is at most the max over k of epsilon-k, over one minus gamma.
Unroll the line above: each old miss shrinks by gamma per round. They add up to epsilon + gamma epsilon + gamma squared epsilon and on, which is epsilon over one minus gamma. The first error dies away.
A miss of 0.05 gives 0.5 at gamma 0.9 and 5.0 at gamma 0.99. Split 0.05 as 0.02 fitting plus 0.03 sampling: four times the data cuts sampling to 0.015, so 0.35 at gamma 0.9.
Each round backs up the toy's Q-values and adds a miss of size ε. Blue is the error to Q*; purple dashed is ε/(1 − γ). Press Run, then switch the sign.
Illustrative: the hero's toy with the true model, Q̂0 = 0, and a miss of exactly ε in every pair.
Measuring the miss in the infinity norm is a strong assumption, as the course says. A regression lowers the squared error, which can leave one pair far off; Chapter 2 showed where that leads. Sharper results use a weighted p-norm under the data distribution.
The failure. Same data, same network, gamma raised from 0.9 to 0.99: the critic gets up to ten times worse. Measure the held-out regression miss and multiply by 1/(1 − γ). Add data for sampling error, capacity for fitting error, or lower gamma.
Chapter 6
Keep the terms, the numbers, the checks and the code in one place
Every result here is the same three tools. The evaluation operator multiplies by at most the horizon. Backups contract by gamma in the infinity norm. Averages of N samples miss by about one over root N. Combine them and error grows with the horizon and falls with the root of the data.
| Term or result | Value | Where |
|---|---|---|
| Horizon 1/(1 − γ) | 10 at 0.9, 100 at 0.99; each row of the evaluation operator sums to it | Ch 1 |
| Contraction of T | gap × γ per sweep; 10 → 0.052 in 50 sweeps at 0.9 | Ch 2 |
| Two-state fitted divergence | w × 6γ/5 per step; diverges above γ = 5/6 | Ch 2 |
| Hoeffding miss | 0.136 at n = 100, δ = 0.05; half the miss needs 4× data | Ch 3 |
| L1 model gap | 0.703 at |S| = 5, N = 100, δ = 0.1 over 10 pairs | Ch 3 |
| Simulation bound factor | γ/(1 − γ)²: 90 at 0.9, 9,900 at 0.99 | Ch 4 |
| Greedy policy gap | at most 2ε | Ch 4 |
| FQI limit | max εk/(1 − γ): 0.05 → 0.5 at 0.9 | Ch 5 |
pythonimport numpy as np def q_pi(P, r, pi, gamma): # P: [S, A, S] chances, r: [S, A] rewards, pi: [S, A] policy S, A, _ = P.shape Pm = P.reshape(S * A, S) # (|S||A|, |S|) Pi = np.zeros((S, S * A)) # (|S|, |S||A|) for s in range(S): Pi[s, s * A:(s + 1) * A] = pi[s] P_pi = Pm @ Pi # (|S||A|, |S||A|) return np.linalg.solve(np.eye(S * A) - gamma * P_pi, r.reshape(-1)) def empirical_model(P, N, rng): S, A, _ = P.shape # oracle exploration: N draws per pair return np.array([[rng.multinomial(N, P[s, a]) / N for a in range(A)] for s in range(S)]) def simulation_bound(S, A, N, gamma, delta=0.1): l1 = np.sqrt(S / N) * (1 + np.sqrt(np.log(S * A / delta))) # union over pairs return gamma / (1 - gamma) ** 2 * l1 # S=5, A=2, N=100, 0.9 -> 63.3 # measured error of one model: np.abs(q_pi(P, r, pi, g) - q_pi(P_hat, r, pi, g)).max()
Now press Present or Teach and derive from memory: the resolvent bound, the simulation lemma and the FQI limit. Then go back to the hero, set N to 1000, and predict the bound before you look.
This supplement follows UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026): the course page, Lecture 20 on RL theory, Lecture 8 on fitted value methods, Lecture 22, the review, and Lecture 4 on MDPs. Lecture 20 credits the RL theory book by Agarwal, Jiang, Kakade and Sun, and slides by Aviral Kumar. The words, toys and numbers here are our own.