Optimism in MDPs: UCRL2 & UCBVI
Confidence sets over models and values, and the regret of exploring a whole MDP.
In a bandit, an optimistic guess costs one pull to test. In an MDP, testing it may require a long walk through states never visited, and the guess must be optimistic about the whole future, not one reward. This lesson follows optimism from R-MAX and UCRL2 to the episodic algorithms UCBVI and optimistic Q-learning, whose regret matches the lower bound up to logarithmic factors, and keeps careful track of where each power of the horizon comes from.
What you’ll learn
- Define regret for episodic and average-reward MDPs, and translate bounds between the conventions (stage-dependent or stationary transitions, ) that change their dependence on .
- Explain R-MAX and UCRL2's extended value iteration as two ways to plan with an optimistic model, and where UCRL2's factors and come from.
- State UCBVI and its bounds, prove optimism by backward induction, and sketch the regret decomposition and its pigeonhole step.
- Explain optimistic Q-learning with step sizes , and why keeps errors from compounding over the horizon.
- Compare the best known upper and lower bounds, and identify what remains open.
From one arm to a whole MDP
Take an episodic MDP with states, actions and horizon : in each of episodes the agent starts in , acts for steps with transitions and rewards , and is then reset. Values are undiscounted sums over the remaining steps, . With steps in total, the regret of the policies is
A bandit is the case , . What is new is that information can be many steps away: to learn what a far state pays, the agent must first get there, which is why undirected exploration such as ε-greedy can need exponentially many episodes.
Two performance measures dominate. Regret, as above. PAC-MDP sample complexity (Kakade, 2003; Strehl, Li & Littman, 2009): with probability , the number of steps on which the agent's policy is not -optimal is polynomial in , , , and the horizon. A sublinear regret bound converts into a PAC-style guarantee by picking one of the played policies at random (Jin et al., 2018, §3.1), and an algorithm that never stops exploring a little can have low regret without being PAC-MDP, so the two notions are related but not equivalent.
Planning optimistically: R-MAX and UCRL2
R-MAX (Brafman & Tennenholtz, 2002) makes optimism crude and effective. A state–action pair counts as known once it has been tried times. Planning uses a doctored model: known pairs keep their empirical transitions, while each unknown pair is sent to an imaginary absorbing state that pays the largest possible reward at every step. The greedy policy of that model either collects near-optimal reward in the real MDP or reaches an unknown pair with substantial probability, and each pair can become known only once, so exploration ends after polynomially many steps: R-MAX is PAC-MDP.
UCRL2 (Jaksch, Ortner & Auer, 2010) replaces "unknown leads to heaven" by confidence sets. For average-reward MDPs that are communicating, with diameter , the longest expected time needed to travel between two states under the best policy for that trip, it keeps for each pair an ball of plausible transition vectors around the empirical one, of radius of order , and plays the optimal policy of the best MDP in the set. Episodes end when some pair's count doubles.
Planning in the most optimistic plausible MDP looks like a hard joint optimization over policies and models, but it decomposes: in each Bellman backup, maximize separately over the transition vector inside each pair's ball. For a value vector :
The inner problem is solved by sorting the states by , so each backup costs per pair. Its gain over the empirical model is bounded by the span of : because sums to zero, subtracting the midpoint of 's range changes nothing:
In the analysis is the optimistic bias vector, whose span is at most , and : a factor and a factor per visit. Summing over visits with the doubling epochs gives , hence the bound below. The is the price of guarding against every transition vector in the ball, not just the ones that matter for .
UCBVI: value iteration with a bonus
UCBVI(δ): # stationary P, known rewards r(s,a) in [0,1], horizon H
for episode k = 1, ..., K:
P̂(s'|s,a) ← N(s,a,s') / N(s,a) for every visited pair
V(H+1, s) ← 0 for all s
for h = H, H−1, ..., 1: # optimistic value iteration
for every (s, a):
if N(s,a) = 0: Q(h,s,a) ← H
else: Q(h,s,a) ← min( Q_previous(h,s,a), H,
r(s,a) + Σ_s' P̂(s'|s,a)·V(h+1,s') + b(s,a) )
V(h, s) ← max_a Q(h, s, a)
for h = 1, ..., H: play a_h = argmax_a Q(h, s_h, a); update the counts N
# UCBVI-CH: b(s,a) = 7·H·L·sqrt(1/N(s,a)), L = ln(5SAT/δ)
# UCBVI-BF: a Bernstein bonus from the empirical variance of V(h+1, ·) at the next stateUCBVI (Azar, Osband & Munos, 2017) adds the bonus to the value, not to the transition model: one confidence interval per pair, for the scalar , instead of a confidence set over -dimensional transition vectors.
Good event. For each pair and step, is a fixed vector with entries in , so is an average of i.i.d. bounded variables. Hoeffding's inequality and a union bound over pairs, steps and counts give, with probability at least , for all of them:
Induction. At both value functions are 0. If entrywise, then, because has nonnegative entries and by the good event,
The two clipping operations keep the inequality: always, and by induction over episodes. So , and maximizing over actions gives . Optimism holds at every step of every episode, simultaneously.
Optimism bounds each episode's regret by the gap between the optimistic value and the value of the policy actually played, , along the visited states. One step of the Bellman equations, with , gives a bonus, a statistical error, the next step's gap and a martingale difference :
The first two terms are at most on the good event. The third is the correction term: depends on the data, so Hoeffding does not apply to it directly, and controlling it without paying is the technical heart of the paper. Unrolling over and summing over episodes, the martingale part is by Azuma's inequality, and the bonuses sum, by grouping visits by pair (counts aggregate over steps when is stationary, ) and Cauchy–Schwarz, to
Multiplying by the bonus scale gives the of UCBVI-CH. UCBVI-BF saves a further with a variance-based bonus and a law of total variance: summed over an episode, the variances of the next-state values are at most of order (the variance of a return bounded by ), not the naive .
Optimistic Q-learning
UCBVI stores an estimated transition model, numbers. Q-learning stores only values and updates one entry per step. Can it explore efficiently? Jin, Allen-Zhu, Bubeck and Jordan (2018) showed that it can, with an exploration bonus in the target and one carefully chosen step size. Their setting: stage-dependent transitions , rewards in , initial states chosen by an adversary, .
Q-LEARNING WITH UCB-HOEFFDING:
Q_h(s,a) ← H and N_h(s,a) ← 0 for all (s, a, h)
for episode k = 1, ..., K:
observe s_1
for h = 1, ..., H:
take a_h = argmax_a Q_h(s_h, a); observe r_h and s_{h+1}
t ← N_h(s_h, a_h) ← N_h(s_h, a_h) + 1
α_t ← (H + 1) / (H + t); b_t ← c · sqrt(H³ · ι / t)
Q_h(s_h,a_h) ← (1 − α_t)·Q_h(s_h,a_h) + α_t·[ r_h + V_{h+1}(s_{h+1}) + b_t ]
V_h(s_h) ← min{ H, max_a Q_h(s_h, a) } # V_{H+1} = 0Algorithm 1 of Jin et al. (2018), with and an absolute constant . The only departures from textbook Q-learning are the optimistic initial value , the bonus and the step size .
Unroll the update. If was taken at step in episodes , the current value is a weighted average of the targets formed at those visits, with weights (and , which is 0 for since ):
Subtracting the Bellman equation for shows that the error at step is a weighted average of the errors at the next step, plus statistical noise and bonuses. When regret is summed over episodes, each next-step error is counted once for every later visit of the pair, with total weight . For this step size the total is a constant just above 1 (Jin et al., Lemma 4.1):
Errors propagate through steps of the episode, so the total amplification is at most a constant:
With horizon , by what factor at most can errors be amplified as they propagate back through the episode, ?
Show the answer
2.59
, and increases to as grows. With instead, every past visit keeps the weight , so targets formed in early episodes, when was far off, keep influencing the estimate. The step size instead concentrates the weight on recent visits: at and the last 10% of visits carry about 68% of the weight and the first half about 0.05%.
The remaining was closed by UCB-Advantage (Zhang, Zhou & Ji, 2020), a model-free algorithm with regret in the same setting, which matches the lower bound up to logarithmic factors: in the tabular case, model-free learning need not be less sample-efficient than model-based learning.
The state of the bounds
| Setting (rewards in per step) | Upper bound | Lower bound |
|---|---|---|
| Average reward, communicating, diameter | UCRL2: ; tractable and minimax optimal: (Boone & Zhang, 2024) | |
| Episodic, stationary , | UCBVI-BF: for | |
| Episodic, stage-dependent , | UCBVI-type, UCB-Advantage: ; Q-learning UCB-H / UCB-B: / | |
| Episodic, stationary, total reward at most 1 per episode, episodes | MVP: , only polylogarithmic in (Zhang, Ji & Du, 2021) |
A paper proves regret for stage-dependent transitions, where is the number of episodes and rewards are in per step. How does that compare with the lower bound in the table?
- It is worse by a factor
- It matches it: with ,
- It beats the lower bound, so one of the two must be wrong
- They cannot be compared, because one counts episodes
Show the answer
B. It matches it: with ,
Substitute : . Counting episodes instead of steps moves one factor of between the regret bound and its argument, which is why papers that look apart by can be saying the same thing.
Key takeaways
- Episodic regret bounds depend on conventions: stage-dependent transitions cost an extra over stationary ones (), and with .
- R-MAX plans in a model where unknown pairs lead to maximal reward; UCRL2 plans in the most optimistic MDP of confidence sets via extended value iteration, reaching against a lower bound.
- UCBVI adds the bonus to the value and concentrates for the fixed , saving ; optimism follows by backward induction, and a pigeonhole argument sums the bonuses to ; a Bernstein bonus reaches , minimax optimal for stationary transitions.
- Optimistic Q-learning with keeps error amplification below because ; it reaches , and UCB-Advantage closes the gap to the lower bound.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
An algorithm has regret in episodic MDPs with stationary transitions (). What does the standard translation give for stage-dependent transitions?
- , unchanged
- , because a stage-dependent MDP is a stationary one with states
Show the answer
B. , because a stage-dependent MDP is a stationary one with states
Augment the state with the step index: becomes and the transitions become stationary. Substituting for gives , which matches the stage-dependent lower bound.
Why does UCBVI's analysis concentrate instead of bounding as UCRL2 does?
- Because the norm cannot be estimated from data
- Because is unknown to the algorithm
- Because UCBVI does not estimate transitions
- Because is a fixed vector, so Hoeffding's inequality applies to one scalar per pair, avoiding the price of guarding against every possible value vector
Show the answer
D. Because is a fixed vector, so Hoeffding's inequality applies to one scalar per pair, avoiding the price of guarding against every possible value vector
A bound on controls for all vectors at once, which costs a factor . The analysis only needs the fixed vector , plus a correction term for the data-dependent that can be handled at lower order.
What is the key property of Jin et al.'s step size ?
- The total weight that a visit's target receives over all later updates, , is , so errors are amplified by at most over an episode
- It satisfies , which guarantees convergence
- It weights every visit equally, which minimizes variance
- It makes the bonus unnecessary
Show the answer
A. The total weight that a visit's target receives over all later updates, , is , so errors are amplified by at most over an episode
The step size forgets old targets fast enough (weight concentrated on roughly the last visits) that errors do not compound across the steps, yet slowly enough to average out noise. The bonus is still needed for optimism.
UCBVI sets . Why do the two clipping operations not break optimism?
- Because the bonus is large enough to compensate for any clipping
- Because clipping only happens in unvisited states
- Because always, and by induction over episodes, so the minimum of three upper bounds on is still an upper bound
- Because optimism is only needed at the first step
Show the answer
C. Because always, and by induction over episodes, so the minimum of three upper bounds on is still an upper bound
Each of the three quantities is at least on the good event: trivially, the previous estimate by induction, the new backup by the induction over and the bonus. A minimum of upper bounds is an upper bound, and a smaller one, which shrinks the exploration bonus actually paid.
Further reading
- T. Jaksch, R. Ortner & P. Auer, "Near-optimal regret bounds for reinforcement learning," Journal of Machine Learning Research 11, 1563–1600 (2010).
- M. G. Azar, I. Osband & R. Munos, "Minimax regret bounds for reinforcement learning," International Conference on Machine Learning (2017).
- C. Jin, Z. Allen-Zhu, S. Bubeck & M. I. Jordan, "Is Q-learning provably efficient?," Advances in Neural Information Processing Systems (2018).
- R. I. Brafman & M. Tennenholtz, "R-max: A general polynomial time algorithm for near-optimal reinforcement learning," Journal of Machine Learning Research 3, 213–231 (2002).
- O. D. Domingues, P. Ménard, E. Kaufmann & M. Valko, "Episodic reinforcement learning in finite MDPs: Minimax lower bounds revisited," Algorithmic Learning Theory (2021).