Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Oracle-Efficient Contextual Bandits

Reducing exploration to regression: from ε-greedy to SquareCB.

With a class of a billion policies, EXP4 achieves the optimal regret, of order KTlog⁡N\sqrt{KT\log N}, by keeping a weight for every policy, which no computer can do. A question shaped a decade of contextual bandit research: can exploration be reduced to the supervised learning we already do well, calling a classifier or a regression solver only a few times? This lesson follows the answer from epoch-greedy's T2/3T^{2/3}, through the "monster" algorithm that reaches T\sqrt T with a classification oracle, to SquareCB and FALCON, where inverse-gap weighting turns any regression method into an optimal contextual bandit, and to the decision-estimation coefficient that explains why it works.

What you’ll learn

  • Define regret against a policy class and the oracle model of computation, and explain why EXP4 is statistically optimal but computationally infeasible.
  • Explain epoch-greedy and the optimization problem of ILOVETOCONBANDITS, and why controlling the variance of importance-weighted estimates is the crux.
  • Prove the per-round inequality of inverse-gap weighting, and derive SquareCB's regret bound in terms of the regression oracle's regret.
  • Describe the decision-estimation coefficient as a general account of the statistical complexity of exploration.

A policy class and an oracle

Fix a class Π\Pi of NN policies, maps from contexts to KK actions: all depth-5 decision trees on some features, say, or all argmax rules of linear scores. The learner competes with the best policy in the class, RT=max⁡π∈Π∑trt(π(xt))−∑trt(At)R_T=\max_{\pi\in\Pi}\sum_t r_t(\pi(x_t))-\sum_t r_t(A_t) in expectation, where rt(a)r_t(a) is the reward action aa would have earned in round tt.

Two kinds of oracle stand in for supervised learning. A cost-sensitive classification oracle receives contexts with a cost for every action and returns the policy in Π\Pi with the lowest total cost, an empirical risk minimization that standard classifiers solve approximately and at scale. A regression oracle fits a reward model f∈Ff\in\mathcal F to (x,a,r)(x,a,r) data by least squares, either once on a batch (offline) or by updating after every example (online); regression-based methods assume realizability, E[r∣x,a]=f⋆(x,a)\E[r\mid x,a]=f^\star(x,a) for some f⋆∈Ff^\star\in\mathcal F. An algorithm is oracle-efficient if it runs in polynomial time and makes few oracle calls.

EXP4 (Auer, Cesa-Bianchi, Freund & Schapire, 2002) treats every policy as an expert: it keeps exponential weights over the NN policies, plays the mixture of actions they recommend with a little uniform exploration, and updates every policy with the importance-weighted estimate of its reward, as EXP3 does for arms (Adversarial Bandits & EXP3). Its regret is of order KTln⁡N\sqrt{KT\ln N}, even when contexts and rewards are chosen by an adversary, and Seldin and Lugosi (2016) showed that no algorithm can beat order KTln⁡N/ln⁡K\sqrt{KT\ln N/\ln K}. Chase, Ito and Mehalel (2026) closed the remaining gap with a lower bound matching an upper bound of Kale (2014): the minimax regret is of order KTln⁡(N/K)\sqrt{KT\ln(N/K)}. The logarithm makes huge classes statistically affordable, but the weights cost time proportional to NN in every round.

AlgorithmOracleOracle calls over TT roundsRegret
EXP4 (Auer et al., 2002)None: enumerates Π\PiWork proportional to NN per roundO(KTln⁡N)\order{\sqrt{KT\ln N}}, even against adversaries
Epoch-greedy (Langford & Zhang, 2008)ClassificationAbout one per epochOrder T2/3T^{2/3}, up to factors in KK and ln⁡N\ln N
ILOVETOCONBANDITS (Agarwal et al., 2014)ClassificationO~(KT/ln⁡N)\tilde{\mathcal O}(\sqrt{KT/\ln N})Order KTln⁡N\sqrt{KT\ln N}, up to logarithms
SquareCB (Foster & Rakhlin, 2020)Online regressionOne update per roundO(KT⋅RegSq(T))\order{\sqrt{KT\cdot\mathrm{Reg}_{\mathrm{Sq}}(T)}}
FALCON (Simchi-Levi & Xu, 2022)Offline regressionO(log⁡T)\order{\log T}, or O(log⁡log⁡T)\order{\log\log T} if TT is knownOptimal for the class, e.g. O~(KTln⁡∣F∣)\tilde{\mathcal O}(\sqrt{KT\ln\abs{\mathcal F}}) for finite classes
Milestones of oracle-efficient contextual bandits. Epoch-greedy, ILOVETOCONBANDITS and FALCON assume i.i.d. contexts, while SquareCB allows adversarial ones; the regression-based methods need realizability.

