Online Learning and Regret
Data arrives one round at a time and you must act before seeing the outcome. Regret scores you against the best single decision you could have made with hindsight.
Why Does This Exist?
Batch learning assumes the dataset sits still while you study it. Spam filters, ad auctions and stock routers never get that luxury: each email, bid or tick arrives once, demands a decision now, and reveals the right answer only after. Retraining from scratch every round is hopeless, and assuming tomorrow looks like yesterday invites an adversary to punish exactly that.
Regret is the scoreboard built for this world. It compares your running total against the best single action chosen with full hindsight, and asks for procedures whose average gap shrinks to zero no matter how nasty the sequence. This page defines regret and proves the classic shrinking bound. The batch counterpart is maximum likelihood estimation; the optimizer this theory justifies is in stochastic gradient descent variants.
The one idea you need first
A loss scores action on round , revealed after you commit. Losses may be adversarial: chosen to hurt your rule, not drawn from any distribution. No statistical assumption saves you; only the algorithm's guarantee does.
Think of It Like This
Picking a checkout line every morning
You shop daily and must join a line before knowing which moves fastest. After a month, the fastest single line averaged 3 minutes while your picks averaged 4. Your regret is 1 minute per trip times 30 trips.
A no-regret rule does not promise to beat the best line each day. It promises the per-trip gap shrinks toward zero as months pass, against any pattern of cashier speeds, even one designed to embarrass you. Copying yesterday's fastest line almost does this, with one famous wobble you will meet below.
Where it stops: real queues let you switch lines mid-wait, but the basic model locks your choice each round.
How It Actually Works
On each round you pick an action (or a distribution over actions), then suffer loss . Against fixed actions, your regret is:
In plain words: your total minus the total of the best single action in hindsight. Note the benchmark never switches; beating a shifting target is much harder and needs Bandit-style extras. No regret means : per-round you converge to the best fixed choice.
The workhorse is multiplicative weights. Keep a weight per action, play proportionally to weights, then multiply each weight by with step . Good actions keep weight, bad ones decay exponentially. With it guarantees : total regret grows like , so average regret falls like .
Worked example
Two news layouts A and B over rounds. Miss-rate losses: A suffers totalling ; B suffers totalling . A stubborn learner always picks A and totals : regret .
Now an adversary notices and flips the pattern against a copycat learner that always repeats last round's winner. Copycat picks B, A, B, A and suffers . Best fixed is still . Regret: , average per round. Multiplicative weights with instead splits weight toward both, totals about here, regret : already far below , and the bound promises at most .
Code
Multiplicative weights on the copycat-trap sequence, showing regret well under the bound.
import numpy as np
def hedge(losses: np.ndarray, eta: float) -> tuple[float, float]: w = np.ones(losses.shape[1]) # one weight per action total = 0.0 for row in losses: # each round: play weights, then penalize p = w / w.sum() total += float(p @ row) w *= 1.0 - eta * row best = float(losses.sum(axis=0).min()) return total, total - best
losses = np.array([[0.0, 1.0], [1.0, 0.0], [0.0, 1.0], [1.0, 0.0]])print(hedge(losses, 0.5)) # -> (2.72, 0.72) approx, bound 1.66Total about against best fixed : regret , inside the bound the theory promised.
Watch Out For
Follow-the-leader whiplashes on alternating losses
Symptom: copying last round's winner scores worst-possible on sequences like the one above, regret growing linearly. Fix: randomize or weight smoothly (hedge, online gradient descent) instead of snapping to the current leader.
Tuning the step for a horizon you do not have
Symptom: the step needs up front, and guessing wrong voids the bound. Fix: use the doubling trick (restart with doubled horizon guesses) or a time-varying .
The Quick Version
- Online learning decides before seeing the loss; regret measures the gap to the best fixed action in hindsight.
- No regret means average regret tends to zero against any sequence, including adversarial ones.
- Multiplicative weights guarantees regret at most over actions and rounds.
- Copying the recent winner can suffer linear regret on alternating sequences.
- The benchmark is the best single action, not the best switching strategy.