Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Posterior Sampling & Deep Exploration

PSRL, randomized value functions and bootstrapped DQN.

Thompson sampling carries over to MDPs almost word for word: sample a whole environment from the posterior, act optimally in it for an episode, then update. Committing to one sample for the entire episode is what makes the exploration deep, aimed at the far end of a chain instead of jittering near the start. This lesson proves why posterior sampling needs no optimism, follows its regret bounds and their fine print, and traces how randomized value functions, bootstrapped ensembles and prior networks carry the idea into deep RL.

What you’ll learn

  • Describe posterior sampling for RL (PSRL), and explain why sampling once per episode explores deeply while dithering needs exponentially many episodes.
  • Prove that confidence sets transfer from the true MDP to the sampled one, and use it to sketch PSRL's O~(HSAT)\tilde{\mathcal O}(HS\sqrt{AT}) Bayesian regret bound.
  • State the sharper Bayesian bounds and the worst-case results for optimistic variants, with their settings and a corrected error.
  • Derive randomized least-squares value iteration as posterior sampling over value functions, and explain bootstrapped DQN and randomized prior functions as scalable approximations.
  • Interpret the deep-sea experiments: what they establish about deep exploration and what they leave open.

Sample a world, then commit to it

Use the episodic setting of Optimism in MDPs: UCRL2 & UCBVI: SS states, AA actions, episodes of HH steps, rewards in [0,1][0,1], KK episodes and T=KHT=KH steps, and regret ∑k(VM⋆⋆(s1)−VM⋆πk(s1))\sum_k\big(V^\star_{M^\star}(s_1)-V^{\pi_k}_{M^\star}(s_1)\big) against the true MDP M⋆M^\star. Posterior sampling for reinforcement learning (PSRL; Strens, 2000; Osband, Russo & Van Roy, 2013) treats M⋆M^\star as drawn from a prior and repeats three steps:

text
PSRL(prior over MDPs):
    for episode k = 1, 2, ...:
        sample M_k ~ posterior( · | history before episode k)
            # e.g. a Dirichlet posterior on each P(·|s,a), a conjugate posterior on each r(s,a)
        π_k ← optimal policy of M_k          # finite-horizon value iteration on the sample
        follow π_k for all H steps, adding every transition to the history

With independent Dirichlet priors on the transition vectors the posterior stays Dirichlet and sampling is cheap; planning in the sample costs one finite-horizon value iteration per episode, O(HS2A)\order{HS^2A} operations. Nothing in the loop is optimistic: the sample is as likely to be pessimistic as optimistic about any given state.

Think first What would go wrong if PSRL drew a fresh MDP at every step instead of once per episode?

Its plan would change at every step. A sample in which the far end pays sends the agent one step right; the next sample may favor the near end and send it back. Exploration becomes a random walk again, the dithering that deep exploration was meant to escape. Osband, Blundell, Pritzel and Van Roy (2016) saw exactly this: a "Thompson DQN" that resampled its value function at every step failed on their chain problems, while the same ensemble resampled once per episode scaled to long chains. A sample is useful because it is a consistent hypothesis, followed long enough to be tested.

Why sampling needs no optimism

Write Hk\mathcal H_k for everything observed before episode kk. PSRL draws MkM_k from the posterior given Hk\mathcal H_k, which is also the conditional law of M⋆M^\star, so the sample and the truth are interchangeable in any expectation given Hk\mathcal H_k: E[g(M⋆)∣Hk]=E[g(Mk)∣Hk]\E[g(M^\star)\mid\mathcal H_k]=\E[g(M_k)\mid\mathcal H_k] for any function gg of an MDP. The whole analysis rests on two choices of gg.

