RL Theory (UC Berkeley CS 285)

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.

Measure the error against the bound

100
0.90

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

What Theory Can Promise

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.

Two questions that sound alike

QuestionWhat 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.

The assumption: oracle exploration

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̂.

Draw N next states for one pair

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.

  1. One matrix inverse: Q-pi for all pairs at once, and the horizon 1/(1 − γ).
  2. Contraction and its norm: why value iteration settles and fitted value iteration can run away.
  3. Concentration: error falls as one over root N.
  4. The simulation lemma: the hero's bound, and the 2ε greedy gap.
  5. Fitted Q-iteration: sampling error plus fitting error, times the horizon.
  6. The field guide: terms, numbers, code and the credit.
Which quantity tells you how well you will do if you act with the greedy policy of your estimate?

Chapter 1

Policy Evaluation Is One Matrix Inverse

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.

ObjectShapeEntry
r|S||A| = 10the reward r(s,a) of each pair
P|S||A| × |S| = 10 × 5the chance of next state s′ after (s,a)
Π|S| × |S||A| = 5 × 10the policy: π(a|s) in row s
Pπ = PΠ10 × 10the 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.

Say it aloud

Q-pi equals the inverse of I minus gamma P-pi, times r.

Qπ
Q-pi the value of each of the 10 pairs under policy π.
( )−1
the inverse of the matrix that undoes the one inside.
I
I the identity matrix, 10 × 10.
γ
gamma the discount, 0.9 here.
Pπ
P-pi the pair-to-pair transition matrix, P times Π.
r
r the reward of each pair.
In plain words

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 numbers

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.

Say it aloud

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.

‖ ‖∞
the infinity norm the largest absolute entry of a vector.
‖ ‖∞
the infinity norm the same norm, closing the bracket.
(I − γPπ)−1
the evaluation operator turns a per-step quantity into a discounted total.
v
v any vector with one entry per pair.
1/(1 − γ)
over one minus gamma the horizon: 10 at gamma 0.9.
In plain words

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.

With numbers

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.

Look inside the evaluation operator

Left: the 10 × 10 matrix (I − γPπ)−1, darker for larger entries. Right: Q-pi under the purple cap. Drag gamma toward 1.

0.90

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.

At gamma 0.95, every entry of a per-step error vector v is at most 0.02 in size. What is the most it can add to Q after the evaluation operator?

Chapter 2

Contraction Depends on the Norm

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.

Say it aloud

The infinity norm of T-V minus T-U is at most gamma times the infinity norm of V minus U.

TV, TU
T-V, T-U one backup of each guess: max over a of r + γPV.
γ
gamma the discount, below 1.
‖V − U‖∞
the infinity norm of V minus U the largest gap between two value guesses.
In plain words

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*.

With numbers

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.

Say it aloud

w at k plus one equals six gamma over five, times w at k.

wk
w-k the network's one weight after k steps. The values are (w, 2w).
6γ/5
six gamma over five the growth per step. Above 1 when gamma is above 5/6.
wk+1
w at k plus one the weight after one more backup and fit.
In plain words

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).

With numbers

At gamma 0.9 the factor is 1.08. From w = 1, fifty steps give w = 1.0850 = 46.9. The truth is 0.

Back up, then project

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.

0.90
0.50

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.

Why can fitted value iteration diverge when value iteration cannot?

Chapter 3

Concentration: Error Falls as One Over Root N

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.

Say it aloud

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.

P( )
the chance that over the random draw of the n samples.
X̄n
X-bar-n the average of n independent samples.
μ
mu the true mean.
ε
epsilon the size of miss you care about.
exp
e to the the exponential: it falls fast as n grows.
b+, b−
b-plus, b-minus the largest and smallest value a sample can take: 1 and 0 here.
In plain words

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.

With numbers

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.

Count the misses

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 ε.

100
0.10

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.

Say it aloud

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.

‖ ‖1
the L1 norm the sum of absolute gaps over next states.
P̂ − P
P-hat minus P counted chances minus true chances for one pair (s, a).
c
c a constant from the proof.
|S|
size of S the number of states, 5 here.
δ
delta the chance that the bound fails.
N
N the samples drawn for this pair.
In plain words

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.

