Online Learning Theory and the Idea of Regret
Understand regret, why following the leader can fail, and how weighted experts and online gradient descent come with guarantees.
Key takeaways
- Online learning proceeds in rounds: choose, observe the loss, update.
- Regret compares your cumulative loss with that of the best fixed option in a chosen comparison set.
- "No-regret" means regret divided by the number of rounds tends to zero, not that you never lose.
- Always following the current leader can fail badly; randomizing or regularizing the choice fixes this.
- Weighted-experts methods and online gradient descent achieve regret that grows about like the square root of time.
Online learning theory studies a learner that makes a decision, sees the outcome, pays a loss and updates, over and over. Its main yardstick is regret: your total loss minus the total loss of the best single choice you could have made in hindsight. A good algorithm has regret that grows more slowly than the number of rounds, so your average shortfall per round fades toward zero.
Remarkably, such guarantees can hold even when the data are not random at all and may be chosen to make you look bad.
The protocol and the yardstick
In each round t = 1, 2, ..., T:
- You choose an action or a parameter vector wₜ.
- The loss function ℓₜ for the round is revealed.
- You pay ℓₜ(wₜ) and update.
Regret over T rounds is:
Regret(T) = ∑ ℓₜ(wₜ) − min over w in W of ∑ ℓₜ(w)
your loss best fixed choice in hindsight The comparison is deliberately modest. The benchmark must use one choice for all rounds, although it gets to pick it after seeing everything. Competing with the best choice separately in every round would be hopeless against an unpredictable sequence.
Think of predicting each day whether a server will exceed a load limit, with ten forecasting rules available. You cannot know which rule will turn out best. Regret asks how much worse you did than if you had known and used it from the start.
A warm-up: halving
Suppose you have N experts, each predicting yes or no, and you are promised that one of them is never wrong. Follow the majority of the experts who have not yet erred. When the majority is wrong, at least half of the remaining experts are eliminated.
So the number of mistakes is at most log₂ N. With 1,024 experts, you err at most 10 times, however long the game runs. The bound does not depend on any probability model. It depends on the promise of a perfect expert, which real problems rarely offer.
Why following the leader can fail
Without a perfect expert, a tempting rule is follow the leader: use whichever expert has the smallest total loss so far. Consider two experts, A and B. In round 1, A loses 0.5 and B loses 0. After that the losses alternate: B loses 1, then A loses 1, and so on.
round losses (A, B) leader before round your loss
2 (0, 1) B 1
3 (1, 0) A 1
4 (0, 1) B 1 The leader flips just in time to be wrong. Your loss grows by 1 per round, while each expert accumulates only about half that. Regret grows linearly with T, which is failure.
The problem is instability: a tiny change in totals swings your choice completely. The cure is to change more smoothly.
Weighting the experts
The Hedge algorithm, a form of multiplicative weights closely related to the weighted majority algorithm, keeps a weight for each of N experts. It splits trust in proportion to the weights, or picks one expert at random with those probabilities.
start: weightᵢ = 1 for every expert
each t: pᵢ = weightᵢ / ∑ weights
observe losses ℓᵢ in [0, 1]
your expected loss = ∑ pᵢ ℓᵢ
weightᵢ ← weightᵢ · exp(−η ℓᵢ) Here η > 0 is the learning rate. With T known in advance and η = √(8·ln N / T), the expected regret is at most √(T·ln N / 2).
For N = 10 and T = 1,000, that is √(1000 × 2.303/2) ≈ 33.9, or about 0.034 per round. Multiply the number of experts by 100 and ln N only rises from 2.3 to 6.9. Because of that logarithm, you can afford a very large pool.
import numpy as np
rng = np.random.default_rng(0)
T, N = 1000, 10
losses = rng.uniform(size=(T, N)) # rows are rounds, columns experts
losses[:, 3] *= 0.8 # expert 3 is somewhat better
eta = np.sqrt(8 * np.log(N) / T)
total = np.zeros(N) # cumulative loss per expert
mine = 0.0
for t in range(T):
w = np.exp(-eta * (total - total.min()))
p = w / w.sum()
mine += p @ losses[t]
total += losses[t]
print(mine - total.min(), np.sqrt(T * np.log(N) / 2)) The first number is the realized regret and should not exceed the second. Subtracting the minimum before exponentiating prevents numerical underflow without changing p.
Online gradient descent
Now let the choice be a vector w in a convex, closed and bounded set W, with convex losses. Online gradient descent steps against the gradient of the loss just seen, then projects back into W if needed:
wₜ₊₁ = project( wₜ − η · gₜ ), gₜ = gradient (or subgradient) of ℓₜ at wₜ Let D bound the distance between any two points of W, and G bound the length of every gradient. With the fixed step η = D/(G·√T):
Regret(T) ≤ D²/(2η) + η·G²·T/2 = D·G·√T The two terms show the tension. A small step makes it slow to travel to the good region (first term). A large step makes you jittery (second term). The chosen η balances them. If T is unknown, a step that shrinks like 1/√t gives a bound of the same order. When losses are strongly convex, meaning curved at least as much as a fixed quadratic, suitable steps give regret that grows only like ln T.
The update is the familiar one from stochastic gradient descent. The analysis differs: it never assumes the examples are random.
An older example: the perceptron
The perceptron, a simple linear classifier, is an online algorithm. It predicts the sign of w·x, and only when it errs does it update w by adding y·x, where the label y is +1 or −1.
Its classic guarantee counts mistakes. Suppose every input has length at most R, and some linear separator through the origin, with a unit-length weight vector, classifies every example with margin at least γ, meaning y·(w·x) ≥ γ. Then the perceptron makes at most (R/γ)² mistakes, in any order of presentation and for sequences of any length.
With R = 1 and γ = 0.1, that is at most 100 mistakes. The number of features does not appear. If no separator with a positive margin exists, this bound no longer applies, and the weights can keep changing indefinitely on repeated data. The perceptron convergence guarantee walks through the proof.
From regret to ordinary learning
If the losses come from independent examples drawn from one distribution, a no-regret algorithm also gives a good ordinary model. For convex losses, take the average of w₁ through w_T. Its expected excess risk over the best fixed w is at most the expected regret divided by T.
The reason is short. By convexity, the loss of the averaged weights is at most the average of the losses of the individual weights. And each wₜ was chosen before example t arrived, so its loss on that example is an honest sample of its performance on new data.
This online-to-batch conversion gives a rate of order 1/√T for online gradient descent in one pass over T examples. It links this theory with risk minimization and sample complexity.
When you only see part of the outcome
| Setting | What you observe | Typical worst-case regret growth |
|---|---|---|
| Full information (experts) | Every expert's loss | About √(T ln N) |
| Bandit feedback | Only your chosen action's loss | About √(T·N), up to log factors |
With bandit feedback, you must spend some rounds exploring actions to learn their losses. The price is that the number of actions enters roughly through its square root instead of its logarithm. See multi-armed bandits.
Limits of the guarantee
Low regret means you keep up with the best fixed choice. If every fixed choice is poor, you may be poor too. In a drifting environment, the best fixed option over a year may be mediocre in every month. Variants measure dynamic or adaptive regret against changing benchmarks, and their guarantees depend on how much change occurs.
The standard bounds also assume bounded losses, prompt feedback and, in the adversarial case, an opponent who cannot see your private random draws before setting the losses. If your actions alter future situations, as in recommendation or control, simple regret against a fixed action may be the wrong question.
In practice, systems that update as data arrive also need monitoring, protection against bad or malicious inputs, and a way to roll back.
Common questions
Is zero regret possible?
Occasionally you may even achieve negative regret, by beating every fixed choice through well-timed switching. No algorithm can guarantee it against all sequences.
Is online learning the same as training on a stream?
Training on a stream is an engineering arrangement. Online learning theory is a way to analyze sequential decisions, and it applies whether or not a production system updates continuously.
Where else do these ideas show up?
Multiplicative weight updates are closely tied to boosting: AdaBoost reweights training examples in a related exponential way, and its original authors, Yoav Freund and Robert Schapire, presented the two together. Similar updates appear in game theory, where two players who both run no-regret algorithms in a repeated zero-sum game have average strategies that approach an equilibrium.
What if I do not know T?
A common device is the doubling trick: run the algorithm for blocks of length 1, 2, 4, 8 and so on, restarting with a rate tuned to each block. Time-varying step sizes avoid the restarts.