From epoch-greedy to taming the monster

Epoch-greedy (Langford & Zhang, 2008) alternates a round of uniform exploration, whose importance-weighted data give unbiased value estimates for every policy at once, with an epoch of exploitation that follows the policy the oracle finds best on those data; epochs lengthen as the estimates sharpen. Like explore-then-commit, it cannot beat order T2/3T^{2/3}: uniform exploration costs the same in every round, whether or not any policy that would choose the explored action is still in contention.

The fix is to explore only as much as needed to tell the remaining good policies apart. ILOVETOCONBANDITS (Agarwal, Hsu, Kale, Langford, Li & Schapire, 2014), building on a slower algorithm of Dudík et al. (2011), keeps a sparse distribution QQ over policies, recomputed at a few epoch boundaries, that satisfies two kinds of constraint:

  • Low empirical regret: playing from QQ is cheap, ∑πQ(π) Reg^t(π)\sum_\pi Q(\pi)\,\widehat{\mathrm{Reg}}_t(\pi) being of the order of the statistical noise.
  • Low variance for every policy: for each π∈Π\pi\in\Pi, the quantity Ex[1/Qμ(π(x)∣x)]\E_x\big[1/Q^\mu(\pi(x)\mid x)\big], where QμQ^\mu is QQ's action distribution smoothed with a little uniform exploration, is at most of order KK plus a term that grows with π\pi's empirical regret.

The constraints are met by a coordinate descent in which each step calls the classification oracle. Over TT rounds it needs O~(KT/ln⁡N)\tilde{\mathcal O}(\sqrt{KT/\ln N}) calls, far fewer than TT, and attains regret of order KTln⁡N\sqrt{KT\ln N} up to logarithms, for i.i.d. contexts.

Check your understanding

A distribution over policies plays some policy's actions with probability about 10−410^{-4} in most contexts. What goes wrong if that policy is in fact the best?

  1. Nothing: its importance weights of about 10410^4 make its estimate unbiased
  2. Its estimated value is unbiased but so noisy, with variance of order 10410^4 per sample, that the learner cannot tell that it is the best
  3. Its value is biased downward, because it is rarely played
  4. The oracle cannot return it
Show the answer

B. Its estimated value is unbiased but so noisy, with variance of order 10410^4 per sample, that the learner cannot tell that it is the best

Unbiasedness holds, but the second moment of each IPS term is of order Ex[1/p(π(x)∣x)]≈104\E_x[1/p(\pi(x)\mid x)]\approx10^4, so separating that policy from a slightly worse one takes an enormous number of rounds. The variance constraints exist to prevent exactly this for every policy with small empirical regret.

SquareCB: exploration by inverse-gap weighting

Assume realizability and an online regression oracle: after every round it updates its predictions y^t(x,a)\hat y_t(x,a), and its cumulative square loss exceeds that of the best f∈Ff\in\mathcal F by at most RegSq(T)\mathrm{Reg}_{\mathrm{Sq}}(T). For a finite class, Vovk's aggregating algorithm gives RegSq(T)≤2ln⁡∣F∣\mathrm{Reg}_{\mathrm{Sq}}(T)\le2\ln\abs{\mathcal F}; for linear functions in Rd\R^d it is of order dlog⁡(T/d)d\log(T/d). SquareCB (Foster & Rakhlin, 2020) turns the predictions into an action distribution with a rule from Abe and Long (1999): put the most weight on the action predicted best, and give every other action a probability inversely proportional to its predicted gap.

python
import numpy as np

def inverse_gap_weighting(pred, gamma):
    """pred[a]: the regression oracle's predicted reward of action a in this context."""
    K = len(pred)
    best = int(np.argmax(pred))
    p = 1.0 / (K + gamma * (pred[best] - pred))   # small predicted gap -> large probability
    p[best] = 0.0
    p[best] = 1.0 - p.sum()                        # the predicted best gets the rest, at least 1/K
    return p

# SquareCB, one round: p = inverse_gap_weighting(oracle.predict(x), gamma)
#   a = rng.choice(K, p=p);  r = observe(a);  oracle.update(x, a, r)

The whole algorithm. It touches the function class only through the oracle's predictions and updates, so it inherits the oracle's runtime and memory, and γ\gamma of order KT/RegSq(T)\sqrt{KT/\mathrm{Reg}_{\mathrm{Sq}}(T)} tunes how fast exploration fades.

