Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Linear Bandits: LinUCB & OFUL

Confidence ellipsoids, the elliptical potential lemma and √T regret in d dimensions.

When rewards are linear in known features, a bandit with millions of arms has only dd unknowns. Optimism then needs a confidence set for a vector, and the right one is an ellipsoid shaped by the data, with a radius from a self-normalized martingale bound. This lesson builds that ellipsoid, proves the elliptical potential lemma that turns it into regret of order dTd\sqrt T, shows that some action sets force that much regret on every algorithm, and asks what happens to Thompson sampling and to the guarantees when the model is only approximately linear.

What you’ll learn

  • State the stochastic linear bandit, and show that the ridge estimator's error is controlled by a self-normalized martingale, which makes the confidence set an ellipsoid.
  • State the confidence-ellipsoid theorem of Abbasi-Yadkori, Pál and Szepesvári with its assumptions.
  • Prove the elliptical potential lemma and derive OFUL's regret of order dTlog⁡Td\sqrt T\log T.
  • Contrast dTd\sqrt T with dTlog⁡K\sqrt{dT\log K} for KK actions per round, and state the matching lower bounds.
  • Explain linear Thompson sampling's extra d\sqrt d and the price of misspecification.

The model, and why the confidence set is an ellipsoid

In round tt the learner receives an action set At⊂Rd\mathcal A_t\subset\R^d, possibly different every round, chooses At∈AtA_t\in\mathcal A_t, and receives Xt=⟨θ⋆,At⟩+ηtX_t=\langle\theta^\star,A_t\rangle+\eta_t. This is the stochastic linear bandit. A contextual bandit with features is the case At={ϕ(xt,a):a=1,…,K}\mathcal A_t=\{\boldsymbol\phi(x_t,a):a=1,\dots,K\}; LinUCB's disjoint model stacks one block of coordinates per arm.

Assume that the noise ηt\eta_t is conditionally RR-sub-Gaussian given the past (bounded or Gaussian noise qualifies), that ∥θ⋆∥2≤S\norm{\theta^\star}_2\le S and that ∥a∥2≤L\norm{a}_2\le L for every action. The regret is RT=∑t(max⁡a∈At⟨θ⋆,a⟩−⟨θ⋆,At⟩)R_T=\sum_t\big(\max_{a\in\mathcal A_t}\langle\theta^\star,a\rangle-\langle\theta^\star,A_t\rangle\big).

DerivationThe error of ridge regression
  1. θ^t−θ⋆  =  Vt−1St  −  λVt−1θ⋆\hat\theta_t-\theta^\star\;=\;V_t^{-1}\mathbf S_t\;-\;\lambda V_t^{-1}\theta^\star

    With Vt=λI+∑s≤tAsAs⊤V_t=\lambda I+\sum_{s\le t}A_sA_s^\top, the ridge estimate is θ^t=Vt−1∑s≤tAsXs\hat\theta_t=V_t^{-1}\sum_{s\le t}A_sX_s. Substitute the model and write St=∑s≤tAsηs\mathbf S_t=\sum_{s\le t}A_s\eta_s for the noise accumulated along the chosen actions:

  2. ∥θ^t−θ⋆∥Vt ≤ ∥St∥Vt−1+λ∥θ⋆∥Vt−1 ≤ ∥St∥Vt−1+λ S\norm{\hat\theta_t-\theta^\star}_{V_t}\ \le\ \norm{\mathbf S_t}_{V_t^{-1}}+\lambda\norm{\theta^\star}_{V_t^{-1}}\ \le\ \norm{\mathbf S_t}_{V_t^{-1}}+\sqrt\lambda\,S

    Measure the error in the norm ∥v∥Vt=v⊤Vtv\norm{v}_{V_t}=\sqrt{v^\top V_tv}. Since ∥Vt−1u∥Vt=∥u∥Vt−1\norm{V_t^{-1}\mathbf u}_{V_t}=\norm{\mathbf u}_{V_t^{-1}} and Vt⪰λIV_t\succeq\lambda I:

  3. So θ⋆\theta^\star lies in an ellipsoid around θ^t\hat\theta_t, stretched along directions the actions have rarely explored, once the noise term is controlled. That term is a self-normalized martingale: the noise sum, measured by the very matrix the actions built. The actions depend on past noise, so fixed-design regression bounds do not apply.

