Online Learning & Regret
Learning from a stream, even against an adversary.
What if there is no distribution at all? In online learning, examples arrive one at a time, possibly chosen by an adversary who knows your algorithm, and every prediction counts. Remarkably, you can still guarantee to do almost as well as the best expert, the best linear predictor or the best slot machine in hindsight. This lesson proves the classic regret bounds and connects them back to learning from i.i.d. data.
What you’ll learn
- Prove the mistake bounds of the halving algorithm () and the perceptron (), and explain why the Littlestone dimension, not the VC dimension, governs online learnability.
- Prove that exponential weights with has regret at most against experts, and explain why randomization is necessary.
- Derive the regret of online gradient descent and the rate under strong convexity, and convert regret into risk for i.i.d. data.
- State and compare the regret bounds of UCB1 and EXP3, and check them against a simulation.
The protocol, mistake bounds and the Littlestone dimension
In online learning the protocol runs for rounds : the learner receives , predicts , sees the true and pays . No distribution is assumed: the sequence may be chosen by an adversary, even adaptively. Performance is measured by the regret against a class , .
Start with the realizable mistake-bound model: binary labels, 0–1 loss, and the promise that some labels every round correctly. Then the regret is just the number of mistakes . The halving algorithm keeps the version space of hypotheses consistent so far and predicts with its majority vote. Every mistake means at least half of voted wrong and is eliminated, and is never eliminated, so , that is , on every sequence.
The gap between the two dimensions can be infinite. Thresholds on have VC dimension 1 and are PAC learnable from about examples, but an online adversary can always offer the midpoint of the interval of thresholds still consistent with the labels and declare the learner wrong: the interval halves, a consistent threshold survives, and the mistakes never stop. Online learnability is strictly harder than PAC learnability. Ben-David, Pál & Shalev-Shwartz (2009) showed that finite Littlestone dimension also characterizes learnability in the agnostic online setting, and Alon, Livni, Malliaris & Moran (2019) and Bun, Livni & Moran (2020) proved that it characterizes PAC learnability under approximate differential privacy too.
Labels and inputs with . Suppose some unit vector separates every example with margin : . The perceptron starts at and, after each mistake (), updates . Each update gains at least along :
But the squared norm grows by at most per update, because the update happens only when :
Cauchy–Schwarz joins the two: . The bound holds for every sequence, does not depend on the dimension or on , and the perceptron never needs to know :
Thresholds on have VC dimension 1. Against an adaptive adversary in the realizable setting, how many mistakes can a deterministic online learner be forced to make in rounds?
- At most 1, since the VC dimension is 1
- At most , by binary search
- All : the adversary keeps offering the midpoint of the consistent interval and answering the opposite label
- At most , since regret is sublinear
Show the answer
C. All : the adversary keeps offering the midpoint of the consistent interval and answering the opposite label
After any finite sequence of answers, the thresholds consistent with them form an interval. The adversary offers its midpoint and reveals the label opposite to the prediction; half the interval stays consistent, so the answers remain realizable while the learner errs every round. Thresholds have infinite Littlestone dimension. Randomizing does not rescue the learner: the adversary reveals the label it is less likely to predict, so the expected number of mistakes is still at least .
Experts and exponential weights
Now drop realizability. experts each predict every round, and the learner wants to do nearly as well as the best of them in hindsight. Weighted majority (Littlestone & Warmuth, 1994) predicts with a weighted vote and halves the weight of each expert that errs; it makes at most mistakes, where is the best expert's count. The factor in front of cannot drop below 2 for any deterministic learner: with two experts who always disagree, the adversary makes the learner wrong every round, while one of the two experts is right at least half the time.
So the learner must randomize, or equivalently play a mixture when the loss is convex. Exponential weights, also called Hedge (Freund & Schapire, 1997), handles losses of expert in round : it puts weight on each expert, where is that expert's total loss so far, follows the distribution , and pays in expectation.
Track , with . Keeping only the best expert's term bounds the final total from below, with :
Each round multiplies by the average of over . Hoeffding's lemma (for a variable in , ) bounds it from above:
Sum over , compare with step 1 and divide by . With the learner's expected loss:
The two terms balance at . Lower bounds in Cesa-Bianchi & Lugosi (2006, chapter 3) show that the constant cannot be improved asymptotically as and grow; if is unknown, restarting with doubled horizons costs a factor .
experts, rounds, losses in , and the tuned learning rate. What is the regret bound ?
Show the answer
152 loss
, at . Per round, the learner is within of the best expert, on every possible sequence of losses. A hundred times more experts would add only to the logarithm.
Online convex optimization and online-to-batch conversion
In online convex optimization the learner picks from a convex set of diameter , then an adversary reveals a convex loss with gradients bounded by , and the learner pays . Online gradient descent (Zinkevich, 2003) steps against the revealed gradient and projects back: .
Fix any comparator and write . Projection onto a convex set never increases distances to points of the set, so
Convexity gives . Rearrange and sum; with nonincreasing the distance terms telescope to at most :
Take and use . A fixed gives when is known.
If every is -strongly convex, the inequality of step 2 gains a term . With the distance terms cancel exactly, leaving a harmonic sum (Hazan, Agarwal & Kale, 2007):
From regret to risk. Suppose the examples are in fact i.i.d. from , and run any online learner with a loss that is convex in . Cesa-Bianchi, Conconi & Gentile (2004) showed that the average of its hypotheses generalizes. The argument takes three lines: depends only on , so ; the expected cumulative loss is at most ; and Jensen's inequality moves the average inside the risk:
Think first In the online-to-batch argument, why is exactly the risk , with no uniform-convergence argument over ?
Because is chosen before is seen, and is a fresh draw independent of : the online protocol makes every example a test point before it becomes a training point. If were allowed to depend on , as an empirical risk minimizer on would, would be an optimistic in-sample loss. Convexity enters only afterwards, in Jensen's step for the averaged hypothesis, and the regret bound in the step between.
Bandits: learning from partial feedback
In a -armed bandit the learner sees only the reward of the arm it pulls. In the stochastic version arm pays i.i.d. rewards in with mean ; with gaps and the number of pulls of arm , the expected regret is .
UCB1 (Auer, Cesa-Bianchi & Fischer, 2002) pulls the arm with the largest optimistic index , its average reward plus a confidence bonus that shrinks as it is pulled times. Its expected regret after pulls satisfies, for every ,
Lai & Robbins (1985) proved that no consistent policy can pull a suboptimal arm fewer than about times asymptotically, so logarithmic regret is the best possible rate; UCB1's constant per arm is larger than the optimal , which refined indices and Thompson sampling attain.
EXP3 (Auer, Cesa-Bianchi, Freund & Schapire, 2002) drops the stochastic assumption. It runs exponential weights on importance-weighted estimates , unbiased for every arm, the same trick as in Active Learning, and mixes in a little uniform exploration. Against any reward sequence its expected regret relative to the best arm is at most , and no algorithm can guarantee less than .
Think first Before running UCB1: what does its theorem promise for these five arms at ? And what does the Lai–Robbins lower bound say?
The gaps are 0.45, 0.2, 0.55 and 0.3, so the bound is , more than the largest regret any policy can incur here, . The guarantee is vacuous at this horizon even though UCB1's actual average is 57.5. The Lai–Robbins constant for these arms is , so roughly ; Thompson sampling's 18.6 sits below it without contradiction, because the lower bound is asymptotic: it governs how regret grows, not its value at a fixed . Worst-case bounds describe rates; simulations show constants.
Key takeaways
- Online learning assumes no distribution and measures regret against the best fixed comparator in hindsight. In the realizable case the halving algorithm makes at most mistakes, the optimum is the Littlestone dimension, and the perceptron makes at most .
- Thresholds on have VC dimension 1 but infinite Littlestone dimension: online learnability is strictly harder than PAC learnability, and finite Littlestone dimension also characterizes agnostic online and private learnability.
- Exponential weights has regret at most , hence at ; against an adaptive adversary with 0–1 loss, randomization is necessary.
- Online gradient descent has regret , or under -strong convexity. On i.i.d. data the averaged hypothesis has excess risk at most .
- UCB1 has regret , matching the Lai–Robbins rate up to constants; EXP3 has against any reward sequence, within of the lower bound.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A data stream is separated by a unit vector with margin , and every input has norm at most . The inputs live in , and the stream is examples long. At most how many mistakes does the perceptron make?
- 10
- 100
- , one per dimension
- It depends on : about
Show the answer
B. 100
, on every such sequence, whatever the dimension or the length of the stream. The margin, not the number of parameters, controls the difficulty, which is also why kernel perceptrons work in infinite-dimensional feature spaces.
With the 0–1 loss and two experts, why can no deterministic online learner guarantee regret against an adaptive adversary?
- Because the experts might both be wrong every round
- Because deterministic learners cannot use weights
- Because the adversary can compute the learner's prediction and reveal the opposite label every round, while one of two experts who always disagree is right at least half the time
- Because the regret of deterministic learners is always exactly
Show the answer
C. Because the adversary can compute the learner's prediction and reveal the opposite label every round, while one of two experts who always disagree is right at least half the time
The learner errs times, the better expert at most times, so the regret is at least . Randomizing (or predicting a probability under a convex loss) hides the learner's choice from the adversary, which is what lets exponential weights reach .
Online gradient descent runs with step sizes on -strongly convex losses with gradients bounded by . How does its regret grow?
- Like
- Like , the same as for merely convex losses
- It stays bounded by a constant independent of
- Linearly in , since the steps shrink too fast
Show the answer
A. Like
Strong convexity adds a term to each round's bound; with it cancels the distance terms, and what is left is , a harmonic sum.
EXP3 sees only the reward of the arm it pulled. Why does it divide that reward by , the probability with which it pulled that arm?
- To keep the weights from overflowing
- To reward exploration of rarely pulled arms with a bonus, as UCB1 does
- To normalize rewards to
- So that every arm's reward estimate is unbiased:
Show the answer
D. So that every arm's reward estimate is unbiased:
An arm pulled with probability is observed only a fraction of the time; dividing by compensates exactly, so exponential weights can run as if it saw every arm's reward. The price is variance of order , which is why EXP3 mixes in uniform exploration, and why its regret has an extra factor compared with full-information experts.
Further reading
- N. Cesa-Bianchi & G. Lugosi, Prediction, Learning, and Games (Cambridge University Press, 2006).
- S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapter 21.
- N. Littlestone, "Learning quickly when irrelevant attributes abound: a new linear-threshold algorithm," Machine Learning 2, 285–318 (1988).
- M. Zinkevich, "Online convex programming and generalized infinitesimal gradient ascent," Proceedings of ICML, 928–936 (2003).
- P. Auer, N. Cesa-Bianchi & P. Fischer, "Finite-time analysis of the multiarmed bandit problem," Machine Learning 47, 235–256 (2002).