DerivationThe per-round inequality of inverse-gap weighting
  1. pa=1K+γua(a≠b),pb=1−∑a≠bpa ≥ 1Kp_a=\frac{1}{K+\gamma u_a}\quad(a\ne b),\qquad p_b=1-\sum_{a\ne b}p_a\ \ge\ \frac1K

    Fix a round. Write y^a\hat y_a for the predicted reward of action aa, faf_a for its true mean, b=arg max⁡ay^ab=\argmax_a\hat y_a, and ua=y^b−y^a≥0u_a=\hat y_b-\hat y_a\ge0 for the predicted gaps. Inverse-gap weighting plays

  2. ∑apa (fa⋆−fa) ≤ γ4∑apa (y^a−fa)2+2Kγ\sum_ap_a\,(f_{a^\star}-f_a)\ \le\ \frac\gamma4\sum_ap_a\,(\hat y_a-f_a)^2+\frac{2K}{\gamma}

    Claim (Foster & Rakhlin, 2020, Lemma 3, here in reward form). For every vector of true means f∈[0,1]Kf\in[0,1]^K, with a⋆=arg max⁡afaa^\star=\argmax_af_a, the round's expected regret is paid for by the oracle's squared error on the actions it plays:

  3. K−1γ−ua⋆+1γ pa⋆+1γ\frac{K-1}{\gamma}-u_{a^\star}+\frac{1}{\gamma\,p_{a^\star}}+\frac1\gamma

    Proof. For a≠a⋆a\ne a^\star split fa⋆−fa=(fa⋆−y^a⋆)+(y^a⋆−y^a)+(y^a−fa)f_{a^\star}-f_a=(f_{a^\star}-\hat y_{a^\star})+(\hat y_{a^\star}-\hat y_a)+(\hat y_a-f_a). Each estimation error, set against its share of the squared errors, costs little by x−ηx2≤1/(4η)x-\eta x^2\le1/(4\eta) with η=γ/4\eta=\gamma/4: together the first and third pieces cost at most 1/(γpa⋆)+1/γ1/(\gamma p_{a^\star})+1/\gamma. The middle piece is ∑apaua−ua⋆\sum_ap_au_a-u_{a^\star}, and ∑apaua=∑a≠bua/(K+γua)≤(K−1)/γ\sum_ap_au_a=\sum_{a\ne b}u_a/(K+\gamma u_a)\le(K-1)/\gamma. So the left side minus the squared-error term is at most

  4. If a⋆=ba^\star=b, then ua⋆=0u_{a^\star}=0 and pb≥1/Kp_b\ge1/K, giving (K−1)/γ+K/γ+1/γ=2K/γ(K-1)/\gamma+K/\gamma+1/\gamma=2K/\gamma. If a⋆≠ba^\star\ne b, then 1/pa⋆=K+γua⋆1/p_{a^\star}=K+\gamma u_{a^\star}, so 1/(γpa⋆)=K/γ+ua⋆1/(\gamma p_{a^\star})=K/\gamma+u_{a^\star}, the ua⋆u_{a^\star} cancels, and the bound is again 2K/γ2K/\gamma. ■\blacksquare An action's probability falls exactly as fast as its predicted gap can be blamed on the oracle's error.

  5. RT  =  O(KT⋅RegSq(T))R_T\;=\;\order{\sqrt{KT\cdot\mathrm{Reg}_{\mathrm{Sq}}(T)}}

    Summing over rounds. Under realizability the oracle's excess square loss controls its squared errors on the sampled actions, ∑tEa∼pt[(y^t(xt,a)−f⋆(xt,a))2]≲2 RegSq(T)\sum_t\E_{a\sim p_t}\big[(\hat y_t(x_t,a)-f^\star(x_t,a))^2\big]\lesssim2\,\mathrm{Reg}_{\mathrm{Sq}}(T) plus a deviation term. So RT≲γ2RegSq(T)+2KT/γR_T\lesssim\tfrac\gamma2\mathrm{Reg}_{\mathrm{Sq}}(T)+2KT/\gamma, and γ\gamma of order KT/RegSq(T)\sqrt{KT/\mathrm{Reg}_{\mathrm{Sq}}(T)} balances the two:

Predict before you look

K=4K=4 actions, γ=100\gamma=100, and the oracle predicts rewards 0.50, 0.48, 0.30 and 0.10. With what probability does inverse-gap weighting play the 0.48 action?

Show the answer

0.17