Predict before you look

Take d=10d=10, t=10,000t=10{,}000, R=S=L=λ=1R=S=L=\lambda=1 and δ=0.01\delta=0.01, and bound the determinant by (λ+tL2/d)d(\lambda+tL^2/d)^d. What is the radius βt\beta_t?

Show the answer

9.8

The log term is d2ln⁡(1+t/d)+ln⁡(1/δ)=5ln⁡1001+ln⁡100≈34.54+4.61=39.15\tfrac{d}{2}\ln(1+t/d)+\ln(1/\delta)=5\ln1001+\ln100\approx34.54+4.61=39.15, so βt=2⋅39.15+1≈9.85\beta_t=\sqrt{2\cdot39.15}+1\approx9.85. A one-dimensional Hoeffding width at the same δ\delta is 2ln⁡100≈3\sqrt{2\ln100}\approx3: the factor of about 3 is the price of covering ten directions, and all times at once.

OFUL and the elliptical potential lemma

OFUL (optimism in the face of uncertainty for linear bandits) plays the action with the highest plausible reward over the confidence set Ct−1={θ:∥θ−θ^t−1∥Vt−1≤βt−1}\mathcal C_{t-1}=\{\theta:\norm{\theta-\hat\theta_{t-1}}_{V_{t-1}}\le\beta_{t-1}\}. By Cauchy–Schwarz in the Vt−1V_{t-1} norm the inner maximum has a closed form, and LinUCB's index appears:

At  =  arg max⁡a∈At max⁡θ∈Ct−1⟨θ,a⟩  =  arg max⁡a∈At(⟨θ^t−1,a⟩+βt−1∥a∥Vt−1−1)A_t\;=\;\argmax_{a\in\mathcal A_t}\ \max_{\theta\in\mathcal C_{t-1}}\langle\theta,a\rangle\;=\;\argmax_{a\in\mathcal A_t}\Big(\langle\hat\theta_{t-1},a\rangle+\beta_{t-1}\norm{a}_{V_{t-1}^{-1}}\Big)
LinUCB is this rule with a tuned constant in place of βt−1\beta_{t-1}, and one block of coordinates per arm.
DerivationRegret of OFUL
  1. rt ≤ ⟨θ~t−θ⋆,At⟩ ≤ ∥θ~t−θ⋆∥Vt−1∥At∥Vt−1−1 ≤ 2βt−1∥At∥Vt−1−1r_t\ \le\ \langle\tilde\theta_t-\theta^\star,A_t\rangle\ \le\ \norm{\tilde\theta_t-\theta^\star}_{V_{t-1}}\norm{A_t}_{V_{t-1}^{-1}}\ \le\ 2\beta_{t-1}\norm{A_t}_{V_{t-1}^{-1}}

    Optimism. On the event of the theorem, let θ~t\tilde\theta_t attain the inner maximum and at⋆a^\star_t be the best action in At\mathcal A_t. Then ⟨θ⋆,at⋆⟩≤⟨θ~t,At⟩\langle\theta^\star,a^\star_t\rangle\le\langle\tilde\theta_t,A_t\rangle, and both θ~t\tilde\theta_t and θ⋆\theta^\star lie in Ct−1\mathcal C_{t-1}, so the round's regret is at most twice the width:

  2. det⁡Vt=det⁡(Vt−1+AtAt⊤)=det⁡Vt−1 (1+∥At∥Vt−1−12)\det V_t=\det\big(V_{t-1}+A_tA_t^\top\big)=\det V_{t-1}\,\Big(1+\norm{A_t}^2_{V_{t-1}^{-1}}\Big)

    If mean rewards lie in [−1,1][-1,1], also rt≤2r_t\le2, and with β≥1\beta\ge1 the two combine into rt≤2βTmin⁡{1,∥At∥Vt−1−1}r_t\le2\beta_T\min\{1,\norm{A_t}_{V_{t-1}^{-1}}\}. The elliptical potential lemma. Each action multiplies the determinant of the design matrix by one plus its squared width, by the matrix determinant lemma:

  3. ∑t=1Tmin⁡{1,∥At∥Vt−1−12} ≤ 2∑t=1Tlog⁡(1+∥At∥Vt−1−12)=2log⁡det⁡VTdet⁡V0 ≤ 2dlog⁡(1+TL2dλ)\sum_{t=1}^T\min\Big\{1,\norm{A_t}^2_{V_{t-1}^{-1}}\Big\}\ \le\ 2\sum_{t=1}^T\log\Big(1+\norm{A_t}^2_{V_{t-1}^{-1}}\Big)=2\log\frac{\det V_T}{\det V_0}\ \le\ 2d\log\Big(1+\frac{TL^2}{d\lambda}\Big)

    Since min⁡{1,u}≤2log⁡(1+u)\min\{1,u\}\le2\log(1+u) for u≥0u\ge0, the squared widths telescope into a log-determinant, which the AM–GM bound caps:

  4. RT ≤ T∑trt2 ≤ 2βT2dTlog⁡(1+TL2dλ) = O(dTlog⁡T)R_T\ \le\ \sqrt{T\sum_tr_t^2}\ \le\ 2\beta_T\sqrt{2dT\log\Big(1+\frac{TL^2}{d\lambda}\Big)}\ =\ \order{d\sqrt T\log T}

    Cauchy–Schwarz over the rounds finishes the proof, with βT\beta_T of order dlog⁡T\sqrt{d\log T}:

The elliptical potential lemma has a vivid reading: only about dlog⁡Td\log T rounds can have a large width. With d=10d=10, T=10,000T=10{,}000 and L=λ=1L=\lambda=1, the sum of min⁡{1,width2}\min\{1,\text{width}^2\} over all 10,000 rounds is at most 20ln⁡1001≈13820\ln1001\approx138; most actions, by then, point in directions the data already cover. The same quadratic form is the elliptical exploration bonus of E3B in Exploration Bonuses at Scale.

How good is d√T?

Two lower bounds frame the result. For general action sets, dTd\sqrt T cannot be improved: Dani, Hayes and Kakade (2008) showed that the minimax regret over some compact action sets in Rd\R^d is of order dTd\sqrt T up to logarithmic factors, and Lattimore and Szepesvári (ch. 24) give clean Ω(dT)\Omega(d\sqrt T) constructions for the hypercube and the unit ball. With KK actions per round the picture changes: Chu, Li, Reyzin and Schapire (2011) proved regret O(Tdlog⁡3(KTlog⁡(T)/δ))\order{\sqrt{Td\log^3(KT\log(T)/\delta)}} with probability 1−δ1-\delta for an algorithm called SupLinUCB, and a lower bound Ω(Td)\Omega(\sqrt{Td}).

SettingUpper boundLower bound
Large or infinite action sets in Rd\R^dOFUL: O~(dT)\tilde{\mathcal O}(d\sqrt T)Ω(dT)\Omega(d\sqrt T) for some sets, such as the hypercube and the ball
KK actions per round, features in Rd\R^dSupLinUCB: O(dTlog⁡3(KTlog⁡(T)/δ))\order{\sqrt{dT\log^3(KT\log(T)/\delta)}}Ω(dT)\Omega(\sqrt{dT})
KK unrelated arms (one-hot features, d=Kd=K)UCB-type: O~(KT)\tilde{\mathcal O}(\sqrt{KT})Ω(KT)\Omega(\sqrt{KT})
Worst-case regret of stochastic linear bandits. The extra d\sqrt d of the first row is the price of having to compete on every direction at once.