DerivationThe posterior sampling lemma, used twice
  1. E[VM⋆⋆(s1)−VM⋆πk(s1)]  =  E[VMkπk(s1)−VM⋆πk(s1)]\E\big[V^\star_{M^\star}(s_1)-V^{\pi_k}_{M^\star}(s_1)\big]\;=\;\E\big[V^{\pi_k}_{M_k}(s_1)-V^{\pi_k}_{M^\star}(s_1)\big]

    No optimism gap. Take g(M)=VM⋆(s1)g(M)=V^\star_M(s_1). Since πk\pi_k is optimal for MkM_k, VMk⋆=VMkπkV^\star_{M_k}=V^{\pi_k}_{M_k}, and the expected regret of episode kk becomes an evaluation gap, the same policy valued in two MDPs:

  2. Pr⁡(Mk∉Ck)  =  Pr⁡(M⋆∉Ck)  ≤  δ\Pr\big(M_k\notin\mathcal C_k\big)\;=\;\Pr\big(M^\star\notin\mathcal C_k\big)\;\le\;\delta

    Confidence sets transfer. Let Ck\mathcal C_k be any set of MDPs determined by Hk\mathcal H_k, for example the MDPs whose transition vectors lie within an L1L_1 radius β(Nk(s,a))\beta(N_k(s,a)) of the empirical ones. Take g(M)=1{M∉Ck}g(M)=\mathbf 1\{M\notin\mathcal C_k\}:

  3. VMkπ(s1)−VM⋆π(s1)=Eπ,M⋆[∑h=1H(rk−r⋆)(sh,ah)+(Pk−P⋆)(⋅∣sh,ah)⊤VMk,h+1π]≤Eπ,M⋆[∑h=1H(∣rk−r⋆∣+H∥Pk−P⋆∥1)(sh,ah)]V^{\pi}_{M_k}(s_1)-V^{\pi}_{M^\star}(s_1)=\E_{\pi,M^\star}\Big[\sum_{h=1}^H\big(r_k-r^\star\big)(s_h,a_h)+\big(P_k-P^\star\big)(\cdot\mid s_h,a_h)^{\top}V^{\pi}_{M_k,h+1}\Big]\le\E_{\pi,M^\star}\Big[\sum_{h=1}^H\big(\abs{r_k-r^\star}+H\norm{P_k-P^\star}_1\big)(s_h,a_h)\Big]

    So frequentist concentration for the true MDP holds for the sample too, although no step of the algorithm is optimistic. Simulation lemma. Unroll the two value functions along a trajectory of πk\pi_k in the true MDP: each step contributes the one-step model error, weighted by a next-step value of at most HH:

  4. E[Regret(T)] ≲ HSlog⁡(SAT)∑s,aNT(s,a) ≤ HSlog⁡(SAT) SAT = HSATlog⁡(SAT)\E\big[\mathrm{Regret}(T)\big]\ \lesssim\ H\sqrt{S\log(SAT)}\sum_{s,a}\sqrt{N_T(s,a)}\ \le\ H\sqrt{S\log(SAT)}\,\sqrt{SAT}\ =\ HS\sqrt{AT\log(SAT)}

    When both MkM_k and M⋆M^\star lie in Ck\mathcal C_k, the triangle inequality gives ∥Pk−P⋆∥1≤2β(Nk)\norm{P_k-P^\star}_1\le2\beta(N_k), with β(n)\beta(n) of order Slog⁡(SAT)/n\sqrt{S\log(SAT)/n}, the L1L_1 concentration of an empirical distribution over SS outcomes. Summing HSlog⁡(SAT)/Nk(s,a)H\sqrt{S\log(SAT)/N_k(s,a)} over all visits with the pigeonhole argument of Optimism in MDPs gives the bound below; counts are refreshed only between episodes, which costs a constant factor.

Check your understanding

Why does Pr⁡(Mk∉Ck)=Pr⁡(M⋆∉Ck)\Pr(M_k\notin\mathcal C_k)=\Pr(M^\star\notin\mathcal C_k) hold?

  1. Because Ck\mathcal C_k is determined by the history, and given the history MkM_k and M⋆M^\star have the same distribution
  2. Because PSRL redraws its sample until it lands in the confidence set
  3. Because the confidence set contains every MDP with high probability
  4. Because the posterior concentrates on M⋆M^\star after one episode
Show the answer

A. Because Ck\mathcal C_k is determined by the history, and given the history MkM_k and M⋆M^\star have the same distribution

The indicator 1{M∉Ck}\mathbf 1\{M\notin\mathcal C_k\} is a fixed function of MM once Hk\mathcal H_k is known, so the posterior sampling lemma applies to it. This is how a Bayesian algorithm borrows frequentist concentration: the confidence set is used only in the proof, and the algorithm never needs to compute it.

UCRL2 must plan in the most optimistic MDP of the whole confidence set, an extended value iteration over L1L_1 balls; PSRL plans in one sampled MDP with ordinary value iteration. The analyses look alike because the same confidence sets appear in both, but PSRL uses them only in the proof, and a sample is optimistic only where the data leave room for it. In Osband, Russo and Van Roy's experiments, PSRL had lower regret than UCRL2 in every environment; on the episodic RiverSwim its total regret was about 69 against UCRL2's 1,260.

Sharper bounds, worst cases and fine print