1/(4+100⋅0.02)=1/6≈0.1671/(4+100\cdot0.02)=1/6\approx0.167. The 0.30 action gets 1/(4+20)≈0.0421/(4+20)\approx0.042, the 0.10 action 1/(4+40)≈0.0231/(4+40)\approx0.023, and the predicted best the remaining 0.769. The close runner-up keeps a large share because a gap of 0.02 could easily be the oracle's error; the clearly poor actions are still sampled now and then, in case the oracle is badly wrong about them.

Offline oracles: FALCON. Online regression oracles are rarer than offline ones, which fit a model to a batch. Simchi-Levi and Xu (2022) run inverse-gap weighting in epochs of growing length, refitting the model by least squares once per epoch on the previous epoch's data and raising γ\gamma as the fit improves. For i.i.d. contexts and realizability this attains the optimal regret with only O(log⁡T)\order{\log T} oracle calls over TT rounds, or O(log⁡log⁡T)\order{\log\log T} if TT is known in advance.

Why not optimism or posterior sampling? Foster and Rakhlin point out that for general function classes, generalized UCB and Thompson sampling adapt to gaps but, without strong structural assumptions on F\mathcal F, can suffer regret growing with ∣F∣\abs{\mathcal F} itself rather than its logarithm. Inverse-gap weighting never needs a confidence set over F\mathcal F, only a good regressor. In a large empirical comparison on supervised datasets, an optimistic regression-oracle method (RegCB; Foster et al., 2018) did best overall, and a purely greedy baseline came a surprisingly close second (Bietti, Agarwal & Langford, 2021). SquareCB is among Vowpal Wabbit's exploration options.

A theory of exploration: the decision-estimation coefficient

The per-round inequality has a general form. Let M\mathcal M be a class of models, each assigning to every decision π\pi a distribution of observations M(π)M(\pi) and an expected reward fM(π)f^M(\pi), with optimal decision πM\pi_M, and let Mˉ\bar M be a reference model, such as the current estimate. Foster, Kakade, Qian and Rakhlin (2021) define the decision-estimation coefficient:

decγ(M,Mˉ)  =  inf⁡p∈Δ(Π) sup⁡M∈M Eπ∼p[fM(πM)−fM(π)−γ DH2(M(π),Mˉ(π))]\mathrm{dec}_\gamma(\mathcal M,\bar M)\;=\;\inf_{p\in\Delta(\Pi)}\ \sup_{M\in\mathcal M}\ \E_{\pi\sim p}\Big[f^M(\pi_M)-f^M(\pi)-\gamma\,D_{\mathrm H}^2\big(M(\pi),\bar M(\pi)\big)\Big]
DHD_{\mathrm H} is the Hellinger distance between the observations a decision produces under MM and under Mˉ\bar M. A decision distribution with a small coefficient has, for every plausible model, either low regret or observations that reveal the model to differ from Mˉ\bar M: one round's best trade-off between losing reward and gaining information.

Their Estimation-to-Decisions (E2D) algorithm plays, in each round, the minimizing distribution for the current estimate, and its regret is at most of order T⋅decγ+γ⋅Est(T)T\cdot\mathrm{dec}_\gamma+\gamma\cdot\mathrm{Est}(T), with Est(T)\mathrm{Est}(T) the cumulative error of an online estimator. They also prove lower bounds, governed by a localized version of the coefficient, that apply to every algorithm, so the coefficient characterizes the statistical complexity of interactive decision making from bandits to reinforcement learning, up to the estimation term; in RL it recovers essentially all known hardness results. Inverse-gap weighting is the KK-armed instance: with squared error in place of Hellinger distance, the per-round inequality says that the coefficient with weight γ/4\gamma/4 on the information term is at most 2K/γ2K/\gamma, and E2D becomes SquareCB.

Key takeaways

  • Against a class of NN policies the optimal regret is of order KTln⁡N\sqrt{KT\ln N}, up to a logarithmic factor in KK. EXP4 attains it but enumerates the class, so the goal is oracle efficiency: few calls to a classifier or a regression solver.
  • Uniform exploration, as in epoch-greedy, gives order T2/3T^{2/3}. ILOVETOCONBANDITS reaches T\sqrt T with O~(KT/ln⁡N)\tilde{\mathcal O}(\sqrt{KT/\ln N}) classification calls by keeping importance-weighted variance small exactly for the policies that might still be best.
  • Inverse-gap weighting, pa=1/(K+γ(y^b−y^a))p_a=1/(K+\gamma(\hat y_b-\hat y_a)), satisfies a per-round inequality, regret at most γ4\tfrac\gamma4 times the squared error plus 2K/γ2K/\gamma, so SquareCB's regret is O(KT⋅RegSq(T))\order{\sqrt{KT\cdot\mathrm{Reg}_{\mathrm{Sq}}(T)}}: any online regression method becomes an optimal contextual bandit. FALCON achieves this with O(log⁡T)\order{\log T} offline fits.
  • The decision-estimation coefficient generalizes this trade-off between regret and information and characterizes the statistical complexity of interactive decision making, from bandits to RL, up to an estimation term.