Why does OFUL pay the extra d\sqrt d? Its analysis needs the confidence set to hold for whatever action the algorithm picks, and those actions depend on the same noise that built the estimate, so it must cover every direction at once, hence βt∼dlog⁡t\beta_t\sim\sqrt{d\log t}. SupLinUCB arranges, by a layered elimination, that the rewards used in each estimate are independent of the choices made with it, which allows a union bound over just KK actions. LinUCB itself, the version used in practice, has no proof of this rate. Computation matters too: for KK actions the OFUL index costs O(Kd2)\order{Kd^2} per round, but maximizing ⟨θ^,a⟩+β∥a∥V−1\langle\hat\theta,a\rangle+\beta\norm{a}_{V^{-1}}, a convex function of aa, over a general convex set is a hard nonconvex problem, NP-hard for some sets such as the hypercube, and Dani et al.'s efficient variant for polytopes loses a factor d\sqrt d.

Check your understanding

Each round offers K=20K=20 actions described by d=1,000d=1{,}000 features, and the best action changes with the context. Which worst-case regret rate is achievable against the best linear policy, up to logarithmic factors?

  1. dTd\sqrt T, as for any linear bandit
  2. KT\sqrt{KT}, by ignoring the features
  3. dT\sqrt{dT}, because there are only KK actions per round
  4. KdTK\sqrt{dT}
Show the answer

C. dT\sqrt{dT}, because there are only KK actions per round

With finitely many actions, a union bound over KK replaces the cost of covering all dd directions, so SupLinUCB attains O(dTlog⁡3(KTlog⁡T/δ))\order{\sqrt{dT\log^3(KT\log T/\delta)}}, and the Ω(dT)\Omega(\sqrt{dT}) lower bound shows that this is optimal up to logarithms. Ignoring the features would compete only with the best fixed action, not with the best policy.

Thompson sampling, misspecification and beyond

Linear Thompson sampling draws θ~t∼N(θ^t−1,v2Vt−1−1)\tilde\theta_t\sim\mathcal N(\hat\theta_{t-1},v^2V_{t-1}^{-1}) and plays arg max⁡a⟨θ~t,a⟩\argmax_a\langle\tilde\theta_t,a\rangle. Its Bayesian regret is O~(dT)\tilde{\mathcal O}(d\sqrt T), by the confidence-ellipsoid route or the information ratio d/2d/2 (Regret Bounds for Thompson Sampling). Frequentist analyses ask for more: a sample must be optimistic, ranking the best action at or above its true value, with probability bounded away from zero. The true parameter can sit about d\sqrt d posterior standard deviations from the estimate along the best action's direction, while a plain posterior sample deviates by about one standard deviation along any fixed direction, so it would rarely be optimistic. Inflating the spread to vv of order d\sqrt d fixes this at a price of d\sqrt d: regret O~(d3/2T)\tilde{\mathcal O}(d^{3/2}\sqrt T) (Agrawal & Goyal, 2013; Abeille & Lazaric, 2017). Hamidi and Bayati (2020) argue that this is not an artifact of the proofs: they prove the inflation fundamental, showing that without it linear Thompson sampling can suffer linear regret.

Misspecification. Real rewards are only approximately linear: E[X∣a]=⟨θ⋆,a⟩+ϵ(a)\E[X\mid a]=\langle\theta^\star,a\rangle+\epsilon(a) with ∣ϵ(a)∣≤ϵ\abs{\epsilon(a)}\le\epsilon. The ellipsoid then surrounds the wrong point. Lattimore, Szepesvári and Weisz (2020) prove regret of order dTlog⁡K+ϵTdlog⁡T\sqrt{dT\log K}+\epsilon T\sqrt d\log T with KK actions, and show that a learner can always find an action within O(ϵd)O(\epsilon\sqrt d) of the best; a lower-bound construction of Du, Kakade, Wang and Yang (2020) shows that with very many actions this amplification by d\sqrt d cannot be avoided in general. Richer features reduce ϵ\epsilon but raise d\sqrt d.

Beyond linear. Generalized linear models with a link function (GLM-UCB; Filippi, Cappé, Garivier & Szepesvári, 2010) handle click probabilities, and kernel methods (GP-UCB; Srinivas, Krause, Kakade & Seeger, 2010) handle smooth reward functions, with an information-gain quantity in place of dd. With neural networks, the norm in practice, guarantees of this kind hold at best for linearizations, and the exploration rules in use, ε-greedy, ensembles and the regression-oracle methods of Oracle-Efficient Contextual Bandits, are justified mostly empirically.

Key takeaways

  • In a linear bandit the ridge error is a self-normalized martingale plus a bias of at most λS\sqrt\lambda S. With probability 1−δ1-\delta, θ⋆\theta^\star lies for all tt at once in an ellipsoid around θ^t\hat\theta_t, of radius R2log⁡(det⁡(Vt)1/2det⁡(λI)−1/2/δ)+λSR\sqrt{2\log(\det(V_t)^{1/2}\det(\lambda I)^{-1/2}/\delta)}+\sqrt\lambda S, of order dlog⁡t\sqrt{d\log t}.
  • OFUL and LinUCB play arg max⁡a⟨θ^,a⟩+β∥a∥V−1\argmax_a\langle\hat\theta,a\rangle+\beta\norm{a}_{V^{-1}}. Each round's regret is at most 2βmin⁡{1,width}2\beta\min\{1,\text{width}\}, and the elliptical potential lemma caps ∑min⁡{1,width2}\sum\min\{1,\text{width}^2\} by 2dlog⁡(1+TL2/(dλ))2d\log(1+TL^2/(d\lambda)), giving regret O~(dT)\tilde{\mathcal O}(d\sqrt T).
  • Some action sets force Ω(dT)\Omega(d\sqrt T) on every algorithm; with KK actions per round, regret of order dT\sqrt{dT} up to logarithms is achievable (SupLinUCB) and optimal.
  • Linear Thompson sampling has Bayesian regret O~(dT)\tilde{\mathcal O}(d\sqrt T), but frequentist proofs inflate the posterior and lose d\sqrt d, an inflation shown necessary in the worst case. Misspecification by ϵ\epsilon costs about ϵTd\epsilon T\sqrt d.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why is OFUL's confidence set an ellipsoid shaped by VtV_t rather than a ball?

  1. Because the noise is Gaussian
  2. Because the reward is linear in the action
  3. Because the estimate is precise in directions the actions have explored and imprecise in others, and VtV_t records how much each direction was explored
  4. Because an ellipsoid is easier to optimize over than a ball
Show the answer

C. Because the estimate is precise in directions the actions have explored and imprecise in others, and VtV_t records how much each direction was explored

The error bound ∥θ^t−θ⋆∥Vt≤βt\norm{\hat\theta_t-\theta^\star}_{V_t}\le\beta_t measures the error with Vt=λI+∑AsAs⊤V_t=\lambda I+\sum A_sA_s^\top: along a direction sampled often, VtV_t is large and the allowed error small. A ball would have to be as wide as the least-explored direction allows, wasting exploration on well-understood directions.

Question 2

What does the elliptical potential lemma state?

  1. ∑tmin⁡{1,∥At∥Vt−1−12}≤2log⁡(det⁡VT/det⁡V0)≤2dlog⁡(1+TL2/(dλ))\sum_t\min\{1,\norm{A_t}^2_{V_{t-1}^{-1}}\}\le2\log(\det V_T/\det V_0)\le2d\log(1+TL^2/(d\lambda)): only about dlog⁡Td\log T rounds can have a large width
  2. The confidence radius βt\beta_t grows like dlog⁡t\sqrt{d\log t}
  3. Every action's width shrinks like 1/t1/\sqrt t
  4. The regret of any algorithm is at least dTd\sqrt T
