Skip to content
Ahmed Haroon
← Reinforcement Learning

Exploration

Reward Does Not Reveal What We Have Not Tried

A reinforcement-learning agent maximizes

J(π)=Eτ∼π[∑t=0∞γtrt],J(\pi) =\mathbb E_{\tau\sim\pi} \left[ \sum_{t=0}^{\infty}\gamma^t r_t \right],

but it learns an action's consequences only by taking that action. Exploitation chooses the behavior currently believed to be best. Exploration chooses behavior that may improve what the agent knows.

Sparse reward makes the distinction temporal. Suppose reward requires one particular action at each of LL steps. Uniform random behavior succeeds with probability

P(successful sequence)=(1∣A∣)L.\boxed{ P(\text{successful sequence}) =\left(\frac1{|\mathcal A|}\right)^L }.

If an ϵ\epsilon-greedy policy must explore correctly at every step, the probability is approximately

P(successful exploratory sequence)≈(ϵ∣A∣)L.P(\text{successful exploratory sequence}) \approx \left(\frac{\epsilon}{|\mathcal A|}\right)^L.

Independent action noise therefore becomes exponentially ineffective with the depth of the required behavior.

Shallow exploration asks which single action pays more. Deep exploration asks which coherent strategy eventually reveals reward. The second problem motivates episode-level hypotheses, intrinsic motivation, goals, and reusable skills.

Bandits Isolate the Exploration Tradeoff

A stochastic multi-armed bandit has actions a∈Aa\in\mathcal A with unknown reward distributions

rt∼Rat,r_t\sim R_{a_t},

and mean values

Q(a)=E[r∣a].Q(a)=\mathbb E[r\mid a].

The optimal arm satisfies

a∗∈arg⁡max⁡aQ(a),V∗=Q(a∗).a^*\in\arg\max_aQ(a), \qquad V^*=Q(a^*).

Bandits remove state transitions and delayed credit assignment while retaining uncertainty about which action is best.

After Nt(a)N_t(a) pulls, the empirical mean is

Q^t(a)=1Nt(a)∑τ=1trτ1{aτ=a}.\widehat Q_t(a) =\frac1{N_t(a)} \sum_{\tau=1}^{t} r_\tau\mathbf 1\{a_\tau=a\}.

Pure greed chooses the largest empirical mean. An unlucky early reward can make a suboptimal arm look best, after which greed gathers no evidence capable of correcting itself.

Regret prices exploration

Define the arm gap

Δa=V∗−Q(a)≥0.\Delta_a=V^*-Q(a)\ge0.

Cumulative expected regret is

LT=E[∑t=1T(V∗−Q(at))].L_T =\mathbb E \left[ \sum_{t=1}^{T} (V^*-Q(a_t)) \right].

It decomposes into the cost of each suboptimal arm times how often it is selected:

LT=∑a∈AΔa E[NT(a)].\boxed{ L_T =\sum_{a\in\mathcal A} \Delta_a\,\mathbb E[N_T(a)] }.
See derivation

Replace instantaneous regret by the selected arm's gap:

LT=E[∑t=1TΔat].L_T =\mathbb E\left[ \sum_{t=1}^{T}\Delta_{a_t} \right].

Group time steps by action:

∑t=1TΔat=∑a∈AΔa∑t=1T1{at=a}.\sum_{t=1}^{T}\Delta_{a_t} =\sum_{a\in\mathcal A} \Delta_a \sum_{t=1}^{T}\mathbf 1\{a_t=a\}.
The inner sum is exactly

Taking expectations gives the result.

Sublinear regret,

LT=o(T),L_T=o(T),

implies vanishing average regret LT/T→0L_T/T\to0. Fixed-rate exploration and permanent greed can both suffer linear regret: one wastes actions forever, while the other may never correct an early mistake.

A contextual bandit observes sts_t before acting and learns

Q(s,a)=E[r∣s,a],Q(s,a)=\mathbb E[r\mid s,a],

but actions still do not affect future contexts. It introduces generalization without sequential credit assignment.

Simple Rules Inject Local Randomness

Under the common convention that uniform exploration may also select the greedy action,

πϵ(a∣s)={1−ϵ+ϵ∣A∣,a∈arg⁡max⁡a′Q(s,a′),ϵ∣A∣,otherwise.\pi_\epsilon(a\mid s) = \begin{cases} 1-\epsilon+\dfrac{\epsilon}{|\mathcal A|}, &a\in\arg\max_{a'}Q(s,a'),\\[6pt] \dfrac{\epsilon}{|\mathcal A|},&\text{otherwise}. \end{cases}

GLIE schedules become greedy in the limit while preserving infinite exploration:

Nt(s,a)→∞,πt(a∣s)→1{a∈arg⁡max⁡a′Qt(s,a′)}.N_t(s,a)\to\infty, \qquad \pi_t(a\mid s) \to \mathbf 1\{a\in\arg\max_{a'}Q_t(s,a')\}.

This requires ϵt→0\epsilon_t\to0 slowly enough that exploration does not disappear after finitely many trials.

Boltzmann exploration distinguishes among alternatives by value:

πτ(a∣s)=eQ(s,a)/τ∑a′eQ(s,a′)/τ.\pi_\tau(a\mid s) =\frac{e^{Q(s,a)/\tau}} {\sum_{a'}e^{Q(s,a')/\tau}}.

As τ→0\tau\to0, it becomes greedy; as τ→∞\tau\to\infty, it approaches uniform. Value magnitude is not calibrated uncertainty, however. A confidently poor estimate and an uncertain estimate can receive the same probability.

Optimistic initialization instead starts with

Q0(s,a)≈Rmax⁡1−γ.Q_0(s,a)\approx\frac{R_{\max}}{1-\gamma}.

Greedy action selection tries unvisited actions because their estimates remain high. The optimism is transient, can generalize incorrectly under function approximation, and still does not sustain a coherent multi-step hypothesis.

All three methods perturb individual actions. They are useful baselines, but deep exploration needs uncertainty that persists across time.

Optimism Turns Uncertainty into Value

Upper confidence bounds assign each arm an optimistic score

Ut(a)=Q^t(a)+bt(a),U_t(a)=\widehat Q_t(a)+b_t(a),

then select

at∈arg⁡max⁡aUt(a).a_t\in\arg\max_a U_t(a).

If an optimistic arm is good, it produces reward. If it is poor, sampling shrinks its uncertainty until its score falls.

Assume rewards are σ\sigma-sub-Gaussian. For nn independent samples with mean μ\mu,

P(μ−μ^n≥ε)≤exp⁡(−nε22σ2).P(\mu-\widehat\mu_n\ge\varepsilon) \le \exp\left(-\frac{n\varepsilon^2}{2\sigma^2}\right).

Solving for a failure probability δ\delta gives the one-sided confidence radius

b(n,δ)=2σ2log⁡(1/δ)n.\boxed{ b(n,\delta) =\sqrt{ \frac{2\sigma^2\log(1/\delta)}{n} } }.
See derivation

Set the tail bound equal to δ\delta:

exp⁡(−nε22σ2)=δ.\exp\left(-\frac{n\varepsilon^2}{2\sigma^2}\right) =\delta.

Taking logarithms and rearranging,

ε2=2σ2log⁡(1/δ)n.\varepsilon^2 =\frac{2\sigma^2\log(1/\delta)}{n}.

Since a radius is nonnegative,

ε=2σ2log⁡(1/δ)n.\varepsilon =\sqrt{ \frac{2\sigma^2\log(1/\delta)}{n} }.

For unit-sub-Gaussian rewards, a horizon-aware UCB rule is

at∈arg⁡max⁡a[Q^t(a)+2log⁡TNt(a)].\boxed{ a_t\in\arg\max_a \left[ \widehat Q_t(a) +\sqrt{\frac{2\log T}{N_t(a)}} \right] }.

The bonus decays as Nt(a)−1/2N_t(a)^{-1/2}. A suboptimal arm remains plausible until

log⁡TNT(a)≲Δa,\sqrt{\frac{\log T}{N_T(a)}} \lesssim\Delta_a,

or

NT(a)≳log⁡TΔa2.N_T(a) \gtrsim\frac{\log T}{\Delta_a^2}.

Each pull costs Δa\Delta_a, suggesting regret

LT=O(∑a:Δa>0log⁡TΔa).L_T =O\left( \sum_{a:\Delta_a>0} \frac{\log T}{\Delta_a} \right).

Uncertainty is not an inconvenience added to value—it becomes a temporary source of value that disappears when evidence resolves it.

Thompson Sampling Commits to a Plausible World

Bayesian exploration places a posterior over unknown reward or dynamics parameters:

p(θ∣D)∝p(D∣θ)p(θ).p(\theta\mid\mathcal D) \propto p(\mathcal D\mid\theta)p(\theta).