ResultSettingGuarantee
Osband, Russo & Van Roy (2013)Episodic, stationary; any priorBayesian: O~(HSAT)\tilde{\mathcal O}(HS\sqrt{AT})
Osband & Van Roy (2017)Episodic, stationary; independent Dirichlet priors on transitionsBayesian: O~(HSAT)\tilde{\mathcal O}(H\sqrt{SAT}); they conjecture O~(HSAT)\tilde{\mathcal O}(\sqrt{HSAT}), which would be unimprovable
Osband, Van Roy, Russo & Wen (2019), RLSVIEpisodic, stage-dependent; Dirichlet priorBayesian: O~(HSAT)\tilde{\mathcal O}(H\sqrt{SAT}), with SS counting the states of all stages
Moradipari, Pedramfar, Shokrian Zini & Aggarwal (2023)Stage-dependent; no Dirichlet assumption; information-ratio analysisBayesian: a tabular bound matching Osband and Van Roy's for large TT, and bounds for linear and general model classes
Agrawal & Jia (2017; corrected 2020)Average reward, communicating, diameter DD; several posterior samples per pair, used optimisticallyWorst case, with high probability: claimed O~(DSAT)\tilde{\mathcal O}(D\sqrt{SAT}), corrected to O~(DSAT)\tilde{\mathcal O}(DS\sqrt{AT})
Russo (2019), RLSVIEpisodic, tabularWorst case: polynomial in HH, SS, AA, not tight
Tiapkin et al. (2022), OPSRLEpisodic, stage-dependent; logarithmically many samples per pairWorst case, with high probability: O~(H3SAK)\tilde{\mathcal O}(\sqrt{H^3SAK}) after KK episodes, matching the lower bound up to logarithms
Guarantees for posterior sampling in tabular MDPs with rewards in [0,1][0,1] per step, as of the mid-2020s; TT counts steps unless stated.

Three cautions in reading the table. Conventions: the rows mix stationary and stage-dependent transitions and count time in steps or in episodes. With T=KHT=KH, OPSRL's H3SAK\sqrt{H^3SAK} is HSATH\sqrt{SAT} in steps, the stage-dependent lower bound of Optimism in MDPs.

Bayesian versus worst case: the first four rows average over the prior the algorithm uses. Worst-case guarantees come from variants that add optimism, by acting on the most favorable of several samples, or, in Russo's analysis of RLSVI, by injecting enough noise that each sampled value function is optimistic with substantial probability: the MDP counterpart of linear Thompson sampling's inflated posterior (Regret Bounds for Thompson Sampling).

Fragility: these proofs are delicate. Agrawal and Jia's published worst-case bound relied on a dimension-free concentration lemma for multinomial vectors that Qian, Fruit, Pirotta and Lazaric (2020) showed cannot hold, since the deviation grows like S\sqrt S; the corrected version, posted in 2020, is worse by exactly that factor S\sqrt S. A bound is a claim about a proof, and proofs in this area deserve the same scrutiny as experiments.

Randomized value functions

PSRL needs a posterior over MDPs and a planner for the sample, both out of reach with neural networks. Randomized value functions instead sample a plausible QQ-function directly and act greedily on it for a whole episode. The first was randomized least-squares value iteration (RLSVI; Osband, Van Roy & Wen, 2016): with linear features ϕ(s,a)\boldsymbol\phi(s,a), work backward through the episode, fit each step's QQ by Bayesian linear regression on targets built from the next step's sampled QQ, and draw the weights from the resulting Gaussian posterior.

text
RLSVI, one episode (features φ(s,a) in R^d, noise variance σ², prior precision λ):
    Q̃_{H+1} ← 0
    for h = H, H−1, ..., 1:
        y_j ← r_j + max_a Q̃_{h+1}(s'_j, a)      for each logged transition (s_j, a_j, r_j, s'_j) at step h
        Σ ← (ΦᵀΦ / σ² + λ I)⁻¹;   w̄ ← Σ Φᵀ y / σ²      # Bayesian linear regression; Φ stacks φ(s_j, a_j)
        draw w_h ~ N(w̄, Σ);   Q̃_h(s, a) ← w_hᵀ φ(s, a)
    act greedily with respect to Q̃_1, ..., Q̃_H for the whole episode

Equivalently, add independent N(0,σ2)\mathcal N(0,\sigma^2) noise to the targets, draw a prior weight vector w~∼N(0,λ−1I)\tilde{\mathbf w}\sim\mathcal N(0,\lambda^{-1}I), and minimize ∥y+ε−Φw∥2/σ2+λ∥w−w~∥2\norm{\mathbf y+\boldsymbol\varepsilon-\Phi\mathbf w}^2/\sigma^2+\lambda\norm{\mathbf w-\tilde{\mathbf w}}^2: the minimizer has mean ΣΦ⊤y/σ2\Sigma\Phi^\top\mathbf y/\sigma^2 and covariance Σ\Sigma, an exact posterior sample. This randomize-then-fit form needs only a regression solver, which is how the idea scales to neural networks.