Show the answer

A. ∑tmin⁡{1,∥At∥Vt−1−12}≤2log⁡(det⁡VT/det⁡V0)≤2dlog⁡(1+TL2/(dλ))\sum_t\min\{1,\norm{A_t}^2_{V_{t-1}^{-1}}\}\le2\log(\det V_T/\det V_0)\le2d\log(1+TL^2/(d\lambda)): only about dlog⁡Td\log T rounds can have a large width

Each action multiplies det⁡V\det V by 1+width21+\text{width}^2, and det⁡VT\det V_T is at most (λ+TL2/d)d(\lambda+TL^2/d)^d, so the widths cannot be large often. Note that it bounds a sum over rounds: individual widths need not shrink at any rate, since the learner may keep choosing new directions, but it cannot do so for long.

Question 3

Why do frequentist analyses of linear Thompson sampling inflate the posterior's spread by a factor of about d\sqrt d?

  1. To speed up the computation of the samples
  2. Because the noise variance is unknown
  3. To make the regret bound independent of dd
  4. So that each sample is optimistic with probability bounded away from zero: the true parameter can lie about d\sqrt d posterior standard deviations from the estimate along the best action's direction, while a plain sample moves about one
Show the answer

D. So that each sample is optimistic with probability bounded away from zero: the true parameter can lie about d\sqrt d posterior standard deviations from the estimate along the best action's direction, while a plain sample moves about one

The confidence radius grows like dlog⁡t\sqrt{d\log t} in units of the posterior's spread, but along any fixed direction a Gaussian sample deviates by about one standard deviation, so it would rarely rank the best action above its true value. Inflating by d\sqrt d restores a constant probability of optimism and costs a factor d\sqrt d: O~(d3/2T)\tilde{\mathcal O}(d^{3/2}\sqrt T). Hamidi and Bayati argue that the inflation is necessary in the worst case.

Question 4

Mean rewards are within ϵ\epsilon of a linear function of dd features. What does the misspecification cost, at best, over TT rounds?

  1. Nothing, as long as ϵ\epsilon is small
  2. An extra term of order ϵTd\epsilon T\sqrt d: the approximation error is amplified by d\sqrt d
  3. An extra term of order ϵT\epsilon\sqrt T
  4. An extra term of order ϵT/d\epsilon T/d, since more features average out the error
Show the answer

B. An extra term of order ϵTd\epsilon T\sqrt d: the approximation error is amplified by d\sqrt d

Lattimore, Szepesvári and Weisz prove regret of order dTlog⁡K+ϵTdlog⁡T\sqrt{dT\log K}+\epsilon T\sqrt d\log T, and a learner can always find an action within O(ϵd)O(\epsilon\sqrt d) of optimal; lower-bound constructions show that the d\sqrt d cannot be removed in general. Adding features lowers ϵ\epsilon but raises d\sqrt d.

Further reading

  • Y. Abbasi-Yadkori, D. Pál & Cs. Szepesvári, "Improved algorithms for linear stochastic bandits," Advances in Neural Information Processing Systems 24 (2011).
  • W. Chu, L. Li, L. Reyzin & R. E. Schapire, "Contextual bandits with linear payoff functions," International Conference on Artificial Intelligence and Statistics (2011).
  • V. Dani, T. P. Hayes & S. M. Kakade, "Stochastic linear optimization under bandit feedback," Conference on Learning Theory (2008).
  • T. Lattimore, Cs. Szepesvári & G. Weisz, "Learning with good feature representations in bandits and in RL with a generative model," International Conference on Machine Learning (2020).
  • T. Lattimore & C. Szepesvári, Bandit Algorithms, ch. 19–20 and 24 (Cambridge University Press, 2020).