Contextual Bandits
Bandits with side information. Why ignoring context makes the benchmark too weak, and the general trade-off of choosing a competitor class (meaningful benchmark versus learnability). Adversarial k-armed contextual bandits; regret against the best context-to-arm map; one Exp3 per context and its 2√(nk|C| log k) worst case. Shrinking the competitor class with partitions, similarity constraints, or supervised-learning predictors. Bandits with expert advice; Exp4 (exponential weights over experts, importance-weighted action estimates propagated through the advice matrix), its √(2nk log M) regret, recovering the per-context bound with M = k^|C|, and the agreement-adaptive √(E*ₙ log M) bound with a time-varying learning rate. Notes on computation (O(M + k) per round), optimisation oracles, reduction of stochastic contextual bandits to cost-sensitive ERM, Exp4-IX, non-oblivious experts, finite-memory policies, epoch-greedy ETC at O(n^{2/3}), and VC-class competitors.
Corresponds to Lattimore & Szepesvári, Part V introduction and Chapter 18.
Motivation: real problems have many actions and side information
IntuitionWhy the earlier algorithms aren’t enough
A targeted-advertising system may have thousands of actions, and before each decision it sees contextual information about the user and the ads. The algorithms so far can’t use side information, and ignoring it makes the problem effectively non-stationary: the best ad for a teenager and for a retiree differ, so “the best single ad in hindsight” is a poor target.
NoteHow Part V handles this
- Large action sets: add structure so that what is learned about one action generalizes to others. Ads have features (topic, format), and the reward is modelled as a nice function (linear, smooth) of the features.
- Context: model the mean reward as a function of context features and action features together. As later chapters show, this amounts to an action set that changes every round.
- Linear structure (Chapter 19 onward) is the main case: stochastic-linear-bandits.
- Computation becomes a central concern, which it never was with a few arms.
- Delayed or unattributed rewards (Part VII) and non-stationarity (Chapter 31) are treated elsewhere.
ImportantChoosing a benchmark is a trade-off
A weak benchmark is pointless: matching it perfectly can still mean performing badly. A strong benchmark is more meaningful but harder to learn to compete with, and the learning penalty must be weighed against the gain. This is the bandit version of the bias–variance trade-off, and it runs through this whole chapter. The chapter first shows how to compete with richer benchmarks; it does not settle how rich to make them.
Contextual bandits: one bandit per context
DefinitionAdversarial -armed contextual bandit
The adversary secretly fixes rewards with and contexts with , an arbitrary fixed set. In each round the learner:
- observes ;
- picks a distribution and samples ;
- observes only .
flowchart LR A["Adversary fixes rewards x_t and contexts c_t"] --> C["Learner sees context c_t"] C --> P["Learner picks P_t, samples A_t"] P --> O["Observes only X_t = x_t,A_t"] O --> C
DefinitionContextual regret
Compete with the best context-dependent choice in hindsight:
Equivalently, with the set of all maps ,
| Component | Detail |
|---|---|
| Benchmark | The best policy in hindsight. |
| Versus Chapter 11 | There, contained only the constant maps. |
| Randomness | Only the learner’s, since rewards and contexts are fixed in advance. |
One Exp3 per context
AlgorithmIndependent Exp3 instances
If is finite, run a separate Exp3 for each context, and in round consult only the instance for . Each instance’s regret is
WarningUse an anytime Exp3
isn’t known in advance, so the learning rate can’t be tuned to it. Use a version with a decreasing learning rate (Exercise 28.13), for which (18.2) holds without knowing .
TheoremRegret of one Exp3 per context
ProofCauchy–Schwarz on the context counts (Exercise 18.1)
, with equality when every context occurs times. Equivalently, by Jensen, uniform context frequencies are the worst case. With one context the bound reduces to the ordinary .
∎
RemarkWhich bound to prefer
Ignoring context, Exp3 guarantees . Per-context Exp3 guarantees . The second benchmark is higher but the penalty is larger by . For large and useful contexts the second wins; it is vacuous whenever .
Bandits with expert advice
The problem. When is large, one bandit per context wastes almost all the data: each context is seen too rarely to learn anything. But large context sets are rarely unstructured. In movie recommendation, the context (age, demographics, viewing history) lives in a combinatorially large space, yet similar users tend to like similar movies. So compete with a smaller, smarter set of policies.
ExampleWays to shrink
| Idea | Competitor class | Algorithmic consequence |
|---|---|---|
| Partitions | maps constant on each part of a partition of | one Exp3 per part: regret depends on , not |
| Similarity | maps whose average dissimilarity is at most | a meaningful target, but no simple Exp3 meta-algorithm |
| Supervised learning | predictors trained offline on batch data | compete online with the best of them, with no need to pick one by offline evaluation |
IntuitionOnce is fixed, contexts barely matter
Each round, all a learner needs is what each policy recommends now. That suggests forgetting the internal structure of and treating its members as black-box experts.
DefinitionBandits with expert advice
experts. In round each expert announces a probability vector over actions (it may randomize), collected in the advice matrix . The learner observes , chooses , samples and receives . The regret is against the best expert in hindsight:
where is expert ‘s expected reward in round . The experts are oblivious: their advice doesn’t depend on the learner’s actions.
RemarkMore general than contextual bandits
A contextual bandit is the special case where each expert is a fixed map , with . This is the “socks for feet” picture: experts look at the context and recommend; the learner decides whom to trust.
Exp4
AlgorithmExp4 — “exponential weighting for exploration and exploitation with experts” (Algorithm 11)
Input . Set (a row vector over experts). For :
- receive advice ;
- play , i.e. sample an expert , then ;
- receive ;
- estimate action rewards: ;
- propagate to experts: , so expert gets ;
- exponential weights over experts: .
IntuitionScore experts, not arms
Exp3 keeps weights on arms. Exp4 keeps weights on experts: it estimates every arm’s reward by importance weighting, credits each expert with what it would have earned in expectation under its own advice, and reweights. With this is the original Exp4; gives Exp4-IX (implicit exploration).
WarningCost
memory and computation per round (sampling in two stages). Practical only when and are both modest, which rules out naive use with combinatorially many experts.
Regret analysis
TheoremTheorem 18.1 — Regret of Exp4
With and ,
LemmaLemma 18.2 — Exponential weights over experts
For any ,
This is exactly the potential argument of Theorem 11.2 with experts in place of arms (Exercise 18.2). It needs , which holds because each and is a convex combination of them.
ProofProof of Theorem 18.1: unbiased propagation, then a variance bound of exactly
Step 1: The benchmark is fixed. Experts are oblivious, so the best expert is deterministic (18.8).
Step 2: Unbiasedness carries through the advice. With , , so (18.10). And , whose conditional mean is the learner’s expected reward. Taking expectations in Lemma 18.2,
Step 3: Switch to losses. With and ,
using .
Step 4: Averaging over experts gives exactly .
Step 5: Tune. .
∎
ImportantExperts cost only
The variance term is per round regardless of : an expert’s estimate is noisy only through the arms it recommends, and averaged over the learner’s own distribution this always sums to . The number of experts enters only through the starting uncertainty . That is why exponentially many experts are statistically affordable.
CorollaryContextual bandits recovered and generalized
- All maps on a finite context set: , so and , the per-context Exp3 bound with a slightly better constant.
- Any finite class of maps , with arbitrary or infinite: . The size of the context space no longer matters, only the size of the policy class.
Adapting to agreement among experts
DefinitionEffective number of experts
If all experts agree, each round contributes , so . In general (Exercise 18.7)
since and . So is an effective number of experts, measuring how much they disagree.
TheoremTheorem 18.3 — Agreement-adaptive regret
With time-varying learning rate , for a universal constant ,
(Proof: Exercise 18.4, adapting the Exp3 analysis to decreasing learning rates; see Exercises 28.12–28.13.)
IntuitionLearning is easy when experts agree
If every expert says the same thing, there is nothing to learn, and the bound grows like rather than . The bound is data-dependent (in adversarial bandits, data and instance coincide), never worse than (18.7) up to constants, and, since doesn’t use , the algorithm is anytime. This is the first time-varying learning rate in the book; they become a main tool for adapting to the instance later.
Notes and extensions
RemarkExp4 as a building block
Define your own experts and Exp4 gives a regret bound for free, though not always an efficient algorithm.
- Non-stationary bandits (Chapter 31): experts are switching sequences of arms. One of the rare cases where Exp4 runs efficiently with combinatorially many experts.
- Finite-memory policies (Exercise 18.5): with observations and experts all maps of the last observations, and .
- When Exp4 isn’t computationally efficient, it is still a good way to find out what regret is statistically achievable.
WarningComputation is the real obstacle
In general there is no way around per round. One escape is an optimisation oracle that, given contexts and reward vectors, returns the best expert in hindsight (the offline problem (18.8)). Chapter 30 shows follow-the-perturbed-leader with such an oracle for combinatorial bandits, though those settings carry extra information that makes reward estimation possible. Note that ERM can be NP-hard even for linear classifiers.
TheoremStochastic contextual bandits: epoch-greedy ETC (Exercise 18.8)
Contexts i.i.d. from , rewards from with mean , policy value , and regret . Explore uniformly for rounds, estimate , then commit to using the oracle. For finite and tuned ,
DerivationWhere comes from
Each is an average of i.i.d. unbiased terms in with variance at most (the indicator fires with probability ). By Bernstein and a union bound over , every estimate is within about of the truth (the range term is lower order at the optimal ). So the committed policy loses at most about per round, and . Balancing at gives the bound. Using Hoeffding with range instead would give the worse . (Sketch worked here.) This is the explore-then-commit version of epoch-greedy (Langford–Zhang 2008), the contextual cousin of ETC.
RemarkReducing contextual bandits to cost-sensitive ERM
Agarwal et al. (2014) give a polynomial-time algorithm with regret about that of Theorem 18.1, using only an ERM oracle. Each round it forms importance-weighted reward estimates, estimates every expert’s regret, and solves a feasibility problem for a sparse distribution over experts whose importance weights stay bounded while its average estimated regret stays small. The distribution is recomputed on an exponentially growing schedule. Any progress on cost-sensitive ERM translates directly into contextual bandits. Earlier attempt: Dudík et al. (2011).
TheoremInfinite policy classes with finite VC dimension (Exercise 18.9)
For stochastic contextual bandits with and , some policy achieves
Explore for an initial period, keep one representative from each group of policies that agree on the observed contexts, and run Exp4 on those. Sauer’s lemma bounds the number of representatives by , so . Exchangeability of i.i.d. contexts makes the representatives behave like the full class on the remaining rounds. (Beygelzimer et al. 2011.)
RemarkHigh probability and non-oblivious experts
- Exp4-IX (Exercise 18.3; Neu 2015): with probability , , the analogue of Theorem 12.1. Exp3.P generalizes too (Beygelzimer et al. 2011).
- Non-oblivious experts (Exercise 18.6): define . Then always (the max of expectations is at most the expectation of the max), and Theorem 18.1 holds for : the proof never needs a deterministic if the comparison expert is fixed before taking expectations. A non-trivial bound on itself is open.
- Lower bounds depend on the experts’ structure. They are sometimes tight (examples come later), sometimes not.
RemarkHistory and related settings
Exp4 is due to Auer et al. (2002); Theorem 18.1 matches their result with a slightly smaller constant. McMahan–Streeter (2009) observed that expert agreement, not or , is what matters, and optimized the played distribution to stay close to while exploring every expert. Theorem 18.3’s learning-rate-only adaptation appears to be new. Other settings: FTPL with static experts and contexts known upfront (Syrgkanis et al. 2016); i.i.d. contexts with adversarial rewards (Lazaric–Munos 2009; Rakhlin–Sridharan 2016, including approximate oracles); bandit multiclass classification with mistake bounds against convex surrogates (Kakade et al. 2008). Survey: Tewari–Murphy (2017).
Quick reference
| Object | Statement | Note |
|---|---|---|
| Contextual regret | = all maps gives (18.1) | |
| One Exp3 per context | needs anytime Exp3 | |
| Worst case | uniform context frequencies | Cauchy–Schwarz |
| Vacuous when | richer benchmark, larger penalty | |
| Expert advice | rows ; regret vs best expert | oblivious experts |
| Exp4 play | pick an expert, follow it | |
| Exp4 update | ; | loss-based IW estimates |
| Exp4 regret | at | variance term is exactly |
| Finite | context-space size irrelevant | |
| Agreement | if experts agree | |
| Adaptive Exp4 | with | anytime |
| Cost | per round | oracles needed for large |
| Epoch-greedy ETC | stochastic, oracle-efficient | |
| VC classes | Sauer’s lemma + Exp4 | |
| Finite memory | experts on the last observations |
Facts to keep to hand
- The competitor class is a modelling choice. Bigger classes mean more meaningful regret and larger regret: per-context learning pays , and is vacuous until .
- Score experts, not arms. Exp4 importance-weights the arms, credits each expert through its advice, and runs exponential weights over experts. Its variance term stays per round, so the number of experts costs only .
- Statistics is cheap; computation is not. is achievable for any finite (or finite-VC) policy class, but naive Exp4 is linear in . Oracle-based reductions to cost-sensitive ERM are the practical route.
- Agreement among experts is what makes learning hard or easy. The effective number of experts , captured by a time-varying learning rate, interpolates between full-information-like and bandit-like regret.
References
- Lattimore & Szepesvári, Bandit Algorithms — Part V introduction; Chapter 18
- Shalev-Shwartz & Ben-David, Understanding Machine Learning (2014) — VC dimension, Sauer’s lemma, hardness of ERM