Skip to content
mlmentorship

Exploration vs exploitation: epsilon-greedy, UCB, Thompson sampling

An RL or bandit agent has to keep trying new actions to learn while taking the best-known action to score. Three classical strategies, each with a different way of resolving the tension.

Published · 8 min read ·Specialist ·Intermediate
Reading depth

Summary

Exploration gathers information; exploitation chooses the action that currently appears best from available evidence. Arm A leads by estimated reward, but arm B has far fewer observations. Compare a random switch, an uncertainty index, and a posterior draw before choosing the next observation.

The setup

There are eligible actions with unknown stationary reward means . Each round chooses one action and observes its reward. For horizon , pseudo-regret compares chosen means with the best eligible mean:

This rewards cumulative performance, not necessarily precise identification at a fixed deadline. Never explore an action outside safety, permission, or resource eligibility. Our displayed means are generic bounded-reward estimates, not exact Bernoulli success fractions.

An uncertainty bonus or a posterior draw can overturn the mean leader

The best mean need not win an uncertainty-aware choiceThe mean favors A. An upper-confidence score or posterior draw can favor B; the table uses illustrative, not empirical, values.One pair of arms; three choice rulesEstimated mean: choose AA 0.65B 0.6Mean plus bonus: choose BA 0.67B 0.72One posterior draw: choose BA 0.62B 0.75
Derivation
The same leader can lose to an uncertainty bonus or one posterior drawArms A, B, C have means .62, .55, .35 and counts forty, four, twenty. Epsilon .3 chooses A with probability .8 because its random branch also includes A. UCB uses mean plus .2 sqrt(log64/n) and selects B. Declared illustrative Normal posteriors with means .62,.55,.35 and standard deviations .06,.18,.09 produce one shown draw .58,.78,.31, selecting B.Same evidence: A .62/40; B .55/4; C .35/201. EPSILON = 0.3: random branchABCP(A)=0.7+0.3/3=0.8; P(B)=P(C)=0.12. UCB: mean + 0.2 sqrt(log(64) / n)Aindex 0.68Bindex 0.75: choose BCindex 0.443. THOMPSON: maximize one posterior drawAssumed Normal posteriors for this toy roundAdraw 0.58Bdraw 0.78: choose BCdraw 0.31Toy posteriors are declared assumptions.Later draws may choose a different arm.Means and counts do not determine these curves.
Dots and whiskers show UCB means and bonuses, not confidence guarantees for this chosen coefficient. Thompson curves are explicit toy assumptions. Only the displayed draw selects B.
Check: Why can B be selected despite its lower mean? How do UCB and Thompson justify that choice differently?
Read it this way: The mean favors A. An upper-confidence score or posterior draw can favor B; the table uses illustrative, not empirical, values.
Can the lower estimated mean win an uncertainty-aware choice?

-greedy

Choose the empirical leader with probability ; otherwise sample uniformly across all eligible arms. Declare a fixed order for exact score ties. For and , the probabilities are , not .

UCB (Upper Confidence Bound)

Initialize untried eligible arms first, or give them infinite priority. For positive pull counts , select the largest index:

For the displayed , the indices are approximately , selecting B. This coefficient illustrates selection; it does not supply UCB1’s stated guarantee. Classical logarithmic, gap-dependent UCB1 bounds assume stationary independent bounded rewards and the corresponding bonus convention.

Thompson sampling

Draw one plausible mean per eligible arm from its posterior; select the largest draw and update from the observed reward. Draws select B, not necessarily on the next round. Separately, a Bernoulli likelihood and Beta prior become Beta after two successes and one failure. Its posterior mean is .

When each strategy is the right choice

Reward means drift

New task: respond when a product update changes rewards.

Picture and change: compare accumulated evidence with a declared recent window or a justified reset/discount model.

Check: 90 successes and ten failures yield Beta. After ten new failures, pooling gives Beta, mean . Using only the new window gives Beta, mean . Discarding history reacts faster but increases uncertainty; stationary regret guarantees no longer transfer automatically.

Use when: fixed means no longer describe the environment.

Estimate a causal comparison

New task: estimate a common-population effect, not merely reward during learning.

Picture and change: specify randomized assignments, recorded propensities, mature outcomes, and a valid adaptive-inference plan.

Check: two independent units have assignment probabilities . The first receives A, the second B; both rewards equal one. Inverse-propensity population means are and . These estimates do not supply a fixed-sample confidence interval after arbitrary adaptive stopping.

Use when: an identified effect and its precision drive the design; retain required controls.

Beyond bandits

Contextual bandits condition reward estimates on available features. Delayed outcomes require pending-assignment accounting rather than treating missing rewards as zeros. Costs and permissions constrain the eligible set before selection.

In sequential RL, actions also change future states. Boltzmann policies sample proportionally to . Maximum-entropy objectives reward policy entropy; intrinsic bonuses target chosen novelty signals. These change the objective or observation process, not merely the bandit score.

Common pitfalls

A bare schedule is not a universal logarithmic-regret theorem. Insufficient exploration can preserve a noisy leader; excessive exploration incurs continuing opportunity cost. Hoeffding bonuses do not directly handle arbitrary unbounded rewards. Posterior sampling does not automatically track drift or guarantee optimality under a misspecified likelihood.

Is constant epsilon always wrong?

Answer

No: continuing support or adaptation may be required. If the true means equal the displayed estimates, the fixed probabilities yield reward , short of by . That fixed rule incurs expected regret under these stationary means. Judge its information benefit against the stated objective.

UCB’s action is deterministic given history and tie rules, but that history contains random rewards. Thompson draws are reproducible with controlled random state and execution; compare repeated seeds and matching reward streams.