ML Systems Lab Open interactive version →
Intermediate 45 min read UCBUCB1confidence boundoptimismKL-UCB

Upper Confidence Bound Algorithms

UCB1, Lai-Robbins optimality, UCB variants, confidence bound construction

Epsilon-greedy's fundamental problem is that it allocates exploration uniformly — it has no mechanism for deciding which arms deserve more exploration. UCB solves this with a principled principle: always pull the arm whose true mean could plausibly be highest given what has been observed. The UCB index is μ̂_a + confidence_bonus, where the bonus shrinks as an arm accumulates data and grows as t increases.

An arm that is either genuinely high-reward or under-explored will win the argmax — and if it wins because it was over-estimated, the next observation corrects that, shrinking its UCB. Over-optimism is self-correcting. UCB1 achieves O(log T) regret matching the Lai-Robbins lower bound's order — though not its exact constant; only KL-UCB (below) matches the constant too. In production, UCB's determinism (fully reproducible, no random coin flips) makes it auditable — but naive UCB scales poorly to millions of arms because maintaining per-arm confidence intervals becomes expensive.

Key points

Takeaway

UCB's self-correcting optimism is the key mechanism: if an arm wins the argmax because it was over-estimated, the next observation corrects that estimate and shrinks its UCB — over-optimism generates exactly the exploration needed to correct itself. The 1/Δ_a regret factor matters: near-optimal arms (small gap) require O(log T / Δ_a) pulls to identify as suboptimal, because small distributional differences need many observations to resolve. Arms with large gaps are eliminated quickly; arms close to the best take persistent exploration.

Recap

Check your understanding

Q1. You have K=5 arms with true means [0.9, 0.8, 0.5, 0.3, 0.1]. After t=100 rounds with UCB1, arm 1 has been pulled N_1=30 times and arm 5 has been pulled N_5=5 times. For this exercise, assume each arm's empirical mean μ̂_a has already converged exactly to its true mean, so you can substitute the true means directly for μ̂_a. Compute the UCB scores and explain what the algorithm will do.

Q2. Why does UCB1's regret bound have a 1/Δ_a factor? Select the two true implications for arms that are very close in quality.

Q3. You're designing an ad serving system with 10 million ads. Describe a practical UCB architecture that is computationally feasible.

Q4. What is the difference between instance-optimal regret (UCB1) and minimax-optimal regret (MOSS)? When does each matter?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →