Contextual and Linear Bandits
Summary
The general Thompson-sampling algorithm (Algorithm 4.2, Bernoulli Bandit and Thompson Sampling Algorithm) extends far past independent Bernoulli arms: rewards can be linear or logistic (generalized linear) functions of a parameter vector, actions can carry side information/context observed before each decision, and the parameter space can be a matrix (product assortment) rather than a vector. This note collects the tutorial’s three running non-trivial-structure examples — correlated shortest-path edges, contextual news-article recommendation, and assortment optimization — plus the general recipe for turning “time-varying constraints” and “side information” into a straightforward extension of TS.
Overview
The unifying move in all these extensions is the same: TS never needed to be small or to be low-dimensional — it only needs (a) a posterior over that can be sampled or approximated, and (b) an ability to solve for a given sampled . Linear/GLM structure buys efficient conjugate (or near-conjugate) posterior updates; context and constraints are absorbed by simply augmenting the action space per period.
Main Content
Correlated linear-Gaussian rewards (Example 4.2)
Extending the independent log-Gaussian edge-time model (Example 4.1, Bernoulli Bandit and Thompson Sampling Algorithm), suppose travel times share common shocks: , where is a day-wide factor and are factors shared within each half of the graph. Taking logs, is jointly Gaussian with mean and covariance , updated in closed form via
for an edge-wise “information” contribution built from the observed edges’ precision. TS samples , exponentiates to get , and solves the deterministic shortest-path problem as before.
Coherent vs. misspecified TS (Fig. 4.3)
“Coherent TS” models the true edge-correlation structure above; “misspecified TS” pretends edges are independent (as in Example 4.1) despite the correlated data-generating process. Coherent TS substantially outperforms misspecified TS in both regret and cumulative-travel-time-vs.-optimal — a direct demonstration that correctly modeling dependencies among actions (not just marginal per-action uncertainty) materially accelerates learning, exactly the lesson CascadeTS also relies on (see UCB and Greedy Algorithms for Bandits).
Contextual bandits: side information before each decision (§6.2)
Contextual online decision problem
Before choosing , the agent observes an independent random context , and the outcome distribution becomes . This is handled without any new algorithm by augmenting the action to and constraining its choice to — a time-varying constraint set — after which ordinary TS (Algorithm 4.2 of Bernoulli Bandit and Thompson Sampling Algorithm) applies unchanged to .
News article recommendation (§7.1)
Logit contextual bandit for personalized recommendation (Li et al. 2010; Chapelle & Li 2011)
At each round , the website observes a user feature vector , chooses an article from , and observes a binary “liked” reward. Each article has parameter ; conditional on , a positive review occurs with probability for logistic function — a generalized linear model per article. Per-period regret is .
Because the logit link breaks Gaussian conjugacy, exact posterior updates are intractable; the tutorial applies the Laplace approximation and Langevin Monte Carlo approximate-sampling schemes of Approximate Thompson Sampling and Practical Extensions and finds both substantially outperform tuned -greedy (Fig. 7.1). Two generalization limitations are noted: (1) as written, must be estimated separately per article, with no transfer learning across articles — fixed by instead using a feature vector that encodes user–article interactions with a single shared , enabling learning about one article to inform others; (2) the article set was assumed time-invariant, whereas real news sites continually retire/add articles — still a contextual bandit, just with a time-varying as in §6.2 above.
Product assortment optimization (§7.2)
Assortment planning with substitute/complement effects
products, profit per unit of product . The agent offers a subset ; log-demand for included product is Gaussian, , where — the diagonal is product ‘s own popularity, off-diagonals capture how offering shifts demand for (substitution/complementarity). Expected profit is .
Here is a matrix, not a vector, but the same multivariate-Gaussian-conjugacy machine applies after vectorizing (stacking its columns into ) and forming a Kronecker-product design matrix from the offered assortment and a selection matrix ; the posterior mean/covariance update is the same generalized-least-squares-looking formula as ordinary Bayesian linear regression. TS strictly outperforms greedy and tuned -greedy in simulation (Fig. 7.2) — greedy in particular performs poorly because it fails to actively probe substitution effects.
Connections
- This note’s three examples are all instances of the general Thompson/greedy algorithms in Bernoulli Bandit and Thompson Sampling Algorithm — the “reward model” becomes linear-Gaussian or logistic instead of Bernoulli.
- Exact conjugate updates are available for the linear-Gaussian cases (correlated edges, assortment); the logistic news-recommendation case requires the approximate-sampling machinery of Approximate Thompson Sampling and Practical Extensions.
- The linear-bandit regret bound and the eluder-dimension generalization in Regret Bounds for Thompson Sampling are stated precisely for the reward models introduced here.
- Sparse linear models and assortment diversification reappear in Regret Bounds for Thompson Sampling as two of the four documented TS failure modes (TS explores one-hot/single-type actions when a more diverse or bisection-search-like strategy would learn faster) — a caution against naively deploying the algorithms in this note without checking the information-ratio diagnosis.
See Also
- Bernoulli Bandit and Thompson Sampling Algorithm — the base algorithm these examples specialize
- Approximate Thompson Sampling and Practical Extensions — Laplace/Langevin approximations needed for the logistic news-recommendation model
- Regret Bounds for Thompson Sampling — linear/eluder-dimension regret bounds, and the assortment/sparse-model failure modes
- UCB and Greedy Algorithms for Bandits — the ellipsoidal- vs. hyper-rectangular-confidence-set argument for why modeling correlation among actions (as in coherent TS here) matters