Online convex learning and regret
Compare a sequence of decisions with the best fixed hindsight decision without assuming iid losses.
On this page
The question for today
What you’ll understand
- Define the timing, comparator and gradient feedback in online convex optimization.
- Derive the projected-gradient regret bound from a telescoping distance inequality.
- Explain when an online-to-batch conversion needs independent sampling and convex prediction losses.
Online learning evaluates decisions made before each loss is revealed. Its basic guarantee compares cumulative loss with one fixed decision chosen in hindsight, even when the loss sequence is not sampled independently from a population. This is a different benchmark from test risk or dynamic tracking. Projected gradient descent offers a short derivation that makes the role of convexity, gradient bounds and decision-set diameter explicit.
The order of play is part of the model
Let K be a nonempty closed convex subset of a finite-dimensional Euclidean space. On round t the learner chooses w_t in K before receiving the current loss function or its subgradient feedback. The revealed loss is convex on K, and the learner incurs its value at w_t. Static regret is cumulative incurred loss minus the smallest cumulative loss of a single fixed comparator in K. The comparator sees the whole realized sequence when selected in hindsight, but it must use one decision for every round.
Regret does not compare to a different optimal point on every round; that stronger dynamic comparator needs additional restrictions on how the environment changes. Nor does a small average regret assert that each individual round has small loss. A pathwise convex-gradient proof can handle adversarially chosen losses, provided the learner’s update uses only available feedback and the stated gradient bounds hold along the actual sequence. An independent-data generalization conclusion is a later, separate step.
Projection makes a squared-distance potential telescope
Fix a comparator u. Nonexpansiveness of Euclidean projection shows that the next squared distance to u is at most the squared distance before projection. Expand that square and rearrange to bound the gradient inner product by a distance decrease divided by twice eta plus eta times squared gradient norm divided by two. Convexity bounds the current loss difference by that same gradient inner product. Summing over t makes the distance decreases telescope, leaving only the initial distance and the sum of gradient squares.
If K has diameter at most D and each chosen subgradient has norm at most G, the resulting regret is at most D squared over twice eta plus eta G squared T over two. For positive D and G and a known horizon T, choose eta=D/(Gsqrt(T)) to obtain DGsqrt(T). Degenerate zero-diameter or zero-gradient cases are handled directly rather than by dividing by zero. Unknown horizons need an adaptive schedule or a doubling argument; the fixed-horizon choice is not available before T is specified.
Population risk needs a new sampling argument
Suppose the online losses are generated from iid examples and w_t depends only on earlier observations. Then the current example is independent of w_t, so expected incurred loss equals expected population risk at w_t. If population loss is convex in the decision, averaging the iterates stays in K and Jensen bounds its risk by the average iterate risks. An expected regret bound relative to a fixed population comparator can therefore yield expected excess risk of the averaged decision at most regret divided by T.
This conversion is an expectation statement and needs its own measurability and integrability assumptions. A high-probability online-to-batch guarantee requires an additional concentration argument; an adversarial pathwise regret statement alone is not an iid test-risk theorem. Finally, averaging parameters need not preserve predictions in a nonconvex model or a nonconvex constraint set. The simple interval example below verifies the online arithmetic directly, while keeping these population conclusions conditional on their additional assumptions.
Work it through
Four linear losses on a constrained interval
Use K=[−1,1], w₁=0 and eta=1/2. The successive linear-loss gradients are 1,−1,1,−1. Compute decisions, total incurred loss, best fixed-comparator loss and regret.
After gradient 1, project 0−0.5 to−0.5, so w₂=−0.5. Gradient−1 then returns w₃ to 0. The next gradient 1 gives w₄=−0.5, and the fourth update returns to 0.
The incurred linear losses g_tw_t are 0,0.5,0,0.5, totaling one. The sum of gradients is zero, so every fixed u in[−1,1] has total linear loss zero.
Static regret is therefore one. With diameter D=2, G=1 and T=4, the displayed bound at eta=1/2 is 4/(1)+0.5·4/2=5, so the actual regret lies well below this conservative certificate.
The decisions are 0,−0.5,0,−0.5; total loss and static regret are both one. A valid worst-case bound need not be attained.
The living notebook
Explore the model
Interactive lab · optimization
A constant loss sequence is an online special case
Pause and Reset, then set step size eta = 0.50 and initial position x₀ = 1. One Step gives x₁=0.5 and objective 0.125; a second gives x₂=0.25 and objective 0.03125. Reset and set both eta = 1 and x₀ = 1: one Step reaches zero. These are updates for the same quadratic loss every round, without projection or varying gradients. The instrument cannot replay the four adversarial linear losses in the worked example or evaluate their regret.
- Position x0
- 2
- Objective x²/2
- 2
- Iteration behavior
- Stable step
Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forOrdinary descent is one repeated-loss sequence; online regret controls a broader timing and comparator problem.
Pause & reason
Check your understanding
Your turn
Try it yourself
With D=3,G=2 and a known horizon T=400, choose the displayed optimal fixed step and compute the regret and average-regret certificates. Explain what extra conditions would turn the latter into expected excess population risk.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use sqrt(T)=20, then distinguish a pathwise cumulative comparison from a statistical expectation.
Compare with the solution
The step is . Regret is at most , giving average regret at most 120/400=0.30. For an expected population excess conclusion, use iid examples, a decision w_t based only on the past, measurable integrable losses convex in the decision, and an averaged decision in the convex feasible set. Independence identifies expected online losses with expected population risks, while Jensen handles averaging. The regret certificate alone does not provide a 0.30 high-probability generalization statement or control a comparator that changes every round.
Keep the idea
Take it with you
- Online decisions must precede current loss feedback.
- Projected-gradient regret follows from convexity and a telescoping distance potential.
- Online-to-batch population guarantees add iid sampling, convexity and a separate expectation or concentration argument.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.