- Introduced by
- Robbins (1952); UCB1 by Auer et al. (2002); Thompson sampling by Thompson (1933)
- Year
- 1952
- Type
- Sequential decision / bandit algorithm
What does it do?
The multi-armed bandit (MAB) is an adaptive experimental framework that allocates trials sequentially across competing arms while learning which arm yields the highest reward.
Auer et al. (2002) gave a finite-time analysis of the UCB1 strategy. The method trades off exploring uncertain arms against exploiting the arm that currently looks best, so the cost of learning is paid during the experiment rather than only after it ends.
The intuition behind the method
Imagine several slot machines with unknown payout rates. Playing each one equally wastes pulls on poor machines. A better strategy tracks which machines have paid out so far and plays them more often, while still trying the others often enough to detect a machine that has been underestimated. The bandit algorithm formalises this trade-off: it updates its estimate for each arm after every trial and shifts future allocation toward the arms that look most promising, without waiting for a fixed sample to be complete.
History
Auer, Cesa-Bianchi, and Fischer (2002) gave a finite-time analysis and introduced the UCB1 strategy with a regret bound. Russo et al. (2018) wrote a tutorial on Thompson Sampling that covers its algorithm, several applications, and when it is and is not effective.
When to use it
Use a multi-armed bandit when you have K candidate options (variants, treatments, content items) that can be sampled repeatedly, the reward for each trial is observed quickly, and the cost of sending traffic to weaker options during learning matters. The reward process should be stationary or change slowly; if arm means drift, a discounted or sliding-window version is needed. UCB1 assumes bounded rewards and needs no prior. Thompson Sampling needs a prior, and the Beta posterior described in this page fits binary success/failure rewards; continuous rewards require a different model. Do not use a bandit when the main goal is a confirmatory estimate of effect sizes with classical inference, or when rewards are delayed so long that the allocation cannot respond to them.
Limitations and considerations
- Regret guarantees assume rewards are stationary; when arm means drift, the index or posterior can lock onto an arm that is no longer best.
- Thompson Sampling's behaviour depends on the prior: a prior that is far from the true reward rates can slow learning, especially when samples are small.
- The UCB1 exploration term is large when rounds are few or arms have small counts, so early allocation can explore more than the eventual optimum requires.
- Adaptive allocation makes the final arm estimates biased toward arms that were favoured early, which complicates reporting to non-technical stakeholders.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Reduces opportunity cost: traffic moves toward better-performing arms during the experiment rather than being split equally until the end.
- UCB1 has a proven worst-case regret bound of order sqrt(K T ln T) (Auer et al., 2002), which gives a formal sense of how the cost of learning scales with the number of rounds and arms.
- Thompson Sampling incorporates prior information through the posterior and gives an explicit uncertainty model for each arm.
- The UCB1 index is deterministic and simple to compute, which makes the allocation rule easy to audit round by round.
Applications
- Online recommendation and content personalisation, where items are arms and user responses are rewards.
- Clinical adaptive designs that allocate more patients to treatments performing better during the trial.
- Web experimentation platforms that compare many page variants while reducing traffic sent to weaker ones.
- Hyperparameter and architecture search, where each configuration is an arm and each training run is costly.
- Dynamic pricing and bidding, where the reward distribution may change over time and needs monitoring.
How it works
How it works
The mechanics list gives a formal reference hypothesis: all K arms share the same expected reward, and the alternative is that at least one pair differs. This statement is included only as a point of reference for the comparison problem. A bandit does not perform this test in the classical sense. Its purpose is to direct trials toward the arm with the highest expected reward while limiting the reward lost during learning, so the algorithm's output is a deployment choice rather than a verdict on the null hypothesis.
Formula
H_0:\ \mu_1 = \mu_2 = \cdots = \mu_K \quad H_1:\ \exists\, i \neq j:\, \mu_i \neq \mu_j
UCB1 computes, at each round t, an index for each arm equal to its current estimated mean reward plus an exploration term, sqrt(2 ln t / n_i), where n_i is the number of times arm i has been played. The exploration term shrinks as an arm is sampled more, so rarely played arms keep a high index until they are tried. Thompson Sampling instead keeps a posterior distribution for each arm's success probability (a Beta posterior when rewards are binary), draws one sample from each posterior, and plays the arm with the largest draw. Both rules concentrate play on high-reward arms, but their regret guarantees are stated differently and should not be conflated.
Formula
\text{UCB1: } A_t = \arg\max_{i}\left[\hat{\mu}_i + \sqrt{\dfrac{2\ln t}{n_i}}\right]The performance criterion is cumulative regret, the reward lost relative to always playing the best arm. Auer et al. (2002) show that UCB1 has worst-case regret of order sqrt(K T ln T) over T rounds, which is the bound given in the mechanics. The standard analysis assumes that rewards are bounded, that the rewards of each arm are independent draws, and that the reward process is stationary or changes slowly. A stopping rule must be fixed before the run. Two common choices are a fixed horizon T, or stopping once the posterior probability that one arm is best exceeds a threshold chosen in advance. The rule chosen determines which arm is deployed and how much confidence that choice warrants. The arm selected at the end is the one to deploy, but its estimated reward is provisional because the sampling was adaptive, so it should be reported descriptively together with the allocation history. Classical p-values and confidence intervals computed as if the sample were fixed are not confirmatory after adaptive sampling; inference that accounts for the adaptive design is required for that purpose.
Formula
\text{Cumulative regret: } R_T = T\mu^* - \sum_{t=1}^{T}\mu_{A_t} \leq O\!\left(\sqrt{KT\ln T}\right)Common pitfalls
- Running a bandit on non-stationary rewards without discounting or a sliding window, so an arm that won early is kept in use after it has become worse.
- Applying a classical significance test after the experiment to the unequal allocation produced by the bandit, without accounting for the adaptive sampling; this can inflate Type I error.
- Choosing a Beta prior for Thompson Sampling that dominates the observed data when samples are small, so the algorithm mostly reflects the prior.
- Treating the bandit as a hypothesis test: it is designed to choose which arm to deploy and to limit regret, and its output is not a calibrated test of whether arm means differ.
Frequently asked questions
How does a bandit differ from a standard A/B test?
A standard A/B test typically allocates traffic in fixed proportions and reaches a conclusion after a pre-set sample. A bandit changes allocation during the experiment, sending more traffic to arms that are performing better, so fewer trials go to weaker arms. The cost is that inference is more complicated, because the sample is no longer fixed and the allocation depends on earlier outcomes.
UCB1 or Thompson Sampling: which should I choose?
UCB1 is deterministic and needs no prior, which makes its allocation rule straightforward to explain and reproduce. Thompson Sampling is randomised and uses a posterior, so it can incorporate prior information; it requires a model for the reward, such as the Beta model for binary outcomes. Russo et al. (2018) discuss when Thompson Sampling is and is not effective. If there is useful prior information and binary rewards, Thompson Sampling is a natural choice; if transparency and no prior are priorities, UCB1 is the simpler option.
What is 'regret' and why does it matter?
Regret is the total reward lost, relative to always playing the best arm, during the learning process; it measures the cost of exploration. UCB1's worst-case regret bound grows at the rate sqrt(K T ln T), so the average loss per round shrinks as the experiment runs longer. Minimising regret is the right objective when every trial has a real cost. A fixed-sample test does not measure this cost, because it does not count reward lost while the arms are being compared.
Can I use a bandit with more than two arms?
Yes. Bandit algorithms are designed for K arms, with K greater than or equal to two. Running K separate pairwise A/B tests is a different design, with its own multiple-comparison issues, and a bandit does not perform familywise error control. If the question is which arm to deploy, a bandit targets that decision directly; if the question is which pairs differ, a bandit is not the right tool.
Related methods
Sources
Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-Time Analysis of the Multiarmed Bandit Problem. Machine Learning, 47(2–3), 235–256.
Open DOI referenceRusso, D., Van Roy, B., Kazerouni, A., Osband, I., & Wen, Z. (2018). A Tutorial on Thompson Sampling. Foundations and Trends in Machine Learning, 11(1), 1–96.
Open DOI reference