Lecture 12

Fast RL Continued

Extending data-efficient exploration from bandits to MDPs: PAC learning frameworks, model-based interval estimation (MBIE-EB), Bayesian model-based RL with posterior sampling (PSRL), generalization with function approximation, exploration bonuses for deep RL, and meta-learning for exploration.

PAC-MDP MBIE-EB Bayesian MDPs PSRL Exploration Bonuses Contextual Bandits
Original PDF slides

Probably Approximately Correct (PAC) Learning

Over the past two lectures, we built two families of exploration algorithms for bandits: frequentist methods like UCB and Bayesian methods like Thompson Sampling. Both measure performance through regret—the cumulative gap between our rewards and the best arm's rewards over $T$ rounds.

But regret hides something important. An algorithm with $O(\sqrt{T})$ regret could achieve that by making many tiny mistakes—or by making a few catastrophic ones. In most settings we don't care which. But imagine you're a surgeon relying on an RL system to recommend treatments. You don't just want good average performance—you want a guarantee that after some learning period, the system almost never recommends a seriously bad action.

This motivates Probably Approximately Correct (PAC) learning. Instead of bounding cumulative regret, PAC bounds the number of time steps on which the agent acts significantly suboptimally. The "probably" captures a failure probability $\delta$, and the "approximately" captures a tolerance $\epsilon$.

Where does PAC fit among the evaluation criteria we've seen so far? Think of it as a ladder, each rung more demanding:

  1. Empirical evaluation — run it and measure
  2. Asymptotic convergence — does it eventually find the optimal policy?
  3. Regret bounds — how does total suboptimality grow with $T$?
  4. PAC bounds — after how many steps does the agent stop making non-trivial mistakes?
Definition — PAC RL Algorithm

For given $\epsilon > 0$ and $\delta \in (0, 1)$, a reinforcement learning algorithm $\mathcal{A}$ is PAC if, on all but $N$ time steps, the action $a_t$ selected by $\mathcal{A}$ at time $t$ is $\epsilon$-optimal:

$$Q(a_t) \geq Q(a^*) - \epsilon$$

with probability at least $1 - \delta$, where $N$ is a polynomial function of the problem parameters $(|\mathcal{S}|, |\mathcal{A}|, \frac{1}{1-\gamma}, \frac{1}{\epsilon}, \frac{1}{\delta})$.

Notice that PAC and regret are complementary, not competing. An algorithm can have low regret but fail PAC (by concentrating errors into rare catastrophic steps), or be PAC but have moderate regret (by taking many slightly suboptimal steps during learning). Most PAC algorithms use optimism or Thompson sampling—some simply initialize all values high to encourage exploration.

Fast RL in MDPs

Now let's make the leap from bandits to full MDPs. The same principles carry over—optimism, probability matching, PAC—but the complexity jumps considerably. In a bandit, pulling an arm tells you about that arm's reward. In an MDP, taking action $a$ at state $s$ reveals both the reward $R(s,a)$ and the transition dynamics $T(s'|s,a)$. Both matter for long-term planning.

Even more challenging: reaching a particular state-action pair may require executing a multi-step strategy. Exploration in MDPs isn't just about trying different actions—it involves planning to explore.

The PAC-MDP formulation captures this. Instead of requiring each action to be $\epsilon$-optimal in immediate reward, we require the agent's policy value at the current state to be close to optimal:

Definition — PAC for MDPs

For given $\epsilon > 0$ and $\delta \in (0,1)$, a reinforcement learning algorithm $\mathcal{A}$ is PAC-MDP if, on all but $N$ time steps, the action $a_t$ selected by $\mathcal{A}$ at time $t$ satisfies:

$$V_M^{A_t}(s_t) \geq V_M^*(s_t) - \epsilon$$

with probability at least $1 - \delta$, where $N$ is polynomial in $(|\mathcal{S}|, |\mathcal{A}|, \frac{1}{1-\gamma}, \frac{1}{\epsilon}, \frac{1}{\delta})$.

Here $V_M^{A_t}(s_t)$ denotes the value of the agent's current policy at state $s_t$, and $V_M^*(s_t)$ is the optimal value function.

The key question becomes: how quickly can an algorithm achieve PAC-MDP status? The answer depends on how efficiently it explores the state-action space, and the algorithms we develop in this lecture will achieve polynomial sample complexity in all problem parameters.

Model-Based Interval Estimation with Exploration Bonus (MBIE-EB)

Remember how UCB works in bandits? We add a confidence bonus to each arm's estimated reward, making under-explored arms look optimistically good. MBIE-EB (Strehl and Littman, 2008) does the same thing for MDPs: maintain a model, but inflate the reward at under-visited state-action pairs with an exploration bonus. It's UCB's optimism principle, transplanted into the Bellman equation.

The agent tracks visit counts $n_{sa}$ for each state-action pair and transition counts $n_{sas'}$ for each triple. From these, it builds empirical estimates:

$$\hat{R}(s,a) = \frac{1}{n_{sa}} \sum_{t : (s_t, a_t) = (s,a)} r_t, \qquad \hat{T}(s' \mid s, a) = \frac{n_{sas'}}{n_{sa}}$$

Instead of acting greedily on this model, MBIE-EB adds an exploration bonus $\frac{\beta}{\sqrt{n_{sa}}}$ to each state-action pair's reward and solves the augmented MDP. The bonus shrinks as $1/\sqrt{n}$—rarely-visited states look optimistically good (explore), while well-visited states rely on their true estimates (exploit). The key: this bonus lives inside the Bellman backup:

$$\tilde{Q}(s,a) = \hat{R}(s,a) + \gamma \sum_{s'} \hat{T}(s' \mid s,a) \max_{a'} \tilde{Q}(s', a') + \frac{\beta}{\sqrt{n_{sa}(s,a)}}$$

where the exploration coefficient is:

$$\beta = \frac{1}{1-\gamma}\sqrt{\frac{1}{2} \ln\!\left(\frac{2|\mathcal{S}||\mathcal{A}|m}{\delta}\right)}$$

The agent acts greedily on $\tilde{Q}$: pick $a_t = \arg\max_{a} \tilde{Q}(s_t, a)$, observe the transition, update counts, and re-solve.

MBIE-EB (Strehl and Littman, 2008)
  1. Given $\epsilon$, $\delta$, $m$.
  2. Set $\beta = \frac{1}{1-\gamma}\sqrt{\frac{1}{2}\ln\!\left(\frac{2|\mathcal{S}||\mathcal{A}|m}{\delta}\right)}$.
  3. Initialize $n_{sas'} = 0$, $n_{sa} = 0$, $rc(s,a) = 0$, $\tilde{Q}(s,a) = \frac{1}{1-\gamma}$ for all $s \in \mathcal{S}$, $a \in \mathcal{A}$, $s' \in \mathcal{S}$.
  4. $t = 0$, $s_t = s_{\text{init}}$.
  5. loop
  6. $a_t = \arg\max_{a \in \mathcal{A}} \tilde{Q}(s_t, a)$.
  7. Observe reward $r_t$ and next state $s_{t+1}$.
  8. $n_{sa}(s_t, a_t) \mathrel{+}= 1$; $\;n_{sas'}(s_t, a_t, s_{t+1}) \mathrel{+}= 1$.
  9. $rc(s_t, a_t) = \frac{rc(s_t, a_t)(n_{sa}(s_t, a_t) - 1) + r_t}{n_{sa}(s_t, a_t)}$.
  10. $\hat{R}(s_t, a_t) = rc(s_t, a_t)$; $\;\hat{T}(s' \mid s_t, a_t) = \frac{n_{sas'}(s_t, a_t, s')}{n_{sa}(s_t, a_t)}$ for all $s'$.
  11. while not converged do
  12. $\tilde{Q}(s,a) = \hat{R}(s,a) + \gamma \sum_{s'} \hat{T}(s' \mid s,a) \max_{a'} \tilde{Q}(s', a') + \frac{\beta}{\sqrt{n_{sa}(s,a)}}$ for all $s, a$.
  13. end while
  14. end loop
Key Insight
The exploration bonus propagates through the Bellman backup. A state-action pair $(s, a)$ that leads to an under-explored region will have inflated Q-values, drawing the agent toward it even if $(s, a)$ itself has been visited many times. The bonus doesn't just reward novelty locally—it creates a gradient of optimism that pulls the agent toward unexplored frontiers.

Notice that Q-values start at $\frac{1}{1-\gamma}$—the maximum possible value when rewards are in $[0, 1]$. This optimistic initialization gives unexplored pairs a built-in appeal, providing a second source of exploration pressure on top of the explicit bonus.

The Simulation Lemma

Here's a question that seems obvious but turns out to be subtle: if we learn an approximate model of an MDP—getting rewards and transitions mostly right—does that mean our policy will be good? Not necessarily! Small model errors could compound over a long horizon and produce terrible decisions.

The Simulation Lemma tells us exactly when we're safe. It bridges model accuracy and policy quality: if $\hat{T} \approx T$ and $\hat{R} \approx R$, then $V^{\pi}$ in the approximate model is close to $V^{\pi}$ in the true one. This is the theoretical backbone of MBIE-EB's PAC guarantee.

Theorem — Simulation Lemma

Let $M_1 = (\mathcal{S}, \mathcal{A}, T_1, R_1, \gamma)$ and $M_2 = (\mathcal{S}, \mathcal{A}, T_2, R_2, \gamma)$ be two MDPs that differ by at most $\alpha$ in rewards and $\beta$ in transition probabilities (L1 norm). That is, for a fixed policy $\pi$:

$$\|R_1(s,a) - R_2(s,a)\|_\infty \leq \alpha, \qquad \|T_1(\cdot \mid s,a) - T_2(\cdot \mid s,a)\|_1 \leq \beta$$

Then the value functions differ by at most:

$$\max_s |V_1^\pi(s) - V_2^\pi(s)| \leq \frac{\alpha + \gamma V_{\max} \beta}{1 - \gamma}$$

where $V_{\max} = \frac{R_{\max}}{1 - \gamma}$ is the maximum possible value.

Proof of the Simulation Lemma

Start from the Bellman equation for $Q^\pi$ in both MDPs. For any state-action pair $(s, a)$:

$$|Q_1^\pi(s,a) - Q_2^\pi(s,a)| = \left|R_1(s,a) - R_2(s,a) + \gamma \sum_{s'} \left(T_1(s'|s,a)\, V_1^\pi(s') - T_2(s'|s,a)\, V_2^\pi(s')\right)\right|$$

Add and subtract $T_1(s'|s,a)\, V_2^\pi(s')$ inside the summation to separate transition error from value error:

$$\leq |R_1(s,a) - R_2(s,a)| + \gamma \left|\sum_{s'} T_1(s'|s,a)(V_1^\pi(s') - V_2^\pi(s'))\right| + \gamma \left|\sum_{s'} (T_1(s'|s,a) - T_2(s'|s,a))\, V_2^\pi(s')\right|$$

Define $\Delta := \max_s |V_1^\pi(s) - V_2^\pi(s)|$. The first term is bounded by $\alpha$. The second term is bounded by $\gamma \Delta$ since $T_1$ is a distribution. The third term is bounded by $\gamma V_{\max} \beta$ by Hölder's inequality (L1 norm of $T_1 - T_2$ times L$\infty$ norm of $V_2^\pi$):

$$\Delta \leq \alpha + \gamma \Delta + \gamma V_{\max} \beta$$

Rearranging:

$$(1 - \gamma)\Delta \leq \alpha + \gamma V_{\max} \beta$$ $$\boxed{\Delta \leq \frac{\alpha + \gamma V_{\max} \beta}{1 - \gamma}} \qquad \blacksquare$$

Notice the $(1 - \gamma)$ in the denominator. Errors at each step propagate through the entire horizon, so longer horizons (larger $\gamma$) amplify model errors. This is intuitive: if you're planning a one-step trip, a slightly wrong map barely matters. If you're planning a cross-country journey, small errors accumulate.

MBIE-EB is PAC

We can now put the pieces together: MBIE-EB is PAC-MDP. The proof has three ingredients:

  1. Concentration — after $m$ visits to a state-action pair, $\hat{R}$ and $\hat{T}$ are close to the true values with high probability.
  2. Simulation Lemma — accurate models yield near-optimal policies.
  3. Counting argument — there are $|\mathcal{S}| \times |\mathcal{A}|$ pairs, and each can be "under-visited" at most $m$ times. So the total number of bad steps is at most $|\mathcal{S}| \cdot |\mathcal{A}| \cdot m$.

On all other steps, the model is accurate enough and the policy is near-optimal. That's the PAC guarantee.

Theorem — MBIE-EB PAC Guarantee (Strehl and Littman, 2008)

Suppose $\epsilon \in (0, 1)$ and $\delta \in (0, 1)$, and $M = (\mathcal{S}, \mathcal{A}, T, R, \gamma)$ is any MDP. There exists an input $m = m(\frac{1}{\epsilon}, \frac{1}{\delta})$ satisfying:

$$m\!\left(\frac{1}{\epsilon}, \frac{1}{\delta}\right) = O\!\left(\frac{|\mathcal{S}|}{\epsilon^2(1-\gamma)^2} + \frac{1}{\epsilon^2(1-\gamma)^4} \ln \frac{|\mathcal{S}||\mathcal{A}|}{\delta}\right)$$

and $\beta = \frac{1}{1-\gamma}\sqrt{\frac{1}{2}\ln\frac{2|\mathcal{S}||\mathcal{A}|m}{\delta}}$, such that if MBIE-EB is executed on MDP $M$, then with probability at least $1 - \delta$:

$$V_M^{A_t}(s_t) \geq V_M^*(s_t) - \epsilon$$

is true for all but

$$O\!\left(\frac{|\mathcal{S}||\mathcal{A}|}{\epsilon^2(1-\gamma)^4}\left(|\mathcal{S}| + \ln\frac{|\mathcal{S}||\mathcal{A}|}{\delta}\right) \ln \frac{1}{\epsilon(1-\gamma)}\right)$$

time steps $t$.

The sample complexity is polynomial in all problem parameters—this is what makes MBIE-EB a PAC-MDP algorithm. The dominant term scales as $\tilde{O}\!\left(\frac{|\mathcal{S}|^2 |\mathcal{A}|}{\epsilon^2 (1-\gamma)^4}\right)$, reflecting the cost of learning transitions for all $|\mathcal{S}||\mathcal{A}|$ state-action pairs to accuracy $\epsilon$ over an effective horizon of $\frac{1}{1-\gamma}$.

Bayesian Model-Based RL

In Lecture 11, we saw how Bayesian bandits maintain a posterior over reward parameters and explore via Thompson Sampling. The natural next step: maintain a posterior over the entire MDP—transitions $\mathcal{P}$ and rewards $\mathcal{R}$.

The posterior $p(\mathcal{P}, \mathcal{R} \mid h_t)$ updates as we observe states, actions, and rewards. With Dirichlet priors over transitions (the conjugate for categorical distributions), these updates stay analytically tractable—just like Beta-Bernoulli for bandits.

The same two exploration strategies carry over:

The conceptual leap is straightforward, but there's an important practical difference: "acting optimally under a sample" now means solving an entire MDP, not just picking the arm with the highest mean. That computational cost is the main challenge.

The upside? If the prior is well-calibrated, Bayesian methods can be far more data-efficient than frequentist ones. The prior encodes structural knowledge—like "nearby states have similar dynamics"—that pure counting methods like MBIE-EB cannot exploit.

Posterior Sampling for Reinforcement Learning (PSRL)

PSRL (Osband, Russo, and Van Roy, 2013) is beautifully simple. At the start of each episode: sample a complete MDP from the posterior, solve it to get the optimal policy, and follow that policy for the entire episode. Then update the posterior and repeat.

Just like Thompson Sampling for bandits—but instead of sampling a reward and picking the best arm, we sample an entire world model and plan optimally within it. The probability matching property still holds:

$$\pi(s, a \mid h_t) = \mathbb{P}[Q(s,a) \geq Q(s,a'),\; \forall a' \neq a \mid h_t] = \mathbb{E}_{\mathcal{P}, \mathcal{R} \mid h_t}\!\left[\mathbf{1}\!\left(a = \arg\max_{a \in \mathcal{A}} Q(s,a)\right)\right]$$
Posterior Sampling for RL (PSRL) (Osband, Russo, Van Roy, 2013)
  1. Initialize prior over dynamics and reward models for each $(s, a)$: $p(R_{sa})$, $p(T(s' \mid s, a))$.
  2. Initialize state $s_0$.
  3. for $k = 1, 2, \ldots, K$ (episodes) do
  4. Sample an MDP $M$:
  5. for each $(s, a)$ pair do
  6. Sample dynamics model $T(s' \mid s, a)$ from posterior.
  7. Sample reward model $R(s, a)$ from posterior.
  8. end for
  9. Compute $Q_M^*$, the optimal Q-function for sampled MDP $M$.
  10. for $t = 1, 2, \ldots, H$ do
  11. $a_t = \arg\max_{a \in \mathcal{A}} Q_M^*(s_t, a)$.
  12. Observe reward $r_t$ and next state $s_{t+1}$.
  13. end for
  14. Update posterior $p(R_{s,a} \mid r_t)$, $p(T(s' \mid s, a) \mid s_{t+1})$ using Bayes' rule.
  15. end for

Why sample per-episode instead of per-step? This is crucial for deep exploration. If the posterior says a distant state might be highly rewarding, PSRL commits to a policy that navigates there. Compare this to $\epsilon$-greedy, which explores locally but can never execute a multi-step plan to reach an informative state far away.

Example — Concurrent PSRL

When multiple agents explore simultaneously (e.g., different users on a website), each can sample from the same posterior with different random seeds. This naturally diversifies exploration—instead of all agents heading to the same unexplored region, randomized sampling spreads them across the state space, accelerating collective learning (Dimakopoulou and Van Roy, 2018).

Generalization and Strategic Exploration

Everything so far—MBIE-EB, PSRL, PAC—treats each state-action pair independently. That's fine when $|\mathcal{S}|$ and $|\mathcal{A}|$ are small. But in Atari, the "state" is a screen of pixels ($256^{210 \times 160 \times 3}$ possible images). In robotics, states are continuous joint angles. We'll never visit most states even once, let alone the multiple times MBIE-EB needs.

We need generalization: using experience from similar states to inform behavior at novel ones. The visit-count approach completely breaks down here.

The bridge between tabular methods and large-scale RL is the contextual bandit. Before choosing an action, the agent observes a context (feature vector) $s$, and the reward depends on both context and action.

Definition — Contextual Multi-Armed Bandit

A contextual bandit is a tuple $(\mathcal{A}, \mathcal{S}, \mathcal{R})$ where $\mathcal{A}$ is the action space, $\mathcal{S}$ is the context/state space, and $\mathcal{R}^{a,s}(r) = \mathbb{P}[r \mid a, s]$ is the reward distribution conditioned on both action and context. When the state/action space is large, we model:

$$r = \theta\, \phi(s, a) + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \sigma^2)$$

using a feature function $\phi$ and learn the parameter vector $\theta$. In the disjoint model, each arm has its own parameter: $r(s, a) = \theta_a\, \phi(s) + \epsilon$.

The payoff of generalization is dramatic. LinUCB replaces raw visit counts with confidence ellipsoids from linear regression. As the number of arms $K$ grows, UCB's regret scales linearly with $K$ (each arm explored independently), while LinUCB stays nearly flat—learning about one arm immediately constrains all others through the shared feature space.

The key shift: instead of asking "how many times have I visited this state?", we ask "how uncertain is my model about this state, given everything I've seen?" A state we've never visited can still have low uncertainty if it's similar (in feature space) to states we know well.

Exploration Bonuses for Deep RL

Can we bring MBIE-EB's optimism into deep RL? The idea is simple: add an exploration bonus $r_{\text{bonus}}(s, a)$ to the Q-learning update, approximating what count-based bonuses do in the tabular setting.

The standard Q-learning weight update with function approximation is:

$$\Delta \mathbf{w} = \alpha\!\left(r(s) + \gamma \max_{a'} \hat{Q}(s', a'; \mathbf{w}) - \hat{Q}(s, a; \mathbf{w})\right) \nabla_\mathbf{w} \hat{Q}(s, a; \mathbf{w})$$

With an exploration bonus, this becomes:

$$\Delta \mathbf{w} = \alpha\!\left(r(s) + r_{\text{bonus}}(s,a) + \gamma \max_{a'} \hat{Q}(s', a'; \mathbf{w}) - \hat{Q}(s, a; \mathbf{w})\right) \nabla_\mathbf{w} \hat{Q}(s, a; \mathbf{w})$$

But how do you count "visits" in a continuous state space? You can't. Instead, researchers have found creative proxies for novelty:

Example — Montezuma's Revenge

Standard DQN with $\epsilon$-greedy learns almost nothing in this notoriously hard Atari game, even after 50 million frames—it never stumbles upon the sparse rewards hidden behind long action sequences. Add count-based exploration bonuses, and the same DQN discovers dozens of rooms and game mechanics. The bonus acts as intrinsic motivation—curiosity about novel states—driving the agent past the first room where $\epsilon$-greedy gets stuck.

One important caveat: bonus terms are computed at the time of visit. During experience replay, a state that was novel when first visited may have been seen many times by the time the replay happens—making the stored bonus stale.

Thompson Sampling with Function Approximation

Thompson Sampling faces a harder challenge with neural networks: maintaining a posterior over millions of weights is intractable. Three pragmatic approximations have emerged:

The gap between theory (exact posteriors give optimal exploration) and practice (approximate posteriors give heuristic exploration) remains open. No current method achieves both the computational efficiency of deep networks and the guarantees of exact Bayesian inference.

Meta-Learning for RL Exploration

Every exploration method so far has been hand-designed: a researcher specifies the strategy (add a bonus, sample from a posterior) and proves it works. But here's a provocative question: can agents learn to explore?

The meta-learning approach trains agents across many tasks so they internalize good exploration behavior. Instead of being told to add $\beta / \sqrt{n}$, the agent discovers from experience what exploration patterns lead to fast learning.

DREAM

DREAM (Liu et al., 2022) trains a policy to explore effectively across a distribution of tasks, learning strategies that generalize to new environments.

Decision-Pretrained Transformer (DPT)

DPT (Lee, Xie, Pacchiano, Chandak, Finn, Nachum, Brunskill, 2023) takes a different approach: train a transformer on trajectories of $(s, a, r, s')$ tuples. Given past experience $D$ and a query state $s_{\text{query}}$, the transformer outputs an action distribution $M_\theta(a^* \mid s_{\text{query}}, D)$.

Why does this work? Training to predict optimal actions given a dataset implicitly mimics Thompson Sampling—but with a learned prior instead of a hand-specified one. Thompson Sampling is optimal when the prior is correct, but choosing the right prior in complex domains is itself an unsolved problem. DPT learns its implicit prior from data across many tasks, and the transformer architecture can represent far richer task distributions than any analytically tractable prior family.

The results are striking: on linear bandits, DPT outperforms both Thompson Sampling and LinUCB. Learned exploration can surpass hand-designed algorithms when task structure is available in training data.

Theoretical Results and Open Problems

Where does the theory stand? For tabular MDPs, it's essentially complete:

The frontier has shifted to function approximation. Jin et al. (2020) gave the first provably efficient algorithms for RL with linear function approximation. But the deeper question—what makes exploration hard?—requires entirely new complexity measures like eluder dimension (Russo and Van Roy) and Bellman rank (Jiang et al.).

A unified characterization remains elusive. This is one of the most active areas in RL theory, and progress here would directly impact practical deep RL systems.

Summary

This lecture completed our three-lecture arc on data-efficient RL (Lectures 10–12), extending exploration from bandits to full MDPs and beyond.

We introduced PAC as a complementary evaluation criterion to regret—especially relevant in safety-critical settings where we care about bounding the count of bad decisions. MBIE-EB achieves PAC-MDP guarantees by injecting optimistic exploration bonuses into the Bellman backup, grounded by the Simulation Lemma connecting model accuracy to policy quality.

On the Bayesian side, PSRL extends Thompson Sampling to MDPs with episode-level commitment that enables deep exploration. When tabular methods hit their limits, contextual bandits and LinUCB replace visit counts with model uncertainty, and deep RL exploration bonuses bring intrinsic motivation to neural networks. Finally, meta-learning approaches like DPT can learn to explore, outperforming hand-designed algorithms.

The algorithm-to-guarantee mapping for the full exploration arc:

AlgorithmGuaranteeSetting
UCBFrequentist regret, PACBandits
Thompson SamplingBayesian regretBandits & MDPs
MBIE-EBPACTabular MDPs
PSRLBayesian regretTabular MDPs
LinUCBRegretLinear contextual bandits
Count-based bonuses / DPTEmpiricalDeep RL