Check yourself

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

Question 1

EXP4's regret is of order KTln⁡N\sqrt{KT\ln N} for a class of NN policies. Why is it not used for, say, all depth-5 decision trees on a hundred features?

  1. Because its regret bound holds only against adversaries
  2. Because ln⁡N\ln N is too large for such classes
  3. Because it keeps and updates a weight for every policy, and the class is astronomically large, so each round costs time proportional to NN
  4. Because it needs the horizon in advance
Show the answer

C. Because it keeps and updates a weight for every policy, and the class is astronomically large, so each round costs time proportional to NN

Statistically, ln⁡N\ln N for such a class is modest, so EXP4's regret would be fine. Computationally, every round updates NN weights. Oracle-efficient algorithms keep the statistics of ln⁡N\ln N while touching the class only through an optimization oracle.

Question 2

What do the variance constraints of ILOVETOCONBANDITS guarantee?

  1. Every policy with small empirical regret has a precise importance-weighted value estimate, because the exploration distribution plays its actions with non-negligible probability
  2. Every policy is played equally often
  3. The regret is zero after the first epoch
  4. The oracle is called in every round
Show the answer

A. Every policy with small empirical regret has a precise importance-weighted value estimate, because the exploration distribution plays its actions with non-negligible probability

The constraint bounds Ex[1/Qμ(π(x)∣x)]\E_x[1/Q^\mu(\pi(x)\mid x)], the quantity controlling each policy's IPS variance, by about KK plus a term proportional to the policy's empirical regret. Good policies get precise estimates; clearly bad ones may stay imprecise, which is what saves exploration.

Question 3

In inverse-gap weighting, how does an action's probability depend on its predicted gap uau_a to the predicted best action?

  1. It is zero unless the gap is zero
  2. It is ε/K\varepsilon/K, whatever the gap
  3. It is proportional to e−γuae^{-\gamma u_a}
  4. It is 1/(K+γua)1/(K+\gamma u_a): actions with small predicted gaps keep substantial probability, actions with large gaps are rarely played, and γ\gamma sets the trade-off
Show the answer

D. It is 1/(K+γua)1/(K+\gamma u_a): actions with small predicted gaps keep substantial probability, actions with large gaps are rarely played, and γ\gamma sets the trade-off

The inverse dependence is what makes the per-round inequality work: an action played with probability pap_a has a gap ua≈1/(γpa)u_a\approx1/(\gamma p_a), which the oracle's squared error on that action, weighted by pap_a, can pay for. Exponential weights would starve near-optimal actions too quickly, and uniform exploration would ignore the predictions.

Question 4

What does a small decision-estimation coefficient decγ(M,Mˉ)\mathrm{dec}_\gamma(\mathcal M,\bar M) mean?

  1. The class M\mathcal M contains few models
  2. Some decision distribution, against every model in the class, has either small regret or observations that distinguish that model from the reference Mˉ\bar M
  3. The reference model Mˉ\bar M is close to the truth
  4. Exploration is unnecessary
Show the answer

B. Some decision distribution, against every model in the class, has either small regret or observations that distinguish that model from the reference Mˉ\bar M

The coefficient is a minimax trade-off: regret under the worst model minus γ\gamma times the information the decision gathers about it. If it is small, every round either earns nearly optimal reward or learns something, which is why it bounds regret together with an estimation term.

Further reading

  • P. Auer, N. Cesa-Bianchi, Y. Freund & R. E. Schapire, "The nonstochastic multiarmed bandit problem," SIAM Journal on Computing 32(1), 48–77 (2002).
  • A. Agarwal, D. Hsu, S. Kale, J. Langford, L. Li & R. E. Schapire, "Taming the monster: A fast and simple algorithm for contextual bandits," International Conference on Machine Learning (2014).
  • D. J. Foster & A. Rakhlin, "Beyond UCB: Optimal and efficient contextual bandits with regression oracles," International Conference on Machine Learning (2020).
  • D. Simchi-Levi & Y. Xu, "Bypassing the monster: A faster and simpler optimal algorithm for contextual bandits under realizability," Mathematics of Operations Research 47(3) (2022).
  • D. J. Foster, S. M. Kakade, J. Qian & A. Rakhlin, "The statistical complexity of interactive decision making," arXiv:2112.13487 (2021).