Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.The best choice depends on the situation
A rover can drive over terrain in three modes: fast, careful or rocking. No single mode is best everywhere. On flat sand “fast” wins, on rocks “careful” wins. Before each choice the rover sees the terrain (its context), picks a mode, and only finds out how well that mode worked. Over time it must learn a rule mapping terrain to mode, while still trying modes it is unsure about. That’s a contextual bandit: the bandit problem with eyes.
Contextual bandits personalize decisions with partial feedback: choosing a locomotion gait from terrain features, selecting a planner or sensor configuration from conditions, picking a compression mode from link quality, or recommending content. Logged data from past decisions can also be reused to evaluate a new policy before deploying it (off-policy evaluation), which matters when trying things on hardware is expensive or risky.
- 1. A contextual bandit sees … before acting.
- 2. The learner must learn…
- 3. Feedback is still…
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Protocol and regret
Each round: observe , choose , receive with mean . Regret is measured against the best action for each context:
An algorithm that ignores contexts can at best find the single best action on average, so its regret against this per-context benchmark grows linearly whenever different contexts favour different actions.
Linear contextual bandits
Assume (disjoint model) or (shared). Each action’s parameters are estimated by ridge regression on the rounds where it was chosen: with and .
- 1. Contextual regret compares with…
- 2. A context-blind bandit's regret against that benchmark is typically…
- 3. LinUCB estimates each action's θ by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.LinUCB
Choose
The bonus is the width of a confidence ellipsoid in direction x: large where that action has seen few similar contexts. With a properly chosen α (from self-normalized concentration, Abbasi-Yadkori, Pál and Szepesvári, 2011), the regret is . Updates cost per round using the Sherman–Morrison formula.
Linear Thompson sampling
Sample and act greedily on the samples. It has similar guarantees (Agrawal and Goyal, 2013) and often performs better in practice.
Off-policy evaluation (OPE)
Given logs from a logging policy with known propensities , estimate the value of a new policy π:
- IPS: . Unbiased, but high variance when propensities are small.
- Direct method (DM): fit and average . Low variance, but biased if is wrong.
- Doubly robust (DR): . Unbiased if either the propensities or the model are correct, and usually lower variance than IPS.
- 1. LinUCB's exploration bonus is large when…
- 2. IPS is…
- 3. DR is unbiased if…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Why IPS is unbiased
For fixed x, , provided (overlap). Its variance scales like , which explodes when the logging policy rarely takes the target’s actions.
Why DR is doubly robust
Write DR = DM + an IPS-weighted residual correction. If the propensities are right, the correction’s expectation is evaluated at π(x), which exactly cancels DM’s bias. If the model is right, the residuals have mean zero, so the correction is unbiased noise. Its variance is IPS’s applied to residuals rather than raw rewards, so it is smaller when is decent. ∎
Regret of LinUCB (idea)
With high probability, lies in the ellipsoid , so optimism gives per-round regret at most . The elliptical potential lemma, , plus Cauchy–Schwarz gives . ∎
- 1. IPS needs the overlap condition…
- 2. The elliptical potential lemma bounds…
- 3. IPS variance scales like…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Contextual bandits, measured
Exercise 1 (K = 4, d = 5, mean over 3 instances). Regret at T = 500 and T = 2000:
| algorithm | T = 500 | T = 2000 |
|---|---|---|
| LinUCB | 9.4 | 10.5 |
| linear ε-greedy (ε = 0.1) | 31.5 | 106.8 |
| context-blind UCB1 | 252.1 | 991.1 |
LinUCB’s regret nearly stops growing (and is 11.4 at T = 8000). ε-greedy pays its exploration tax forever. Ignoring context is catastrophic: no single action is best everywhere.
Exercise 2: off-policy evaluation (3 actions, logging probabilities 0.2/0.2/0.6, a deterministic target policy, a deliberately misspecified linear reward model; true value 0.633; 200 datasets per n). Bias and RMSE:
| n | IPS | DM | DR |
|---|---|---|---|
| 200 | −0.004, 0.118 | −0.147, 0.160 | −0.012, 0.082 |
| 1000 | −0.002, 0.056 | −0.150, 0.152 | −0.004, 0.038 |
| 5000 | +0.004, 0.024 | −0.149, 0.149 | +0.001, 0.016 |
The direct method’s bias doesn’t shrink with data: the model is wrong. IPS is unbiased and its error falls like 1/√n. DR is unbiased and has 30–40% lower error than IPS.
Contextual bandits in AI, robotics and aerospace
- Terrain-adaptive locomotion: choose gait or speed from terrain features with partial feedback.
- Adaptive communications: pick modulation or coding from channel-state context.
- Safe policy updates: use logged data and DR estimates to vet a new decision rule before flight testing.
- Bridge to RL: contextual bandits are one-step reinforcement learning; OPE ideas extend to multi-step policies.
References
- L. Li, W. Chu, J. Langford, R. E. Schapire (2010). “A contextual-bandit approach to personalized news article recommendation.” WWW.
- Y. Abbasi-Yadkori, D. Pál, C. Szepesvári (2011). “Improved algorithms for linear stochastic bandits.” NeurIPS.
- S. Agrawal, N. Goyal (2013). “Thompson sampling for contextual bandits with linear payoffs.” ICML.
- M. Dudík, J. Langford, L. Li (2011). “Doubly robust policy evaluation and learning.” ICML.
- A. Agarwal, D. Hsu, S. Kale, J. Langford, L. Li, R. E. Schapire (2014). “Taming the monster: a fast and simple algorithm for contextual bandits.” ICML.
- T. Lattimore, C. Szepesvári (2020). Bandit Algorithms. Cambridge University Press (chapters 18–20).