Thompson Sampling
Thompson sampling (posterior sampling) samples an environment from the posterior and plays its optimal action, so exploration comes from posterior randomness. The note covers its Bayesian regret O(√(kn log n)) for any prior, via the key identity that the played action and the optimal action have the same conditional law, which reduces the analysis to UCB's. The frequentist analysis views Thompson sampling as stochastic follow-the-perturbed-leader with per-arm perturbation distributions, and bounds pull counts by an optimism term Σ(1/G₁ₛ − 1) plus an over-sampling term Σ 𝕀{Gᵢₛ > 1/n}; this gives asymptotic optimality (2/Δᵢ) and O(√(nk log n)) for Gaussian Thompson sampling with a flat prior, with higher regret variance than AdaUCB in experiments. Linear Thompson sampling has Bayesian regret O(d√n log n), and its computational advantage is that it needs only a linear optimisation, whereas LinUCB needs a bilinear one. The information-theoretic analysis bounds Bayesian regret by information ratio × information gain; the posterior over the optimal action is a martingale whose expected Bregman divergence telescopes, giving √(kn log k/2) against Bayesian adversaries and √(2kn) with the Tsallis potential. Notes cover information-directed sampling, BayesUCB, sensitivity to misspecified priors, the variance inflation needed for frequentist linear guarantees, and minimax adversarial bounds via Sion's theorem.
Corresponds to Lattimore & Szepesvári, Chapter 36.
Motivation: where it all began
IntuitionSample a world, then act optimally in it
Thompson (1933) proposed the first bandit algorithm, for two Bernoulli arms, with hand-calculated evidence only. Choose a prior over environments. Each round, sample an environment from the posterior and play its optimal action.
- When the posterior is diffuse, samples vary a lot and the algorithm explores.
- When the posterior concentrates, samples agree and it exploits.
Exploration is automatic and proportional to uncertainty, with no confidence-level tuning. The algorithm was largely ignored for eight decades, then rediscovered around 2010 (Graepel, Granmo, Chapelle–Li, …). It is now near-optimal in many settings and often very practical.
WarningRandomisation has a cost
Randomisation is essential against adversaries and sometimes useful in stochastic settings (SETC, TopRank). But injecting noise can raise the variance of the regret. What Thompson sampling gains or loses through its randomness is still not fully understood.
| Analysis | Setting | Result |
|---|---|---|
| Bayesian | finite-armed, any prior | ; with refined intervals |
| Frequentist | Gaussian, flat prior | asymptotically optimal ; |
| Bayesian | linear | , matching LinUCB |
| Information-theoretic | Bayesian adversarial | ; with the Tsallis potential |
Thompson sampling for finite-armed bandits
AlgorithmThompson sampling (Algorithm 23)
Input: a Bayesian bandit environment (Chapter 34). For :
- sample ;
- play .
Formally, with (systematic tie-breaking): play each arm with its posterior probability of being optimal.
NoteThree equivalent views (Note 1, Exercise 36.1)
- play with probability (Thompson’s original view);
- sample an environment and play its best arm (Algorithm 23);
- if arm means are independent under the posterior: sample each arm’s mean and play the largest.
These are different push-forwards of the same posterior. They define the same policy, but approximate Thompson sampling (for example in RL) differs depending on which object is approximated. Non-Bayesian ways to induce exploration can also be cheaper.
Bayesian regret
TheoremTheorem 36.1 — Bayesian regret of Thompson sampling
If every is 1-subgaussian (after centring) with mean in , then for any prior,
Refined (MOSS-type) confidence bounds give (Exercise 36.4; Bubeck–Liu 2013).
ImportantThe key identity
Under the Bayesian measure, given the history,
The optimal arm is random through , and Thompson sampling plays an arm with the same posterior law (Exercise 36.3). So any history-measurable function satisfies , which lets UCB’s analysis run unchanged.
ProofUCB analysis via probability matching
Step 1: Insert a UCB. Let , which is -measurable. By (36.1),
so (36.2).
Step 2: The good event. is the event that every confidence interval holds, with (Exercise 36.2). On :
- optimism: the first sum is at most 0, since ;
- width: , so
Step 3: on the regret is at most . Take .
∎
IntuitionThompson sampling is “UCB in expectation”
UCB plays the arm with the largest confidence bound. Thompson sampling plays arms in proportion to the probability of being best. In the Bayesian analysis these are interchangeable: any optimistic index, in expectation over the posterior, is as large at as at . Thompson sampling never computes the index, yet inherits its guarantees for any prior (Russo–Van Roy 2014).
Frequentist analysis
WarningWhy frequentist analysis is harder
For a fixed , the optimal arm is not random, so (36.1) fails: is random but isn’t. A different argument is needed.
AlgorithmStochastic follow-the-perturbed-leader (Algorithm 24)
Per-arm distribution functions . Each round:
- sample independently;
- play ;
- update only the played arm: .
With a product prior and Bayesian updates this is Thompson sampling. The key property is that an arm’s distribution changes only when it is played. Let be arm ‘s distribution after plays, defined for all through the reward-stack model. This is the stochastic cousin of FTPL (and Exp3 is FTPL with Gumbel noise).
TheoremTheorem 36.2 — Pull-count bound for perturbed leaders
Let arm 1 be optimal, , , and , the probability that arm ‘s sample exceeds after plays. Then
IntuitionThe perturbation scale trades the two terms
- First term: how hard it is for the optimal arm’s sample to be (nearly) optimistic. Larger perturbation variance makes it smaller (more exploration).
- Second term: how long a suboptimal arm’s sample can still look as good as . Smaller variance makes it smaller (less exploration).
Balancing the two is the exploration–exploitation trade-off, here set by the spread of the posterior.
ProofProof of Theorem 36.2: compare playing with playing 1 when ‘s sample is low
Let and split (36.4).
First part. Let . Since is conditionally independent of the others:
- (arm 1’s sample beats , which beats everyone else);
- .
So . Summing over , each value occurs in only one round in which arm 1 is played, giving the term (36.6).
Second part. In rounds where arm ‘s current , count plays of : at most . In the other rounds, , so they contribute at most 1 in total (Exercise 36.5).
∎
TheoremTheorem 36.3 — Gaussian Thompson sampling is asymptotically optimal
With (forces one initial play of each arm) and the CDF of (a flat-prior Gaussian posterior), on Gaussian bandits :
ProofSketch (Exercise 36.6)
(a) Optimism of the optimal arm. , a constant. The sample exceeds unless is far below , which is exponentially unlikely in . Use the Gaussian tail lower bound .
(b) Over-sampling. . For a Gaussian sample with variance to exceed with probability above , roughly : exactly UCB’s condition, so .
(c) Combine with the regret decomposition and let . This matches the Lai–Robbins constant of asymptotically optimal UCB.
∎
ExampleExperiment 36.1 — Thompson sampling versus AdaUCB
Two Gaussian arms with means , , runs: expected regret 23.8 for AdaUCB, 29.9 for Thompson sampling (both beat Chapter 7’s UCB). Thompson sampling’s regret distribution has a much heavier upper tail: its second moment is far larger. It is better than simple UCB, but worse in both mean and variance than sophisticated UCB variants.
WarningFrequentist caveats (Notes 3, 5)
- Not minimax optimal for Gaussians: the worst case is (Agrawal–Goyal 2013), versus MOSS’s .
- The prior matters a lot. In classical statistics a bad prior is washed away by data. In bandits, a prior that underestimates an arm can mean it is (almost) never played, so no data ever corrects the belief (Exercise 36.16). Even for Gaussians with unknown variance, some natural priors are asymptotically optimal and others aren’t (Honda–Takemura 2014).
- Where it is optimal: Beta–Bernoulli Thompson sampling is asymptotically optimal like KL-UCB (Kaufmann et al. 2012; Agrawal–Goyal 2013), and so are one-parameter exponential families with suitable priors (Korda et al. 2013).
RemarkBayesUCB (Note 4)
Instead of sampling, play the arm with the largest posterior quantile (a Bayesian upper confidence bound). It has excellent theory and practice (Kaufmann et al. 2012; Kaufmann 2018), and is a deterministic cousin of Thompson sampling.
Thompson sampling for linear bandits
AlgorithmLinear Thompson sampling (Algorithm 25)
, with rewards 1-subgaussian with mean . Each round: sample from the posterior, play , observe .
TheoremTheorem 36.4 — Bayesian regret of linear Thompson sampling
If and almost surely under the prior, and , then
That is for fixed , matching LinUCB’s Corollary 19.3.
ProofSame trick with the ellipsoidal UCB
Let with . The self-normalised bound gives for all (event ) except with probability , which costs at most 2. On , using probability matching and optimism, . Truncate at 2, apply Cauchy–Schwarz over , and use the elliptical potential lemma.
∎
ImportantThe real advantage: computation
Thompson sampling needs (1) a posterior sample, which is easy for a Gaussian prior with Gaussian noise and generally the subject of a large MCMC literature, and (2) a linear optimisation . LinUCB needs a bilinear problem , often intractable for large or continuous action sets. In finite-armed bandits Thompson sampling’s advantages are modest; in linear and structured problems they are substantial.
WarningLinear Thompson sampling: frequentist and asymptotic limits (Notes 2, 6)
- Frequentist guarantee needs variance inflation. Sample with (a pretend noise variance of order ). That gives , worse than LinUCB by (Agrawal–Goyal 2013; Abeille–Lazaric 2017). The analysis needs the samples to be optimistic with constant probability, which requires the inflation. Hamidi–Bayati (2020) showed it is necessary on some instances, even with three fixed actions. Empirically often works well.
- Not asymptotically optimal: like optimism, it under-plays informative but suboptimal actions (clouds looming). When Thompson sampling is near-optimal in general remains open.
Information-theoretic analysis
Setting: Bayesian adversarial bandits. A reward matrix is drawn from a prior and kept secret. The learner sees . Actions depend on only through the history, so . The optimal arm is , and . Thompson sampling plays . This includes stochastic bandits as a special case (an i.i.d. prior).
TheoremTheorem 36.5 — Thompson sampling against Bayesian adversaries
For any prior on ,
TheoremTheorem 36.6 — Regret ≤ √(information ratio × total information)
Let be the posterior over the optimal arm, the instantaneous regret, and convex. If
then .
ProofThe posterior is a martingale, so expected Bregman divergences telescope
Step 1: is a martingale: . For convex (using directional derivatives, Fatou, and Jensen),
since the linear term vanishes in expectation.
Step 2: by the assumption and Cauchy–Schwarz, .
Step 3: by (36.8) the sum telescopes to .
∎
IntuitionRegret only where you learn
The information ratio says that each round’s regret is paid for by learning about the optimal action. The total learnable information is bounded by the potential’s range ( for negentropy: you can’t learn more than the entropy of ). A small information ratio plus finite total information gives small regret. With negentropy, is the mutual information , the information gain about the optimal arm, hence the name.
LemmaLemma 36.7 — Thompson sampling’s information ratio is at most
If , Thompson sampling with any prior satisfies
ProofProbability matching, Pinsker, Cauchy–Schwarz
Write (probability matching). Then
by Pinsker, since . Cauchy–Schwarz over terms gives at most . Bound by the full double sum , which equals the mutual information between and the observation (by Bayes, Exercise 36.7), i.e. the expected KL from prior to posterior on .
∎
ProofProof of Theorem 36.5
Lemma 36.7 gives with negentropy, whose diameter on the simplex is . Theorem 36.6 gives .
∎
TheoremVariants (Exercises 36.8–36.10)
- Full information (Thompson sampling for experts): , so .
- Information-directed sampling (IDS): choose the action distribution that minimises the information ratio directly, . It has the same bound and can beat Thompson sampling in structured problems where informative actions are suboptimal (Russo–Van Roy 2014; frequentist version by Kirschner–Krause).
- Tsallis potential , with total variation bounded by Hellinger: for any prior, with no . This is the same potential as the INF algorithm. The stability terms of mirror descent and the information ratio are controlled by the same calculations (Zimmert–Lattimore 2019).
- Any martingale works: the proof only used that is a martingale. Other martingales sometimes give better bounds.
- Linear bandits: information ratio about . For infinite action sets the entropy of can be infinite, so discretise and compare to a near-optimal action, giving (Dong–Van Roy 2018).
ImportantFrom Bayesian to adversarial regret: non-constructive minimax bounds (Note 11)
By Sion’s minimax theorem (Exercises 36.11–36.12; Tychonoff for the compactness of deterministic policies),
This is a factor 2 better than Exp3’s Theorem 11.2. But it doesn’t produce an algorithm: it proves a good adversarial policy exists. The technique gave the first near-optimal bounds for adversarial convex bandits (Bubeck et al.; Bubeck–Eldan) and for partial monitoring.
ExampleBinary rewards are the worst case (Exercise 36.13)
: run a minimax policy for binary rewards on rewards by feeding it a sample of each observed reward. The expected regret is unchanged by linearity. (Reduction worked here.)
History and scope
RemarkHistory
Thompson (1933), two Bernoulli arms, no theory. Rediscovered around 2010. Frequentist analysis: Agrawal–Goyal (2012, 2013, bounded rewards); asymptotic optimality: Kaufmann et al. (2012), Korda et al. (2013). The Bayesian analysis via confidence intervals is due to Russo–Van Roy (2014). Information-theoretic analysis: Russo–Van Roy (2014, 2016), generalised beyond negentropy by Lattimore–Szepesvári (2019). Extensions include combinatorial semi-bandits (Wang–Chen 2018), reinforcement learning (posterior sampling for RL: Osband et al. 2013), and more. Tutorial: Russo et al. (2018). Algorithm 24 admits other perturbation schemes (Kveton et al. 2019).
Quick reference
| Object | Statement | Note |
|---|---|---|
| Thompson sampling | play , posterior | equivalently |
| Probability matching | Bayesian only | |
| Bayesian regret | (or ) for any prior | UCB proof via matching |
| Perturbed leader | sample , update only the played arm | product prior = TS |
| Pull bound | optimism vs over-sampling | |
| Gaussian TS | ; | worst case |
| Experiment | TS 29.9 vs AdaUCB 23.8, TS higher variance | |
| Linear TS | only needs linear optimisation | |
| Frequentist linear TS | with inflation | inflation necessary |
| Information theorem | posterior martingale telescopes | |
| TS information ratio | (negentropy) | Pinsker + Cauchy–Schwarz |
| Bayesian adversarial | ; (Tsallis) | full info: |
| IDS | minimise the information ratio | same bounds, better on structure |
| Minimax via Sion | non-constructive |
Facts to keep to hand
- Thompson sampling explores by sampling plausible worlds. Exploration scales with posterior uncertainty, with no confidence tuning. It is simple, general and often practical, especially in linear and structured problems where it replaces LinUCB’s bilinear optimisation with a sample and a linear one.
- Bayesian analysis is UCB analysis in disguise. Probability matching makes and exchangeable given the history, so any optimistic index’s analysis transfers to any prior.
- Frequentist analysis is a perturbation trade-off. Enough spread that the optimal arm is sometimes optimistic, little enough that bad arms stop looking good. Gaussian Thompson sampling attains Lai–Robbins, but it has heavier regret tails, depends on the prior (a bad prior can starve an arm), and linear versions need variance inflation for worst-case guarantees.
- The information ratio unifies everything. Regret is at most √(information ratio × total information about ). For Thompson sampling the ratio is , giving for any prior. The Tsallis potential links this to mirror descent’s , and via Sion it yields non-constructive minimax bounds for adversarial problems.
References
- Lattimore & Szepesvári, Bandit Algorithms — Chapter 36
- Russo & Van Roy, “An information-theoretic analysis of Thompson sampling” (2016)
- Agrawal & Goyal, “Further optimal regret bounds for Thompson sampling” (2013)
- Russo, Van Roy, Kazerouni, Osband & Wen, “A Tutorial on Thompson Sampling” (2018)