Thompson sampling draws one plausible model and acts optimally in it:

θ~t∼p(θ∣ht),at∈arg⁡max⁡aQθ~t(a).\widetilde\theta_t\sim p(\theta\mid h_t), \qquad a_t\in\arg\max_aQ_{\widetilde\theta_t}(a).

Beta–Bernoulli updates

For binary rewards,

r∣θ∼Bernoulli⁡(θ),θ∼Beta⁡(α,β).r\mid\theta\sim\operatorname{Bernoulli}(\theta), \qquad \theta\sim\operatorname{Beta}(\alpha,\beta).

After SS successes and FF failures,

θ∣D∼Beta⁡(α+S,β+F).\boxed{ \theta\mid\mathcal D \sim \operatorname{Beta}(\alpha+S,\beta+F) }.
See derivation

Ignoring normalization constants,

p(θ∣D)∝θS(1−θ)Fθα−1(1−θ)β−1=θα+S−1(1−θ)β+F−1.\begin{aligned} p(\theta\mid\mathcal D) &\propto \theta^S(1-\theta)^F \theta^{\alpha-1}(1-\theta)^{\beta-1}\\ &= \theta^{\alpha+S-1} (1-\theta)^{\beta+F-1}. \end{aligned}

This is the kernel of a Beta⁡(α+S,β+F)\operatorname{Beta}(\alpha+S,\beta+F) density.

For each arm, sample

θ~a∼Beta⁡(αa,βa),\widetilde\theta_a \sim\operatorname{Beta}(\alpha_a,\beta_a),

select arg⁡max⁡aθ~a\arg\max_a\widetilde\theta_a, and update only the chosen arm. Exploration decays automatically as poor arms become unlikely under the posterior.

Thompson sampling implements probability matching:

πTS(a∣ht)=P(a=arg⁡max⁡a′Qθ(a′)  |  ht).\boxed{ \pi_{\mathrm{TS}}(a\mid h_t) =P\left( a=\arg\max_{a'}Q_\theta(a') \;\middle|\;h_t \right) }.
See derivation

The selected action is a deterministic function of a posterior sample:

\pi_{\mathrm{TS}}(a\mid h_t) =\mathbb E_{\theta\sim p(\theta\mid h_t)} \left[ \mathbf 1\left{ a=\arg\max_{a'}Q_\theta(a') \right} \right].

The expectation of an indicator is the probability of its event, giving the posterior probability that aa is optimal.

In an MDP, posterior sampling can draw an entire environment

(P~,R~)∼p(P,R∣hk),(\widetilde P,\widetilde R) \sim p(P,R\mid h_k),

plan in it, and follow its optimal policy for a full episode. Posterior Sampling for Reinforcement Learning therefore maintains one coherent hypothesis across many steps:

at∈arg⁡max⁡aQP~,R~∗(st,a).a_t\in\arg\max_aQ^*_{\widetilde P,\widetilde R}(s_t,a).

If the sampled world suggests that a distant corridor is valuable, the policy commits long enough to test that hypothesis. This is deep exploration rather than independently resampled action noise.

Posterior Sampling for Reinforcement Learning\textbf{Posterior Sampling for Reinforcement Learning}Maintain p(P,R∣hk).At the beginning of episode k:(P~k,R~k)∼p(P,R∣hk),πk←PLAN⁡(P~k,R~k),follow πk for the whole episode,update the posterior with the new trajectory.\begin{aligned} &\text{Maintain }p(P,R\mid h_k).\\[0.25em] &\text{At the beginning of episode }k:\\[0.25em] &\qquad (\widetilde P_k,\widetilde R_k) \sim p(P,R\mid h_k),\\[0.25em] &\qquad \pi_k\leftarrow \operatorname{PLAN}(\widetilde P_k,\widetilde R_k),\\[0.25em] &\qquad \text{follow }\pi_k\text{ for the whole episode},\\[0.25em] &\qquad \text{update the posterior with the new trajectory}. \end{aligned}

Exact posterior inference and repeated planning are usually expensive. Bootstrapped Q-heads, Bayesian last layers, and sampled ensembles approximate the same persistent-hypothesis idea in deep RL.

Exploration Bonuses in Large State Spaces

Bandit optimism becomes an augmented reward in an MDP:

r+(s,a)=r(s,a)+rint(s,a).\boxed{ r^+(s,a) =r(s,a)+r_{\mathrm{int}}(s,a) }.

