Foundations to Frontier
Tests
B. Statistical Learning Theory › B5 Online learning and bandits

Online Learning and Regret

In online learning there is no fixed dataset: data arrive one at a time, possibly chosen by an adversary, and the learner must predict before seeing each answer. Performance is measured by regret, the gap to the best fixed strategy in hindsight. This topic covers prediction with expert advice (why Follow-the-Leader fails and Hedge achieves √(T ln N) regret), online convex optimization with online gradient descent (√T regret, and log T for strongly convex losses), lower bounds, and online-to-batch conversion. In the exercises you break Follow-the-Leader, verify Hedge's bound, and measure √T vs log T regret growth.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Learning while the game is played

Every morning you must guess whether it will rain, and you have three weather apps whose advice you can follow. Each evening you learn who was right. You don’t know in advance which app is best, and the weather owes you nothing. How should you combine their advice? Online learning studies exactly this: decisions made one at a time, with feedback after each one. The goal isn’t to be perfect. It’s to do almost as well as the best app in hindsight. The gap is called regret, and good algorithms keep it growing much slower than the number of days.

Learning from experts: Follow-the-Leader vs Hedge
losses:
regret: orange FTL, blue Hedge, dashed √(t ln N / 2)round t → 400Hedge's weights on experts 1, 2, 3
final regret: FTL 200.0 · Hedge 10.4 · bound √(T ln N / 2) = 14.8 (η* = 0.148)
Regret compares you with the best single expert in hindsight; sublinear regret means your average loss approaches the best expert's. FTL is greedy and gets whipsawed when the leader flips every round. Hedge's randomized, smoothed weights guarantee regret at most √(T ln N / 2) for every loss sequence, even an adversarial one. Too small an η reacts too slowly (try "switching"); too large an η behaves like FTL.
Why engineers care

Online learning powers adaptive systems that can’t wait for a dataset: combining several fault detectors on a spacecraft, choosing among motion planners as terrain changes, adapting a controller’s gains in flight, and routing in communication networks. Regret guarantees hold even when conditions shift unpredictably.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Regret compares your total loss with…
  2. 2. A good online learner's regret grows…
  3. 3. Online learning can handle data chosen by…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

The protocol

For t = 1, …, T: the learner picks a decision wtw_t (or a distribution ptp_t over N experts), the environment reveals a loss ℓt\ell_t, and the learner suffers ℓt(wt)\ell_t(w_t). Regret against a comparator class:

RegT=∑t=1Tℓt(wt)−min⁡w∑t=1Tℓt(w).\mathrm{Reg}_T = \sum_{t=1}^T\ell_t(w_t) - \min_{w}\sum_{t=1}^T\ell_t(w).

Sublinear regret, RegT=o(T)\mathrm{Reg}_T = o(T), means the average loss approaches that of the best fixed choice.

Experts: FTL and Hedge

  • Follow-the-Leader (FTL): pick the expert with the smallest cumulative loss. It can be forced to regret about T/2: with losses alternating (0, 1), (1, 0), …, the leader flips every round and FTL always picks the loser.
  • Hedge (multiplicative weights): pt,i∝exp⁡(−ηLt−1,i)p_{t,i}\propto\exp(-\eta L_{t-1,i}), with LL the cumulative losses. With η=8ln⁡N/T\eta = \sqrt{8\ln N/T} and losses in [0, 1],
RegT≤T2ln⁡N.\mathrm{Reg}_T\le\sqrt{\tfrac T2\ln N}.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Hedge's bound for T = 200, N = e⁴:
  2. 2. FTL's regret on the alternating sequence after T rounds:
  3. 3. Hedge weights for cumulative losses (0, 1) with η = ln 3:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Online convex optimization (OCO)

Decisions wtw_t live in a convex set K of diameter D, and losses ℓt\ell_t are convex with ∥∇ℓt∥≤G\|\nabla\ell_t\|\le G. Online gradient descent (Zinkevich, 2003):

wt+1=ΠK(wt−ηt∇ℓt(wt)),ηt=DGt ⇒ RegT≤32DGT.w_{t+1} = \Pi_K\big(w_t - \eta_t\nabla\ell_t(w_t)\big),\qquad\eta_t = \frac D{G\sqrt t}\ \Rightarrow\ \mathrm{Reg}_T\le\tfrac32DG\sqrt T.

If every ℓt\ell_t is μ-strongly convex, the step ηt=1/(μt)\eta_t = 1/(\mu t) gives RegT≤G22μ(1+ln⁡T)\mathrm{Reg}_T\le\frac{G^2}{2\mu}(1 + \ln T) (Hazan, Agarwal and Kale, 2007).

Lower bounds

For linear losses on a ball, any algorithm suffers Ω(DGT)\Omega(DG\sqrt T) against random ±1 gradients. For experts, regret is Ω(Tln⁡N)\Omega(\sqrt{T\ln N}). So OGD and Hedge are minimax-optimal up to constants.

Online-to-batch

If data are i.i.d., the average iterate wˉ=1T∑wt\bar w = \frac1T\sum w_t has excess risk at most RegT/T\mathrm{Reg}_T/T in expectation. Regret bounds give generalization bounds, and SGD analysis is often done this way.

🐍 Exercise 1: break Follow-the-Leader, verify Hedge
Implement Hedge and Follow-the-Leader for N experts. On the alternating loss sequence show that FTL's regret is T/2 while Hedge stays within √(T ln N / 2); on stochastic losses compare both with the bound.
📝 Quick check (Level 2)
0/3 answered
  1. 1. OGD's regret with η_t = D/(G√t) is…
  2. 2. For μ-strongly convex losses with η_t = 1/(μt), regret is…
  3. 3. Online-to-batch: the average iterate's excess risk is at most…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proof of the Hedge bound (sketch)