Bootstrapped DQN (Osband, Blundell, Pritzel & Van Roy, 2016) approximates the posterior with an ensemble: K=10K=10 heads on a shared convolutional torso, each trained on its own subset of the replay data against its own target network. At the start of each episode one head is chosen uniformly at random and followed greedily for the whole episode, PSRL's episode-long commitment. On chain problems it was the only variant that scaled; the same ensemble resampled at every step, or used as a majority vote, did not. On Atari it learned faster than DQN in most games. Two details temper the story: in the Atari runs every head saw all the data (bootstrap masks with p=1p=1), so the diversity came from random initialization and separate targets, not from the bootstrap; and on Montezuma's Revenge it reached the first key after 20 million frames, where DQN saw no reward in 200 million, yet did not learn to exploit it.

Randomized prior functions (Osband, Aslanides & Cassirer, 2018) fix a deeper flaw. An ensemble fit only to data has no reason to disagree where there are no data: with no rewards observed, every member can learn to predict zero everywhere, and nothing pushes the agent anywhere new. The fix adds to each member a fixed, randomly initialized, untrainable network, Qk=fθk+β pkQ_k=f_{\boldsymbol\theta_k}+\beta\,p_k, so members disagree wherever data have not pinned them down. For linear-Gaussian models this is exactly the randomize-then-fit recipe above, so the method is a form of RLSVI. The same paper shows that dropout, a popular uncertainty estimate, does not concentrate with data at all: duplicating the dataset leaves the dropout distribution unchanged.

Predict before you look

On deep sea with N=20N=20, a policy that picks each action uniformly at random reaches the chest with probability 2−202^{-20}. How many thousand episodes does it need on average before the first visit?

Show the answer

1049 thousand episodes

The number of episodes until the first visit is geometric with mean 220=1,048,5762^{20}=1{,}048{,}576, about a million; at N=50N=50 it would be about 101510^{15}. Dithering strategies inherit this exponential scaling, because their random deviations are independent from step to step and the reward requires a coordinated run of NN of them. PSRL-style agents need a number of episodes polynomial in NN.

What the evidence shows, and what is open

Deep sea shows that a method can explore deeply: it is deterministic, its observations are one-hot, and its only difficulty is the length of the commitment required. It does not test generalization across observations, noisy rewards and transitions, or credit assignment over long horizons. That narrowness is deliberate: deep sea is one of the core experiments of the Behaviour Suite for RL (Osband et al., 2020), whose experiments are each designed to isolate one capability. On the hard-exploration Atari games, posterior-sampling agents learned faster without solving the hardest games; as of the mid-2020s the strongest results there came from agents built on exploration bonuses or on returning to remembered states (Exploration Bonuses at Scale). A fair summary: randomized value functions are the best-understood route to deep exploration with function approximation, but not yet the most effective one on the hardest benchmarks.

Key takeaways

  • PSRL samples one MDP per episode from the posterior and follows its optimal policy for the whole episode. That commitment makes exploration deep: on a chain it needs a number of episodes roughly linear in the length, where dithering needs exponentially many.
  • The posterior sampling lemma removes the optimism gap and transfers confidence sets from the true MDP to the sample, so the regret reduces to model errors along visited pairs: O(HSATlog⁡(SAT))\order{HS\sqrt{AT\log(SAT)}} Bayesian regret for any prior.
  • Sharper Bayesian bounds of order HSATH\sqrt{SAT} hold under Dirichlet priors and, later, without them; worst-case guarantees need optimism added to sampling (OPSRL matches the lower bound). The fine print matters: one published worst-case bound was later corrected by a factor S\sqrt S.
  • Randomized value functions sample QQ directly: RLSVI fits Bayesian regressions backward through the episode, bootstrapped DQN follows one ensemble head per episode, and randomized prior functions add a fixed random network so that disagreement persists where no data exist.
  • Deep sea isolates deep exploration (dithering needs about 2N2^N episodes) and shows prior-augmented ensembles scaling polynomially; trustworthy uncertainty at scale, generalization and the hardest-exploration benchmarks remain open.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why does PSRL sample a new MDP once per episode rather than at every step?

  1. Sampling is too expensive to do at every step
  2. The posterior does not change within an episode
  3. Following one sampled MDP for a whole episode tests a consistent hypothesis, so the agent can travel deliberately to distant states; resampling every step makes its plan change constantly, which degenerates into dithering
  4. The regret bound requires an even number of samples