With numbers

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.

An estimate has error 0.2 with 100 samples, and its error falls as one over root N. About how many samples give error 0.05?

Chapter 4

The Simulation Lemma: Error Grows With the Horizon Squared

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.

Say it aloud

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.

Qπ − Q̂π
Q-pi minus Q-hat-pi the error in each of the 10 pairs.
γ
gamma the discount.
(I − γP̂π)−1
the evaluation operator of the model adds a per-step error over the horizon.
P − P̂
P minus P-hat the gap in next-state chances, 10 × 5.
Vπ
V-pi the true value of each of the 5 states.
In plain words

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.

With numbers

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.

The derivation, in four steps
  1. Start from Qπ − (I − γP̂π)−1r.
  2. Write Qπ as (I − γP̂π)−1(I − γP̂π)Qπ, and r as (I − γPπ)Qπ.
  3. Take out the common inverse. The two I's cancel.

    = γ(I − γP̂π)−1(Pπ − P̂π)Qπ

  4. Pπ = PΠ and ΠQπ = Vπ, so (Pπ − P̂π)Qπ = (P − P̂)Vπ.

Bound each factor with the tools of Chapters 1 and 3 and the hero's line appears.

Say it aloud

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.

‖Qπ − Q̂π‖∞
the infinity norm of the error the worst pair's error.
γ/(1 − γ)²
gamma over one minus gamma, squared one horizon from V-pi, one from the operator.
c√( )
c root of size-of-S log one over delta over N the L1 gap of Chapter 3.
In plain words

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 − δ.

With numbers

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.

Grow the horizon

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.

Gamma moves from 0.9 to 0.99 with the same data. By what factor does the bound's horizon term γ/(1 − γ)² grow?

Chapter 5

Fitted Q-Iteration: Two Errors, Times the Horizon

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.

ErrorWhere it comes fromWhat shrinks it
Sampling: T̂ ≠ Ttargets from finite datamore data, as one over root N
Approximation: Q̂k+1 ≠ T̂Q̂kthe fit misses its targetsa 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?

Say it aloud

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.

‖Q̂k − Q*‖∞
the error at round k the worst pair's gap to the best Q-function.
εk−1
epsilon k minus one the miss made in the round that produced Q̂k.
γ
gamma the contraction factor of T.
‖Q̂k−1 − Q*‖∞
the error at round k minus one last round's gap.
In plain words

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 numbers

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.

Say it aloud

The limit, as k goes to infinity, of the error is at most the max over k of epsilon-k, over one minus gamma.

limk→∞
the limit as k goes to infinity of where the error settles after many rounds.
maxk εk
the max over k of epsilon-k the largest miss of any round.
1/(1 − γ)
over one minus gamma the horizon.
In plain words

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.

With numbers

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.

Miss a little every round

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.

0.05
0.90

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.

Each FQI round misses its target by at most 0.02 in every pair, and gamma is 0.98. What does the bound say the error settles below?

Chapter 6

The Field Guide

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 resultValueWhere
Horizon 1/(1 − γ)10 at 0.9, 100 at 0.99; each row of the evaluation operator sums to itCh 1
Contraction of Tgap × γ per sweep; 10 → 0.052 in 50 sweeps at 0.9Ch 2
Two-state fitted divergencew × 6γ/5 per step; diverges above γ = 5/6Ch 2
Hoeffding miss0.136 at n = 100, δ = 0.05; half the miss needs 4× dataCh 3
L1 model gap0.703 at |S| = 5, N = 100, δ = 0.1 over 10 pairsCh 3
Simulation bound factorγ/(1 − γ)²: 90 at 0.9, 9,900 at 0.99Ch 4
Greedy policy gapat most 2εCh 4
FQI limitmax εk/(1 − γ): 0.05 → 0.5 at 0.9Ch 5

Checks before you trust a value

The core in code

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()

Keep going

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.

Credit and source

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.

RL Theory (UC Berkeley CS 285)
The course page · Lecture 20 slides · RL theory book · Back to Gleams