ε-greedy, UCB & Thompson Sampling
Solving the classic Exploration vs Exploitation trade-off in decision systems, recommendation feeds, and multi-armed bandits.
The Exploration-Exploitation Dilemma
THE DECISION DILEMMA
┌───────────────────────────────────────┬───────────────────────────────────────┐
│ EXPLOITATION │ EXPLORATION │
├───────────────────────────────────────┼───────────────────────────────────────┤
│ Pick action with highest known reward.│ Pick under-sampled action to gain │
│ Maximizes short-term revenue. │ new information. │
│ Risk: Misses hidden optimal action! │ Risk: Wastes short-term user clicks. │
└───────────────────────────────────────┴───────────────────────────────────────┘
Three Core Exploration Strategies
1. -Greedy
- With probability : Exploit ().
- With probability : Explore (Sample uniformly at random across all arms).
Drawback: Explores all suboptimal arms equally, even those known to be terrible.
2. Upper Confidence Bound (UCB1)
Principle: Optimism in the Face of Uncertainty.
- : Empirical mean reward of arm .
- : Total steps taken so far.
- : Number of times arm has been pulled.
- As , uncertainty term explodes , forcing exploration!
Arm A (Sampled 100 times): Mean = 0.70, Bonus = 0.05 ──► Upper Bound = 0.75
Arm B (Sampled 2 times): Mean = 0.50, Bonus = 0.40 ──► Upper Bound = 0.90 (WINNER -> Explore B!)
3. Thompson Sampling (Bayesian Posterior Sampling)
Maintains Beta distribution prior for each binary arm :
- For each arm , sample .
- Pull arm .
- Observe reward . Update: , .
Strategy Comparison Matrix
| Strategy | Exploration Type | Regret Bound | Best Use Case |
|---|---|---|---|
| -Greedy | Random Uniform | Linear (unless ) | Simple baseline, low-overhead systems |
| UCB1 | Deterministic Optimism | Logarithmic | Cold-start news / ad ranking feeds |
| Thompson Sampling | Bayesian Probability Matching | Logarithmic | E-commerce recommendations, A/B testing |
Say this out loud
"Exploration vs Exploitation balances short-term reward against long-term learning. ε-greedy explores via uniform random sampling. UCB1 implements 'Optimism in the face of uncertainty', adding an upper confidence bound bonus c√(ln N / N_a) to under-sampled arms. Thompson Sampling samples from Bayesian posterior distributions Beta(α,β), offering state-of-the-art logarithmic regret in production recommendation engines."
Follow-ups to expect
- What is Cumulative Regret? The total loss in reward incurred by playing suboptimal arms compared to playing the true optimal arm continuously: .
- How does Thompson Sampling handle continuous contextual features? Use LinUCB or Neural Thompson Sampling, where a linear regression or neural network predicts reward distributions conditioned on user context vectors .
Check yourself
What is the core principle of the Upper Confidence Bound (UCB1) algorithm?