Bandits and exploration

Child of Topic: rl. How an agent decides between using what it knows and finding out more: bandit algorithms and their regret, contextual bandits and A/B tests in production, and exploration in full RL. Simulations run on the page's seeded engine, checked against Python; sources linked inline. Data as of October 2026. Reading: 27 min, plus 9 in closed details.

Bandits and exploration: the idea

An agent only sees the reward of the action it takes, so it must spend some reward finding out; random exploration pays the same price every step forever (linear regret), while exploring where its estimates are uncertain makes the price shrink, growing only like the logarithm of time, which is the proven floor.

The same evidence, three choices; the same arms, four very different bills

  1. The evidence. After 65 pulls of three 0/1 arms (illustrative counts), each arm's pulls are piled in front of it, wins in green: arm A has 25 wins in 40 pulls (estimate 0.63), arm B 2 wins in only 5 (0.40), arm C 6 in 20 (0.30). The bars behind are the estimates on a value scale. The dots streaming from the agent are its pulls landing on each arm; the green dots flowing back are the wins that make up each estimate.
  2. Greedy pulls A. A has the best estimate, so greedy pulls it. Nothing in that rule asks how much evidence stands behind each estimate: B's five pulls count as much as A's forty.
  3. UCB pulls B. UCB adds a bonus √(2 ln t / n) that is large where n is small (the translucent green blocks). B's estimate (0.40) is weak and its upper bound Q + √(2 ln t / n) is the highest, 1.69 against A's 1.08 and C's 0.95, so UCB pulls B to find out.
  4. Thompson sampling draws. Thompson sampling keeps a Beta posterior per arm (the shapes on the glass plates: narrow for A, wide for B), draws a plausible mean for each and pulls the highest draw: A 83%, B 17%, C 0.7% of the time (100,000 seeded draws). It explores B in proportion to the chance that B is best.
  5. The bill. Expected regret on four 0/1 arms with means 0.9, 0.8, 0.6, 0.5 (the regret chart's far preset in section 4), 200 runs, over 10,000 pulls: greedy 650 and ε-greedy (ε = 0.1) 213 grow in a straight line; UCB1 170 and Thompson sampling 20 bend over. Derived on this page's engine (src/make_data.mjs); the arm means are illustrative.

You need: the vocabulary of Topic: rl (reward, action value Q, policy). Section 6 assumes states and the Bellman equation, taught on Dynamic programming.

Arm
one of the k actions of a bandit; its rewards come from a fixed, unknown distribution with mean μa (or q*(a)).
Regret
reward lost against always pulling the best arm: the pulls of each worse arm times its gap Δa = μ* − μa.
Exploration bonus
an addition to an action's estimate that is large where the agent knows little (UCB's √(ln t / N), count bonuses, RND).
Posterior
the agent's belief about an arm's mean after the rewards it has seen; Thompson sampling acts on one draw from it.
Contextual bandit
a bandit that sees features (a user, a page) before each choice and learns a policy from contexts to actions.
Intrinsic reward
reward the agent pays itself for novelty or surprise, added to the task's reward to drive exploration in large state spaces.
StrategyHow it exploresKnobRegret as time T growsWhere it shows up
GreedyNever on purposenoneLinear: it can lock onto a worse arm foreverThe baseline that fails
ε-greedyA random action a fraction ε of the timeε (or a decay schedule)Linear for fixed ε; logarithmic with a tuned decay (εn-greedy)DQN and most deep value methods
Optimistic initial valuesStart every estimate high; disappointment drives tryingQ₀Not a general guarantee (only explores at the start)Tabular tricks; R-MAX in full RL
UCBBonus for uncertainty: Q + c √(ln t / N)cLogarithmic (UCB1, proved for rewards in [0, 1])Agent57's policy chooser; MCTS (UCT)
Gradient banditSamples from a softmax over learned preferencesstep αDepends on α; no log guarantee hereThe bandit version of policy gradients
Thompson samplingActs on one draw from its posterior beliefthe priorLogarithmic, matching the lower bound for Bernoulli armsAds, recommendation, adaptive trials
A/B test (explore, then commit)Splits traffic evenly for a fixed time, then ships the winnertest length mPays m·Δ while the test runs; with m tuned to the gap, of order √T in the worst caseProduct experiments
LinUCB (contextual)UCB on a linear model of reward given featuresαSublinear under its linear modelNews recommendation (Yahoo!), Decision Service
Count bonuses, RND, Go-ExploreReward novelty, or return to promising statesbonus scaleTheory only in the tabular caseHard-exploration Atari (Montezuma's Revenge)

Each row is derived and sourced in the section that covers it. Exploration is also one of the axes of the Taxonomy tab on Topic: rl.

1The exploration-exploitation trade-off

Exploitation takes the action believed best, maximising reward now; exploration takes one that looks worse, to buy information that may pay later (Silver's examples: your favourite restaurant or a new one, the best-known advert or a different one; Silver, Lecture 9). Pure exploitation gets stuck on the first decent option, because it never collects the evidence that something else is better; pure exploration never cashes in.

What makes this special to reinforcement learning: in supervised learning the labels arrive whatever the model predicts, but here the agent's own choices decide which data it sees, so a wrong belief about an action is never corrected if the agent stops taking it. A multi-armed bandit isolates exactly this: one situation repeated, k actions with unknown mean payoffs, no state and no delay, so nothing is left but exploration (Sutton and Barto, chapter 2).

The trade-off is "solved" in theory: Bayes-optimal play and the Gittins index (1 min)

With a prior over the arms and a known horizon, the best possible policy is the Bayes-optimal one, computed by planning over all future beliefs. It is almost never computed, because the tree of possible futures explodes: Sutton and Barto note that for 1,000 steps of a two-armed bandit with two possible rewards the tree would have 22000 leaves (§2.10). For the discounted, infinite-horizon case, Gittins (1979) showed that the Bayes-optimal policy reduces to an index computed per arm. Everything else on this page is a cheaper rule that gets close.

2The k-armed bandit and action values

At each step t the agent picks an action At from k options and receives a reward Rt from that action's distribution. An action's value is its expected reward, q*(a) = E[Rt | At = a]; the agent keeps an estimate Qt(a), usually the sample average, updated without storing past rewards:

Qn+1 = Qn + αn [Rn − Qn],   αn = 1/n (sample average) or α (constant)
Rn − Qn
the error: how surprising the new reward is. The form NewEstimate ← OldEstimate + StepSize [Target − OldEstimate] recurs through all of RL, from TD learning to the deep methods (Sutton and Barto §2.4, eq. 2.3)
constant α
unrolls to an exponential recency-weighted average, Qn+1 = (1 − α)n Q1 + Σi α (1 − α)n−i Ri (§2.5, eq. 2.6): weights decay geometrically with age and sum to 1

Predict: at α = 0.1, how much weight does the oldest of 20 rewards get, against 0.05 for the sample average? Then drag the α slider.

When a step-size schedule converges: the stochastic approximation conditions (under 1 min)

A schedule αn converges to the true value when Σ αn = ∞ (steps large enough to overcome any start) and Σ αn2 < ∞ (small enough to settle). The sample average's 1/n meets both; a constant α fails the second, which is exactly what lets it keep tracking a moving target (§2.5, eq. 2.7). The initial estimate Q1 is a bias: with sample averages it disappears the first time an arm is pulled; with a constant α it is permanent, though decreasing.

A constant step forgets old rewards; the sample average never does

Blue: sample average, every reward 1/20 = 0.05 and the initial guess erased. Orange: constant α, weight α(1 − α)20−i on reward i and (1 − α)20 on the initial guess Q₁. At α = 0.1 the oldest reward gets 0.014 and Q₁ still 0.12: the constant step tracks an arm whose mean drifts (a nonstationary problem) but keeps a shrinking bias from its start, which is the lever behind optimistic initial values (§2.6). The testbed tab's Nonstationary preset runs both on drifting arms: 10-armed testbed.

3The strategies

Five ways to choose, run on the same five arms with the same pre-drawn rewards, so they differ only in the choices they make. Predict before the stage plays: which strategy ends with the least regret after 300 pulls, and which one's regret line never bends?

Five strategies on the same five arms, the same reward for the same arm at the same step (seed 3)

  1. Same arms, same rewards. Five arms with true means 0.2, 1.0, −0.4, 1.5, 0.6 (illustrative; arm 4 is the best; its column is tinted on the floor), one row per strategy. Every strategy reads the same pre-drawn reward for the same arm at the same step, so the rows differ only in their choices. A bar's height is the share of that row's pulls that went to that arm; the block at the right end of each row is its total regret so far. While a stretch of pulls plays, its pulls fall as dots onto the arms they went to.
  2. Pulls 1 to 5. Greedy and ε-greedy start on arm 1 (ties go to the first arm); its first reward is positive, so its estimate (0.43) beats the untried arms' 0 and both pull arm 1 five times. Optimistic and UCB try every arm once. Thompson pulls by its draws, none of them yet on arm 4.
  3. Pull 30. Greedy is still only on arm 1 (estimate 0.30, still above the untried arms' 0), and so is ε-greedy: its one random pull so far (pull 9) happened to pick arm 1 as well. Optimistic has tried every arm 4 to 7 times, each disappointing in turn. UCB already gives arm 4 16 of its 30 pulls. Thompson favours arm 2 (20 pulls; mean 1.0, good but not best) and has tried arm 4 only twice.
  4. Pull 100. ε-greedy's random pulls found arm 4 (20 pulls, estimate 1.47) and its greedy pulls took over. Greedy has paid 130 of regret, 1.3 on every pull, and never collects the evidence that another arm is better. UCB has 60 of 100 on arm 4 (regret 41.0), Thompson has switched to arm 4 (57 pulls, regret 29.1), optimistic is still spread out (28 on arm 4, regret 71.2).
  5. Pull 300: the bills. Greedy 390, a straight line; ε-greedy 86.4, still paying on bad arms one pull in ten at the same rate as on the first day; optimistic 98.8 (its optimism used up, from here it is greedy with a constant step size); UCB 50.6 and Thompson 35.6, each with 250 of 300 pulls on arm 4. Rarely pulled arms keep a large bonus or a wide belief, so UCB and Thompson still try them now and then, less often as the evidence grows.

Greedy and ε-greedy

Greedy always takes argmaxa Qt(a) and locks onto whichever arm looked good first. ε-greedy takes the greedy action with probability 1 − ε and otherwise picks uniformly among all m actions, so the greedy action has probability 1 − ε + ε/m: with ε = 0.1 and m = 4 that is 0.9 + 0.025 = 0.925, and each other action 0.025 (Silver, Lecture 5). Every estimate converges, but ε-greedy keeps picking bad arms at the same rate forever, so its regret grows linearly. Decaying ε towards 0 while still trying every action infinitely often is GLIE (greedy in the limit with infinite exploration), the condition under which SARSA and Monte Carlo control converge; it is used on Model-free prediction and control.

Optimistic initial values

Start every estimate far above any plausible reward (Sutton and Barto use +5 when true values are drawn from N(0, 1)). Whatever greedy tries disappoints it, so it moves on, and every arm is tried several times before the estimates settle (§2.6). It needs a constant step size (a sample average erases the optimism on the first pull), and the book calls it "a simple trick that can be quite effective on stationary problems, but it is far from being a generally useful approach": its drive is spent at the start. Made principled, it is R-MAX in full RL (section 6).

Upper confidence bound (UCB)

ε-greedy explores indiscriminately; UCB prefers arms that could plausibly be the best, given how uncertain their estimates are (§2.7, eq. 2.10):

At = argmaxa [ Qt(a) + c √( ln t / Nt(a) ) ]
Nt(a)
how often a has been pulled before t; an unpulled arm counts as maximising
√(ln t / N)
shrinks each time a is pulled and grows slowly while it is not, so every arm is eventually retried, ever more rarely
c
the confidence level; UCB1 (Auer et al. 2002) uses x̄j + √(2 ln n / nj), that is c = √2, for rewards in [0, 1] (the hero's left panel)

This is optimism in the face of uncertainty: act as if each arm is as good as it plausibly could be; either the optimism was right and you collect, or the pull shrinks the bonus. The book's caution: UCB "is more difficult than ε-greedy to extend beyond bandits", to nonstationary problems and to large state spaces where counting visits is not practical; section 6 is about how deep RL works around that.

Thompson sampling

Keep a posterior distribution over each arm's mean; at every step draw one sample from each and pull the arm whose sample is highest, then update that arm's posterior. An arm is pulled with exactly the probability that it is the best under the current belief ("probability matching"). For 0/1 rewards with a uniform prior the posterior is Beta(1 + successes, 1 + failures), so the algorithm is two counters per arm and one Beta draw. Uncertain arms have wide posteriors and sometimes draw high; a bad arm's posterior narrows below the best arm's and it stops being chosen. It is the oldest method here: Thompson (1933) proposed it "for allocating experimental effort in two-armed bandit problems arising in clinical trials" (Russo et al., tutorial), and Sutton and Barto note that it "often performs similarly to the best of the distribution-free methods" (§2.10).

Gradient bandits: the one-state policy gradient (1 min)

Instead of estimating values, learn a preference Ht(a) per action and act by softmax, πt(a) = eHt(a) / Σb eHt(b). After each reward (§2.8, eq. 2.12):

H(At) ← H(At) + α (Rt − R̄t)(1 − πt(At)),   H(a) ← H(a) − α (Rt − R̄t) πt(a) for a ≠ At
R̄t
the baseline: the average reward so far (the book's experiments include Rt itself, per its footnote on p. 37)
Rt − R̄t
better than usual raises the chosen action's probability; worse lowers it; the others move the opposite way

The box in §2.8 proves that the expected update equals the gradient of expected reward, so this is stochastic gradient ascent: the one-state case of the policy gradient (REINFORCE with a baseline). The baseline does not change the expected update, only its variance; Figure 2.5 shows what happens without it when all rewards are shifted by +4 (10-armed testbed, Fig. 2.5). The general case lives on Policy gradients and actor-critic (section 2 for the theorem, section 4 for baselines).

Across 2,000 tasks. The 10-armed testbed tab reruns Sutton and Barto's Figures 2.2 to 2.6 live, with Thompson sampling added and the nonstationary exercise. Its defaults reproduce the book's printed numbers independently: the best possible average reward is the expected maximum of ten standard normals, 1.539 by integration (book: "about 1.54"); greedy settles near 1.0 per step and finds the best arm in about 35% of tasks (book: "only about 1" and "approximately one-third"); ε = 0.1 stays below its 91% ceiling (src/recompute.py, 2,000 tasks).

Pull by pull: what each strategy believes and why it picks the arm it picks

Left: each arm's estimate (bar) against its true mean (the tick across each arm: 0.2, 1.0, −0.4, 1.5, 0.6; illustrative); the arm about to be pulled is orange. UCB adds its upper bound (green whisker). Thompson shows its belief about each mean, a normal posterior drawn sideways (prior N(0, 1), noise variance 1 assumed known), and the circle is this step's draw from it. Right: total regret of all five on this stream. Estimates are sample averages, except the optimistic agent's constant step 0.1 (Figure 2.3's setting). Seeds differ: greedy is sometimes lucky, never reliable; ε-greedy's regret line never bends.

4Regret, and the floor under it

Testbed curves average over a family of tasks; theory asks how much a strategy loses on any task against an oracle that always pulls the best arm. That loss is the regret, and it splits into pulls wasted on each bad arm times its gap:

Regret(T) = T μ* − E[ Σt=1..T μAt ] = Σa Δa E[Na(T)]
μ*
the best arm's mean; Δa = μ* − μa is arm a's gap
Na(T)
how often arm a is pulled in T steps (the regret decomposition, Lattimore and Szepesvári, Lemma 4.5)

A strategy that pulls a bad arm a fixed fraction of the time (greedy stuck on it, ε-greedy with fixed ε) has regret growing linearly in T. How slowly can it grow? The Lai and Robbins lower bound (Lai and Robbins 1985): any strategy that is good on every instance (regret o(Ta) for every a > 0) must pull each suboptimal arm at least about ln T / KL(pa, p*) times, so

lim infT→∞ Regret(T) / ln T ≥ Σa: Δa > 0 Δa / KL(pa, p*)
KL(pa, p*)
the Kullback-Leibler divergence between arm a's reward distribution and the best arm's: how much each pull tells them apart. For 0/1 rewards KL(p, q) = p ln(p/q) + (1 − p) ln((1 − p)/(1 − q))

To be sure an arm is worse you must pull it until the evidence rules it out, which takes more pulls the surer you need to be (ln T) and fewer the more distinguishable the arms (KL). The bound is asymptotic: it fixes the slope against ln T, not the regret at any finite T. (The original is paywalled; the statement follows Auer et al. 2002, p. 236: "IE[Tj(n)] ≥ (ln n)/D(pj||p*) asymptotically".)

Predict: on far arms the bound's constant drops from 12.28 to 4.00. Does every method's regret fall with it? Switch presets to check.

Who reaches the floor. UCB1 is logarithmic after any number of plays for rewards in [0, 1], but the authors note its leading constant "8/Δi2 is worse than the corresponding constant 1/D(pj||p*) in Lai and Robbins' result" (Auer et al. 2002, Theorem 1). Thompson sampling had no regret analysis for almost eighty years; Kaufmann, Korda and Munos (2012) gave "the first finite-time analysis that matches the asymptotic rate given in the Lai and Robbins lower bound" for 0/1 rewards, so it is asymptotically optimal there. KL-UCB builds its confidence bound from the KL divergence itself and is the UCB-family method that closes the gap (Lattimore and Szepesvári, §10.2).

The finite-time bounds, and two other ways to score a bandit (2 min)
  • UCB1's bound: regret at most 8 ΣΔi>0 (ln n)/Δi + (1 + π²/3) Σ Δj after any number of plays n (Auer et al. 2002, Theorem 1).
  • εn-greedy: ε-greedy with εn = min(1, cK/(d²n)), where d is a lower bound on the gap, is also logarithmic (Auer et al., Theorem 3); it needs d, which you do not know in practice.
  • Thompson sampling's first proof: Agrawal and Goyal (2012) proved logarithmic regret "for the first time".
  • Thompson below the line is not a contradiction. The bound constrains the slope as T grows without limit; on two arms 0.6 and 0.5 the same engine's Thompson slope rises from 3.2 (103 to 104 pulls) to 4.2 (105 to 106), 20 runs, towards the bound's 4.9 (src/README.md).
  • Worst case. The bound above is instance-dependent: it blows up as a gap shrinks, even though tiny gaps cost little per pull. Over all instances, for any policy there is one with means in [0, 1] whose regret is at least (1/27) √((k − 1)n) (Lattimore and Szepesvári, Theorem 15.2): a square root of time, because an adversary can choose gaps of about √(k/n), too small to detect yet still costly every pull.
  • Bayesian regret (expected regret under a prior, where the Gittins index is optimal for discounted problems) is a third yardstick. Which one a paper optimises changes which algorithm "wins".

Where UCB went next. The same index applied at every node of a search tree is UCT (Kocsis and Szepesvári 2006), the selection rule of Monte Carlo tree search and, with a learned prior, of AlphaGo's search: see Model-based RL and planning. Agent57 chooses among its exploration policies with "a simplified sliding-window UCB with εUCB-greedy exploration" over the last 160 episodes (Badia et al. 2020), because a plain UCB "will not be able to adapt to the changes of the reward through time".

Linear regret curves upward on a log axis; Thompson sampling stays below the Lai and Robbins line

At 10,000 pulls, 200 runs, close arms: greedy 607, ε-greedy 193, UCB1 261, Thompson 55; far arms: 650, 213, 170 and 20 (src/make_data.mjs, the page's engine). The Lai and Robbins constant is 12.28 per unit of ln T on close arms and 4.00 on far ones, from the formula above. On close arms UCB1 trails ε-greedy at this horizon: its constant is large when gaps are small.

5Contextual bandits, A/B tests, and where bandits run in production

A contextual bandit sees a context first (a user's features, the page being viewed), picks an action, and sees the reward of that action only; the goal is a policy from contexts to actions. Sutton and Barto call it associative search and place it exactly between the bandit and full RL (§2.9). It is the most deployed form of RL, because many products face exactly this loop: show something, see a click or not, never see what the other options would have earned.

What a bandit does not do
A bandit's action does not change the next context. If showing an article changes what the user does next week, or a treatment changes the patient's later state, the problem is full RL with delayed consequences, and a bandit optimising the immediate click can be confidently wrong about the long run.

What each step up adds: a situation to recognise, then consequences that last

Bandit
pull arm a→reward of a↺ same situation

One situation, repeated. Only exploration is left.

Contextual bandit
context xt→action a→reward of a only

The next context arrives whatever the agent did. Learn which action suits which context.

Full RL (an MDP)
state st→action a→reward+next state depends on a

Actions have delayed consequences: credit assignment and planning (Dynamic programming).

LinUCB, and evaluating a policy offline

Li, Chu, Langford and Schapire (2010) model each article's click probability as linear in a feature vector xt,a of user and article, fit by ridge regression, and add an upper-confidence width (their eq. 5):

at = argmaxa ( xt,a⊤ θ̂a + α √( xt,a⊤ Aa−1 xt,a ) )
Aa
= I + Σ x x⊤ over the contexts where a was shown: how much evidence there is in each feature direction
θ̂a
= Aa−1 ba, with ba = Σ (reward) x: the ridge-regression estimate
√(x⊤A−1x)
the standard deviation of the prediction in this context's direction; it plays the part of √(ln t / N) in UCB

On the Yahoo! Front Page Today Module, with "over 33 million events", LinUCB gave "a 12.5% click lift compared to a standard context-free bandit algorithm, and the advantage becomes even greater when data gets more scarce". Their second contribution is still the standard way to test a policy without shipping it: replay logged traffic in which articles were chosen uniformly at random, keep only the events where the logged article matches the one the new policy would choose, and average their clicks; because the logging was random, this "can provide provably unbiased evaluations" (Li, Chu, Langford and Wang 2011).

Replay evaluation keeps about one logged event in k, and those are an unbiased sample

#ContextLogged article (uniform)ClickNew policy picksKept?
1sport, mobileB0Ano
2news, desktopA1Ayes
3sport, desktopB1Cno
4news, mobileA0Bno
5sport, mobileA1Ayes
6news, desktopC1Ano
7sport, desktopC0Cyes
8news, mobileC0Bno
9sport, mobileB1Ano

Nine logged events with three articles shown uniformly at random (illustrative). The new policy agrees with the log on 3 events (one in k = 3), with 2 clicks: its estimated click rate is 2/3. Clicks on events it would not have shown (event 6) say nothing about it, and with a non-random logging policy you would need its propensities (inverse propensity weighting) instead.

A/B tests are a bandit strategy, and usually not the cheapest

The classic product experiment splits users into two groups (Lattimore and Szepesvári's example: two groups of 10,000), shows each a version, and ships the winner. In bandit terms that is explore-then-commit (ETC): pull each arm m times, then commit to the one that looked best. Its regret has exactly two parts, the test's cost and the risk of shipping the wrong version (Lattimore and Szepesvári, Theorem 6.1 and eq. 6.4):

Rn ≤ m Δ + (n − 2m) Δ · P(wrong winner),   P(wrong winner) ≤ exp(−m Δ2 / 4)
m Δ
the visitors sent to the worse version during the test, times the gap: paid in full however obvious the difference becomes
(n − 2m) Δ P(wrong)
everyone after the test, if the test picked the worse version; a longer test lowers this and raises the first term
tuning m
needs the gap Δ, "seldom reasonable to assume" known; with m tuned the regret is at most Δ + C√n, and with m chosen from n alone it is O(n2/3) (the book's eqs. 6.5 to 6.7 and Exercise 6.5)

Predict: conversion rates 10% and 12%, the test runs 2,000 visitors per version. Which design loses fewer conversions, and which knows the difference more precisely when the test ends?

Lattimore and Szepesvári put the difference in purpose plainly: "In traditional A/B testing, the objective of the statistician is to decide which website is better. When using a bandit algorithm, there is no need to end the trial" (§1.2). The same tension is sharpest in clinical trials, below.

The same 20,000 visitors under an A/B test and under Thompson sampling

Share of each 500 visitors sent to the worse version
Conversions lost against always showing the better one

Rates 10% and 12% and the test length are illustrative; 1,000 runs, each A/B run and Thompson run seeing the same visitors (visitor t converts on a version when one shared uniform draw falls below its rate). The A/B test loses 45 conversions, 40 of them (2,000 × 0.02) during the test, and ships the worse version with probability 2.15% (exact, from two binomials; simulated 1.7%; the formula above then gives 46.9). Thompson sampling with Beta(1, 1) priors loses 29, because it shifts traffic as soon as the evidence leans. The price: at 4,000 visitors it has shown the worse version 828 times instead of 2,000, so its 95% interval on the difference is ±2.3 points against ±1.9. A bandit maximises reward during the experiment; an A/B test maximises what you learn at its end (src/make_data.mjs).

Where bandits are used

  • Recommendation and content: Yahoo! news (above). Microsoft's Decision Service, a general contextual-bandit system, reported "two live production deployments for content recommendation that achieved click-through improvements of 25-30%, another with 18% revenue lift in the landing page" (Agarwal et al. 2016).
  • Advertising: Bing's adPredictor paper proposes that instead of always feeding the expected click rate to the auction, "the system can sample from the posterior weight distribution", an idea it traces to Thompson, which has "the effect of bubbling up ads about whose CTR the system has a high degree of uncertainty left" (Graepel et al. 2010, §5; the paper says "can", not that this was the deployed default). Yahoo!'s Chapelle and Li (2011) found on display ads and news that "Thompson sampling achieves state-of-the-art results, and in some cases significantly outperforms other alternatives like UCB", which revived the method.
  • Clinical trials: the field's origin (Thompson 1933) and its sharpest tension. Assigning more patients to the arm that looks better is an ethical gain, but it weakens the trial's statistical power (the A/B card's interval, in medicine): Villar, Bowden and Wason (2015) find bandit designs "offer significant advantages, in terms of assigning more patients to better treatments, and severe limitations, in terms of their resulting statistical power", and propose a rule that keeps power. The cautionary example is the 1985 ECMO trial, which used randomised play-the-winner: one infant was assigned to conventional treatment and died, eleven to ECMO and all survived (Bartlett et al. 1985), a result too lopsided for many to accept as evidence.
  • Inside other learners: Agent57's policy chooser and UCT's tree search (section 4).

6Exploration in full RL, in brief

With states, an exploratory action's payoff may only show up many steps later, after a specific sequence of further actions. Three things get harder:

  • Dithering is exponentially slow. If a reward sits at the end of a chain of N decisions where only one of two actions keeps you on track, a uniformly random policy reaches it with probability 2−N per attempt, so it needs about 2N attempts derived. What is needed is deep (temporally extended) exploration: "Unlike dithering strategies such as epsilon-greedy exploration, bootstrapped DQN carries out temporally-extended (or deep) exploration; this can lead to exponentially faster learning" (Osband et al. 2016).
  • Sparse rewards give no gradient. If almost every episode returns 0, every action looks the same until something succeeds by chance.
  • Distractors trap exploiters. A small nearby reward is found first, and a greedy-ish learner stops looking for the larger one far away: greedy on the testbed, scaled up.

The stage puts all three in one small world: a 14 × 7 grid, a 0.1 reward four steps from the start, a +1 reward thirteen steps away, 60 steps per episode, tabular Q-learning, run three ways. Predict: which of the three reaches the +1 in all 20 seeds?

One sparse-reward world, three ways to explore, 500 episodes each (seed 1)

  1. The world. Start S on the left edge, a 0.1 reward four steps away, the +1 thirteen steps away on the far right; both end the episode, and an episode stops after 60 steps. Q starts at 0 everywhere and ties are broken at random, so the first episodes are random walks; ε = 0.1.
  2. Episode 1. A 39-step random walk over 11 cells that ends on the 0.1. Whichever reward a walk hits first starts to pull the greedy policy towards it.
  3. Episode 10. The 0.1 has won: the episode goes straight to it in four steps. 16 cells visited so far; the bars near the start grow and nothing else does.
  4. Episode 50. Still 31 of 98 cells. Hitting the +1 needs at least 13 steps in the right direction, and exploration that is random at each step is shallow: one random action in ten only wobbles around the path to the 0.1.
  5. Episode 200. 37 cells, the +1 never seen. The agent is not wrong about anything it has tried; it has simply stopped trying anything far away.
  6. Episode 500. It found the +1 once, by chance, in episode 493 (64 cells visited). Whether one discovery wins depends on how far the value has to propagate before the small reward's pull takes over.

Bar height: how often each cell has been entered so far (log scale); orange dots: that episode's path, walked from the start. Q-learning with step 0.5, γ = 0.95, ties broken at random; ε = 0.1 in the first two modes. All settings illustrative, chosen so the small reward is a real trap. Over 20 seeds, 2 of 20 ε-greedy runs reach +1, against 20 of 20 with the count bonus and 20 of 20 with optimistic starts (table above; the page's Python reference src/recompute.py agrees). Optimism is faster than the bonus because the bonus agent's Q starts at 0, so the bonus has to be collected before it can pull the agent onwards.

The answers since then form families. Every one either adds a bonus where knowledge is thin, starts optimistic and lets evidence correct it, or acts on a plausible guess drawn from its uncertainty:

FamilyThe ruleWhat it needs, or where it failsA result
Optimism with counts: E3, R-MAX, MBIE-EB, UCRL2Unknown state-actions assumed maximally rewarding, or a bonus β/√N(s, a) in the Bellman equation (UCB for MDPs)A count per state, impossible when states are imagesFirst polynomial-time guarantees; UCRL2 regret Õ(DS√(AT))
Pseudo-counts and hashingA count derived from a density model, bonus β (N̂ + 0.01)−1/2; or counts of hashed statesA density model or a hash of the observationMontezuma's Revenge 3,439 at 100M frames; 15 of 24 rooms
Curiosity (ICM)Reward the error in predicting the next state's featuresThe noisy TV: unpredictable noise stays surprising foreverStudied with curiosity alone, no task reward, on 54 environments
Random Network DistillationReward the error in predicting a fixed random network's outputFamiliar observations stop paying; noise does not keep payingMontezuma's Revenge 8,152, above the average human's 4,753
Remember and return: NGU, Agent57, Go-ExplorePer-episode plus lifelong novelty; or an archive of states to return to, then explore fromGo-Explore's first version resets the emulatorAgent57 above the human benchmark on all 57 Atari games; Go-Explore 43,763
Posterior sampling: Bootstrapped DQN, NoisyNetAct greedily on one plausible value function for a whole episode; or learned weight noiseSeveral heads, or noisy layersNoisyNet is one of Rainbow's six extensions
Entropy bonuses: A3C, SACAdd the policy's entropy to the objective (weight β = 0.01 in A3C)Local: keeps the policy from collapsing, sends it nowhere newSAC's maximum-entropy objective

Randomness alone (ε-greedy, entropy) is the cheap fallback that works when rewards are dense. The deep methods' mechanics are on Value-based deep RL (NoisyNet in Rainbow) and Policy gradients and actor-critic (entropy, SAC).

The families in detail: sources, quotes and numbers (5 min)

Optimism with counts. E3 (Kearns and Singh 2002) and R-MAX (Brafman and Tennenholtz 2002) gave the first polynomial-time guarantees for exploring an MDP. R-MAX's model "is initialized in an optimistic fashion: all actions in all states return the maximal possible reward (hence the name)"; once a state-action pair has been tried enough times its true model replaces the optimistic one. MBIE-EB (Strehl and Littman 2008) turns this into a bonus β/√N(s, a) added to the reward in the Bellman equation (as restated by Bellemare et al. 2016). UCRL2 (Jaksch, Ortner and Auer 2010) plans optimistically within confidence sets on the transition model and proves regret Õ(DS√(AT)) against a lower bound Ω(√(DSAT)) (D the MDP's diameter, S states, A actions).

Pseudo-counts and hashing. Bellemare et al. (2016) derive a pseudo-count N̂(x) from a density model of observations: how much the model's probability of x rises after one more look at x says how familiar x is. The bonus is β (N̂ + 0.01)−1/2 with β = 0.05. On Montezuma's Revenge their agent "consistently navigates through 15 rooms" of the first level's 24 within 50 million frames, where the agent without the bonus saw two, and scored 3,439 on average by 100 million frames. Tang et al. (2017) count hashed states instead (SimHash of pixels or of learned features), bonus β/√n(φ(s)).

Curiosity. The Intrinsic Curiosity Module uses "the error in an agent's ability to predict the consequence of its own actions in a visual feature space learned by a self-supervised inverse dynamics model" (Pathak et al. 2017); learning features through an inverse model is meant to ignore what the agent cannot affect. A large-scale study trained agents with curiosity alone, no extrinsic reward, on 54 environments, and documented the noisy TV: add a TV with a channel-changing action to a maze and "the presence of the TV drastically slows down learning". Prediction error mixes up "new" with "random".

RND. Burda et al. (2018) fix the target: a randomly initialised network that is never trained maps each observation to a feature vector, and a second network is trained to predict those features; because the target is a deterministic function of the observation, noise does not keep the error high. RND was the "first method that achieves better than average human performance on this game without using demonstrations or having access to the underlying state": a mean of 8,152 on Montezuma's Revenge against an average human 4,753 (Table 1), the best agent often finding "22 out of the 24 rooms on the first level".

Remember and return. Never Give Up combines a per-episode novelty bonus with RND's lifelong one and was the "first algorithm to achieve non-zero rewards (with a mean score of 8,400) in the game of Pitfall! without using demonstrations" (Badia et al. 2020a); Agent57 adds the bandit meta-controller of section 4 and is "the first deep RL agent that outperforms the standard human benchmark on all 57 Atari games" (Badia et al. 2020b; the Milestones and benchmarks tab of Topic: rl has its scores, including two mistyped MuZero entries found there). Go-Explore (Ecoffet et al. 2019) keeps an archive of distinct states ("cells") reached so far, picks a promising one, returns to it (by restoring the emulator's state), explores from there, then trains a robust policy from the best trajectories. Without domain knowledge its policies averaged 43,763 on Montezuma's Revenge, "higher than the human expert mean of 34,900", and solved level 1 in 99.8% of attempts. The journal version, "First return, then explore", adds a policy that learns to return without resets and reports that it "solves all heretofore unsolved Atari games"; with easy-to-provide domain knowledge it reaches 102,571 on Pitfall and 1,731,645 on Montezuma's Revenge (figures from the preprint).

Posterior sampling. Thompson sampling's deep-RL form keeps several plausible value functions and acts greedily on one of them for a whole episode, the temporally extended exploration per-step noise lacks: Bootstrapped DQN trains several Q heads on bootstrapped data (Osband et al. 2016), developed in Osband, Van Roy, Russo and Wen (2019). NoisyNet learns noise in the network's weights, replacing ε-greedy and entropy bonuses, with initial noise scale σ0 = 0.5 (Fortunato et al. 2017); it is one of the six extensions Rainbow combines (Method atlas tab of Topic: rl).

Entropy. A3C adds the policy's entropy to the objective, "with a weight β = 0.01 for all Atari and TORCS experiments" (Mnih et al. 2016); SAC makes it the objective itself, J(π) = Σt E[r(st, at) + α H(π(·|st))], "to succeed at the task while acting as randomly as possible", with the temperature α weighing entropy against reward (Haarnoja et al. 2018).

Montezuma's RevengeScoreConditions
DQN (2015)0Human 4,367 in the same table (Mnih et al. 2015, Extended Data Table 2)
#Exploration, BASS-SimHash (2017)23850M steps (Tang et al., Table 1)
Pseudo-counts (2016)3,439average at 100M frames (Bellemare et al., appendix)
RND (2018)8,152mean; average human 4,753 in that paper's table
Go-Explore (2019)43,763no domain knowledge; resets the emulator to return; "human expert" 34,900
Go-Explore (2021)1,731,645with domain knowledge (room, discretised position, keys held, level, read from pixels by hand-written classifiers)

The human reference changes from paper to paper (4,367, 4,753, 34,900), and so do frame budgets, whether the emulator may be reset, and whether domain knowledge is used. The rows are not a leaderboard; each is a result under its own conditions.

7Exploration when training language models

RL on a pretrained language model starts from a policy that already produces sensible answers, so exploration is inherited from pretraining and controlled through sampling: several responses per prompt at a temperature around 1, so that some are right and some wrong and the advantage has something to compare (GRPO's group). In bandit terms, RL concentrates probability on arms the base model already pulls sometimes; it rarely finds arms the base model never pulls. Three results frame this, each taught on RL for LLMs: base models overtake their RL-trained versions on pass@k at large k (Yue et al. 2025); performance follows R = −a eH + b in the policy's entropy H, capped at −a + b when entropy runs out (Cui et al. 2025, with Clip-Cov and KL-Cov to slow the collapse); and DAPO's Clip-Higher (εlow = 0.2, εhigh = 0.28) lets rare tokens grow to keep exploring. The pipeline around them is on Alignment: SFT, RLHF, DPO Family, RLVR; DeepSeekMath (GRPO) and DeepSeek-R1 (RL from a base model without supervised warm-up) show what this exploration produced at scale.

Common mistakes

Breaking ties by taking the first arm
With all estimates equal at the start, "argmax" in most libraries returns the first index, so a greedy agent always starts on arm 1 and the results depend on arm order. Sutton and Barto break ties at random; so does every simulation on this page except the strategies animation, where the fixed tie rule is visible and stated.
Reading one run, or a few, as a result
A single bandit run is dominated by luck (try the five seeds in section 3). The book averages 2,000 tasks; on the testbed tab, compare 200 with 2,000 to see how much of a curve's wiggle is noise.
Using UCB's constant outside its scale
UCB1's √(2 ln n / nj) assumes rewards in [0, 1]. With rewards in the hundreds the bonus is negligible and UCB is greedy; with rewards in [0, 0.01] it explores almost uniformly. Rescale the rewards or tune c (Figure 2.6 shows how much c matters).
Treating optimistic initial values as a general method
Optimism explores only at the start. With sample averages it vanishes after one pull of each arm, and in a nonstationary task it never comes back (§2.6). R-MAX makes it principled by tying optimism to counts.
Reading the Lai and Robbins bound as a finite-time floor
It is a statement about the slope against ln T in the limit. A good algorithm can sit below the line at any T you can afford to run (the regret chart in section 4 shows Thompson sampling doing exactly that).
Crediting Thompson sampling for a matched prior
On the 10-armed testbed Thompson sampling with a N(0, 1) prior uses the exact distribution the tasks are drawn from. With a wrong or overconfident prior it can under-explore; report the prior with the result.
Stopping an A/B test the first time it looks significant
The test's p-values and intervals assume its length was fixed in advance; they "are wholly unreliable if users endogenously choose samples sizes by continuously monitoring their tests" (Johari, Pekelis and Walsh, Always valid inference). To stop early, use a sequential test built for it (their always-valid p-values) or a bandit, which needs no stopping rule.
Expecting a novelty bonus to ignore noise
Prediction-error curiosity is drawn to anything unpredictable (the noisy TV). RND's fixed random target and counts of states avoid that particular trap, but any bonus can distract from the task if it is not scaled down as the task reward appears.
Comparing hard-exploration scores across papers
Human baselines, frame budgets, sticky actions, emulator resets and domain knowledge all differ (see the Montezuma's Revenge table). Compare within one paper's table, or re-run.
Thinking ε-greedy is always the wrong choice
In Auer et al.'s experiments "an optimally tuned εn-GREEDY performs almost always best" (Auer et al. 2002); its weakness is that the tuning depends on the unknown gap, and in full RL that its exploration is shallow. With dense rewards (most of Atari) it is still the default.