Let Wt=∑ie−ηLt,iW_t = \sum_ie^{-\eta L_{t,i}}. Then ln⁡WtWt−1=ln⁡Ei∼pte−ηℓt,i≤−η pt⋅ℓt+η28\ln\frac{W_{t}}{W_{t-1}} = \ln\mathbb E_{i\sim p_t}e^{-\eta\ell_{t,i}}\le-\eta\,p_t\cdot\ell_t + \frac{\eta^2}8 by Hoeffding’s lemma. Summing gives ln⁡WT−ln⁡N≤−η∑tpt⋅ℓt+η2T/8\ln W_T - \ln N\le-\eta\sum_tp_t\cdot\ell_t + \eta^2T/8, while ln⁡WT≥−ηmin⁡iLT,i\ln W_T\ge-\eta\min_iL_{T,i}. Rearranging, RegT≤ln⁡Nη+ηT8\mathrm{Reg}_T\le\frac{\ln N}\eta + \frac{\eta T}8, minimized at η=8ln⁡N/T\eta = \sqrt{8\ln N/T}. ∎

Proof of the OGD bound (sketch)

By convexity, ℓt(wt)−ℓt(u)≤gt⋅(wt−u)\ell_t(w_t) - \ell_t(u)\le g_t\cdot(w_t - u). Expanding ∥wt+1−u∥2≤∥wt−ηtgt−u∥2\|w_{t+1} - u\|^2\le\|w_t - \eta_tg_t - u\|^2 (projection is non-expansive) gives gt⋅(wt−u)≤∥wt−u∥2−∥wt+1−u∥22ηt+ηtG22g_t\cdot(w_t - u)\le\frac{\|w_t - u\|^2 - \|w_{t+1} - u\|^2}{2\eta_t} + \frac{\eta_tG^2}2. Telescoping with ∥wt−u∥≤D\|w_t - u\|\le D and ∑ηt≤2DT/G\sum\eta_t\le2D\sqrt T/G gives 32DGT\tfrac32DG\sqrt T. With strong convexity the extra −μ2∥wt−u∥2-\tfrac\mu2\|w_t - u\|^2 term cancels the telescoping residue for ηt=1/(μt)\eta_t = 1/(\mu t). ∎

Unifying view: FTRL and mirror descent

Follow-the-regularized-leader chooses wt+1=arg⁡min⁡w∑s≤tℓs(w)+R(w)/ηw_{t+1} = \arg\min_w\sum_{s\le t}\ell_s(w) + R(w)/\eta. With an entropy regularizer on the simplex it is Hedge; with 12∥w∥2\tfrac12\|w\|^2 it is (lazy) OGD. The regularizer is what stops FTL from being whipsawed.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The key inequality in the Hedge proof is…
  2. 2. FTRL with an entropy regularizer on the simplex is…
  3. 3. Hedge's regret before tuning η is at most…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Regret, measured

Exercise 1. On the alternating sequence, FTL’s regret is exactly T/2: 50, 500 and 5000 for T = 100, 1000 and 10 000. Hedge’s is 3.2, 9.5 and 29.7, about half its bound (5.9, 18.6, 58.9) and growing like √T. On stochastic losses (T = 2000) Hedge’s regret is 14.5, 32.6 and 54.9 for N = 2, 10 and 100, all under the bound. Here FTL does as well or better (0, 22, 46): FTL is fine when the world is benign, and Hedge is insurance against when it isn’t.

Exercise 2: growth rates. Mean regret at T = 100, 400, 1600 and 6400:

setting regret growth exponent
OGD on linear losses 8.2, 16.0, 26.6, 64.2 0.48 (√T)
quadratic losses, η = 1/√t 6.4, 10.9, 23.2, 41.3 0.46 (√T)
quadratic losses, η = 1/t 3.3, 3.9, 4.3, 5.4 0.12 (log T)

The log-regret prediction ½·d·Var(z)·(1 + ln T) = 2.8, 3.5, 4.2, 4.9 is close. With strong convexity, matching the step size to the curvature turns √T into log T.

🐍 Exercise 2 (research): √T vs log T
Run online gradient descent on linear losses over a ball, and on strongly convex quadratic losses with steps 1/√t and 1/t. Measure regret against the best fixed point for growing T and fit the growth exponents.

Online learning in AI, robotics and aerospace

  • Sensor and detector fusion: weight several fault detectors or estimators by their recent performance with exponential weights.
  • Adaptive control and planning: online convex optimization for adapting gains or choosing among planners as conditions drift.
  • Boosting and game solving: AdaBoost and many equilibrium solvers are multiplicative-weights algorithms.
  • Online-to-batch analyses of SGD underpin many training guarantees.

References

  1. N. Cesa-Bianchi, G. Lugosi (2006). Prediction, Learning, and Games. Cambridge University Press.
  2. Y. Freund, R. E. Schapire (1997). “A decision-theoretic generalization of on-line learning and an application to boosting.” Journal of Computer and System Sciences, 55.
  3. M. Zinkevich (2003). “Online convex programming and generalized infinitesimal gradient ascent.” ICML.
  4. E. Hazan, A. Agarwal, S. Kale (2007). “Logarithmic regret algorithms for online convex optimization.” Machine Learning, 69.
  5. E. Hazan (2016). “Introduction to online convex optimization.” Foundations and Trends in Optimization, 2(3–4).
  6. S. Shalev-Shwartz (2012). “Online learning and online convex optimization.” Foundations and Trends in Machine Learning, 4(2).