Show the answer

C. Following one sampled MDP for a whole episode tests a consistent hypothesis, so the agent can travel deliberately to distant states; resampling every step makes its plan change constantly, which degenerates into dithering

Deep exploration means committing to a multi-step plan that would gather information if a hypothesis were true. A per-step sample changes the hypothesis before the plan can pay off; in the bootstrapped DQN experiments, the variant that resampled every step failed on chains that the per-episode version solved.

Question 2

Why do randomized prior functions add a fixed, untrainable random network to each member of a bootstrapped ensemble?

  1. To make training faster
  2. To reduce the variance of the value estimates
  3. To regularize the networks toward zero
  4. Because an ensemble fit only to data can agree where there are no data (for example, predicting zero everywhere when no reward has been seen), leaving nothing to drive exploration; the prior keeps members different wherever data have not pinned them down
Show the answer

D. Because an ensemble fit only to data can agree where there are no data (for example, predicting zero everywhere when no reward has been seen), leaving nothing to drive exploration; the prior keeps members different wherever data have not pinned them down

Bootstrap diversity comes from the data, so it vanishes in unvisited regions, exactly where exploration is needed. A random prior network supplies prior uncertainty that only data can remove. For linear-Gaussian models the recipe yields exact posterior samples, and on deep sea only the ensemble with priors scaled to large problem sizes.

Question 3

Which statement about PSRL's guarantees is accurate?

  1. PSRL has a worst-case regret bound of O~(HSAT)\tilde{\mathcal O}(\sqrt{HSAT}) on every MDP
  2. Its classical guarantees bound Bayesian regret, averaged over the prior it uses; worst-case guarantees come from optimistic variants that draw several samples or inflate the noise
  3. It has no guarantees of any kind; it is a heuristic
  4. Its guarantees require optimistic initial values
Show the answer

B. Its classical guarantees bound Bayesian regret, averaged over the prior it uses; worst-case guarantees come from optimistic variants that draw several samples or inflate the noise

Osband, Russo and Van Roy bound the Bayesian regret by O~(HSAT)\tilde{\mathcal O}(HS\sqrt{AT}) for any prior. Worst-case results, such as OPSRL's, add optimism by taking the most favorable of several samples. O~(HSAT)\tilde{\mathcal O}(\sqrt{HSAT}) is Osband and Van Roy's conjecture for the Bayesian regret, not a proven worst-case bound.

Question 4

With linear features, RLSVI can add Gaussian noise to its regression targets, draw a random prior weight vector, and fit a regularized least-squares regression. What does this produce?

  1. An exact sample from the Gaussian posterior over the weights, obtained with only a regression solver
  2. The posterior mean, made robust to noise
  3. An optimistic estimate, larger than the true value with high probability
  4. A biased estimate that must be corrected by importance sampling
Show the answer

A. An exact sample from the Gaussian posterior over the weights, obtained with only a regression solver

For linear-Gaussian models, the minimizer of ∥y+ε−Φw∥2/σ2+λ∥w−w~∥2\norm{\mathbf y+\boldsymbol\varepsilon-\Phi\mathbf w}^2/\sigma^2+\lambda\norm{\mathbf w-\tilde{\mathbf w}}^2 with ε∼N(0,σ2I)\boldsymbol\varepsilon\sim\mathcal N(0,\sigma^2I) and w~∼N(0,λ−1I)\tilde{\mathbf w}\sim\mathcal N(0,\lambda^{-1}I) has the posterior mean and the posterior covariance. Replacing the regression by a neural network, and the random prior vector by a random prior network, gives randomized prior functions.

Further reading

  • I. Osband, D. Russo & B. Van Roy, "(More) efficient reinforcement learning via posterior sampling," Advances in Neural Information Processing Systems 26 (2013).
  • I. Osband, B. Van Roy, D. Russo & Z. Wen, "Deep exploration via randomized value functions," Journal of Machine Learning Research 20(124), 1–62 (2019).
  • I. Osband, C. Blundell, A. Pritzel & B. Van Roy, "Deep exploration via bootstrapped DQN," Advances in Neural Information Processing Systems 29 (2016).
  • I. Osband, J. Aslanides & A. Cassirer, "Randomized prior functions for deep reinforcement learning," Advances in Neural Information Processing Systems 31 (2018).
  • M. Strens, "A Bayesian framework for reinforcement learning," International Conference on Machine Learning (2000).