A tabular bonus may use

rint(s,a)∝1N(s,a)r_{\mathrm{int}}(s,a) \propto\frac1{\sqrt{N(s,a)}}

or a faster-decaying 1/N(s,a)1/N(s,a). The optimistic Q update is

Q(s,a)←Q(s,a)+α[r+rint(s,a)+γmax⁡a′Q(s′,a′)−Q(s,a)].Q(s,a)\leftarrow Q(s,a)+\alpha \left[ r+r_{\mathrm{int}}(s,a) +\gamma\max_{a'}Q(s',a') -Q(s,a) \right].

Exact counts fail for pixels and continuous states because almost every observation is unique. Novelty must generalize across similar observations.

Density-model pseudo-counts

Let a density model assign probability

ρ=pθ(s)\rho=p_\theta(s)

before learning from ss, and

ρ′=pθ′(s)\rho'=p_{\theta'}(s)

afterward. Define imaginary tabular quantities by

ρ=N^(s)n^,ρ′=N^(s)+1n^+1.\rho=\frac{\widehat N(s)}{\widehat n}, \qquad \rho'=\frac{\widehat N(s)+1}{\widehat n+1}.

Solving gives

N^(s)=ρ(1−ρ′)ρ′−ρ.\boxed{ \widehat N(s) =\frac{\rho(1-\rho')}{\rho'-\rho} }.
See derivation

From ρ=N^/n^\rho=\widehat N/\widehat n,

N^=n^ρ.\widehat N=\widehat n\rho.

Substitute into the post-update probability:

ρ′=n^ρ+1n^+1.\rho' =\frac{\widehat n\rho+1}{\widehat n+1}.

Rearranging,

n^=1−ρ′ρ′−ρ.\widehat n =\frac{1-\rho'}{\rho'-\rho}.

Multiplying by ρ\rho yields

N^(s)=ρ(1−ρ′)ρ′−ρ.\widehat N(s) =\frac{\rho(1-\rho')}{\rho'-\rho}.

A large probability increase means the observation taught the model a lot, producing a small pseudo-count and a large novelty bonus. If the model barely changes, the state behaves as familiar.

Prediction-error novelty

Random Network Distillation fixes a random target fξf_\xi and trains a predictor f^ϕ\widehat f_\phi:

rint(s)=∥f^ϕ(s)−fξ(s)∥22.\boxed{ r_{\mathrm{int}}(s) =\|\widehat f_\phi(s)-f_\xi(s)\|_2^2 }.

Visited observations become easy to predict, while unfamiliar observations retain error. A forward model can similarly reward

∥fϕ(s,a)−s′∥22.\|f_\phi(s,a)-s'\|_2^2.

Prediction error is only an uncertainty proxy:

error=epistemic uncertainty+aleatoric noise+misspecification+optimization error.\text{error} =\text{epistemic uncertainty} +\text{aleatoric noise} +\text{misspecification} +\text{optimization error}.

An agent rewarded for error may stare forever at an inherently unpredictable screen—the noisy-TV problem. Learning progress and posterior information gain better target reducible uncertainty.

Generalization Changes What a Count Means

With function approximation, one observation changes predictions at many state-action pairs. Uncertainty depends on coverage in representation space, not literal repetition.

Consider a linear contextual model

rt=θ⊤xt+ηt,xt=ϕ(st,at).r_t=\theta^\top x_t+\eta_t, \qquad x_t=\phi(s_t,a_t).

Ridge regression gives

θ^t=At−1bt,\widehat\theta_t=A_t^{-1}b_t,

where

At=λI+∑i=1t−1xixi⊤,bt=∑i=1t−1xiri.A_t=\lambda I+\sum_{i=1}^{t-1}x_ix_i^\top, \qquad b_t=\sum_{i=1}^{t-1}x_ir_i.

If the parameter lies in the confidence ellipsoid

∥θ−θ^t∥At≤βt,\|\theta-\widehat\theta_t\|_{A_t}\le\beta_t,

then an optimistic reward estimate is

Ut(s,a)=θ^t⊤ϕ(s,a)+βtϕ(s,a)⊤At−1ϕ(s,a).\boxed{ U_t(s,a) =\widehat\theta_t^\top\phi(s,a) +\beta_t \sqrt{ \phi(s,a)^\top A_t^{-1}\phi(s,a) } }.
See derivation

Let x=ϕ(s,a)x=\phi(s,a). Then

θ⊤x=θ^t⊤x+(θ−θ^t)⊤x.\theta^\top x =\widehat\theta_t^\top x +(\theta-\widehat\theta_t)^\top x.

By Cauchy–Schwarz in the AtA_t geometry,

(θ−θ^t)⊤x≤∥θ−θ^t∥At∥x∥At−1.(\theta-\widehat\theta_t)^\top x \le \|\theta-\widehat\theta_t\|_{A_t} \|x\|_{A_t^{-1}}.

Apply the confidence bound:

θ⊤x≤θ^t⊤x+βtx⊤At−1x.\theta^\top x \le \widehat\theta_t^\top x +\beta_t\sqrt{x^\top A_t^{-1}x}.

The bonus is large in feature directions poorly covered by previous data. It is the geometric analogue of 1/N(a)1/\sqrt{N(a)}.

Deep representations make this geometry nonstationary and their uncertainty harder to calibrate. Ensembles and bootstrapped heads provide useful approximations, but they do not inherit tabular guarantees automatically.

Curiosity Values Information

State-marginal entropy measures breadth of visitation:

H(dπ)=−Es∼dπ[log⁡dπ(s)].\mathcal H(d_\pi) =-\mathbb E_{s\sim d_\pi} [\log d_\pi(s)].

Maximizing it encourages coverage, although not every reachable state is equally relevant.

Intrinsic rewards differ in what they call interesting:

rarity:rint(s)∝1/N(s),surprise:rint(s)=−log⁡pϕ(s),prediction error:rint=∥fϕ(s,a)−s′∥2,learning progress:rint=ℓbefore−ℓafter.\begin{aligned} \text{rarity:}&\quad r_{\mathrm{int}}(s)\propto1/\sqrt{N(s)},\\ \text{surprise:}&\quad r_{\mathrm{int}}(s)=-\log p_\phi(s),\\ \text{prediction error:}&\quad r_{\mathrm{int}}=\|f_\phi(s,a)-s'\|^2,\\ \text{learning progress:}&\quad r_{\mathrm{int}}=\ell_{\mathrm{before}}-\ell_{\mathrm{after}}. \end{aligned}

Information gain directly measures how much an observation changes beliefs about an uncertain model parameter Θ\Theta:

IG⁡(x)=DKL(p(θ∣D,x) ∥ p(θ∣D)).\boxed{ \operatorname{IG}(x) =D_{\mathrm{KL}} \left( p(\theta\mid\mathcal D,x) \,\|\, p(\theta\mid\mathcal D) \right) }.

Before observing the outcome, the expected information gain of an action is

Ex∼p(x∣a,D)[DKL(p(θ∣D,x) ∥ p(θ∣D))].\mathbb E_{x\sim p(x\mid a,\mathcal D)} \left[ D_{\mathrm{KL}} \left( p(\theta\mid\mathcal D,x) \,\|\, p(\theta\mid\mathcal D) \right) \right].

This equals conditional mutual information:

Ex[IG⁡(x)]=I(Θ;X∣D).\boxed{ \mathbb E_x[\operatorname{IG}(x)] =I(\Theta;X\mid\mathcal D) }.

Curiosity should reward observations that reduce epistemic uncertainty, not outcomes that remain surprising because of irreducible aleatoric noise.

Choosing an Exploration Strategy

The right mechanism depends on both uncertainty and temporal depth.

  • Use ϵ\epsilon-greedy or Boltzmann sampling as cheap local baselines.
  • Use UCB when calibrated confidence sets or meaningful counts are available.
  • Use Thompson sampling when a posterior can represent coupled uncertainty and a sampled hypothesis can persist.
  • Use pseudo-counts or RND when state spaces are large and novelty must generalize.
  • Use information gain or learning progress when stochastic distractions make raw prediction error unreliable.

Exploration always depends on representation. A count, posterior, or density model declares two observations similar according to its features. Bad features turn principled formulas into misleading bonuses.

The progression is

random actions⟶uncertainty-aware actions⟶coherent hypotheses⟶information-seeking behavior.\boxed{ \text{random actions} \longrightarrow \text{uncertainty-aware actions} \longrightarrow \text{coherent hypotheses} \longrightarrow \text{information-seeking behavior} }.

When useful behavior must persist beyond a single decision, exploration can be lifted into temporally extended goals and skills. That is the subject of skill learning.

Exploration is therefore not synonymous with randomness. Useful exploration selects behavior whose outcomes can change what the agent knows.