Skip to content
AI360Xpert
Beta

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.

The learner running total climbs to 6 while the best fixed action reaches only 3, and the gap of 3 is the regret
The learner running total climbs to 6 while the best fixed action reaches only 3, and the gap of 3 is the regret

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 ℓt(a)\ell_t(a) scores action aa on round tt, 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 t=1,…,Tt = 1, \ldots, T you pick an action (or a distribution over actions), then suffer loss ℓt\ell_t. Against KK fixed actions, your regret is:

RT=∑t=1Tℓt(at)−min⁡a∑t=1Tℓt(a)R_T = \sum_{t=1}^{T} \ell_t(a_t) - \min_{a} \sum_{t=1}^{T} \ell_t(a)

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 RT/T→0R_T / T \to 0: 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 (1−ηℓt(a))(1 - \eta \ell_t(a)) with step η\eta. Good actions keep weight, bad ones decay exponentially. With η=log⁡K/T\eta = \sqrt{\log K / T} it guarantees RT≤Tlog⁡KR_T \le \sqrt{T \log K}: total regret grows like T\sqrt{T}, so average regret falls like 1/T1/\sqrt{T}.

Worked example

Two news layouts A and B over T=4T = 4 rounds. Miss-rate losses: A suffers [0,1,0,1][0, 1, 0, 1] totalling 22; B suffers [1,0,1,0][1, 0, 1, 0] totalling 22. A stubborn learner always picks A and totals 22: regret 2−2=02 - 2 = 0.

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 [1,1,1,1]=4[1, 1, 1, 1] = 4. Best fixed is still 22. Regret: 4−2=24 - 2 = 2, average 0.50.5 per round. Multiplicative weights with η=0.5\eta = 0.5 instead splits weight toward both, totals about 2.72.7 here, regret 0.70.7: already far below 22, and the Tlog⁡2\sqrt{T \log 2} bound promises at most 4×0.69≈1.66\sqrt{4 \times 0.69} \approx 1.66.

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.66

Total about 2.72.7 against best fixed 22: regret 0.70.7, inside the 1.661.66 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 log⁡K/T\sqrt{\log K / T} step needs TT up front, and guessing wrong voids the bound. Fix: use the doubling trick (restart with doubled horizon guesses) or a time-varying ηt∝1/t\eta_t \propto 1/\sqrt{t}.

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 Tlog⁡K\sqrt{T \log K} over KK actions and TT rounds.
  • Copying the recent winner can suffer linear regret on alternating sequences.
  • The benchmark is the best single action, not the best switching strategy.