Optimization for Data Science · Lecture 13
What changes when the gradient disappears?
From absolute residuals and sparse coefficients to supporting lines, unexpected uphill steps, and convergence through averaging.
1 Absolute residuals and outliers
Fit the same 25 observations with squared loss and absolute loss. Move two responses far from the main trend and watch which fitted line moves.
Least absolute deviations (LAD): mina,b (1/n) Σᵢ |axᵢ + b − yᵢ|.
Two different fitting objectives
Both lines are optimized fully for the current dataset.
Where does the residual live?
Absolute residual for each observation. Exact fits appear at zero.
| Fit | Slope | Intercept | Mean |residual| | Mean residual² | Exact fits |
|---|
How these fits are computed
Least squares uses its two-parameter normal equations. For LAD, the demo examines lines through every pair of observations and chooses one with minimum absolute loss. A minimum of this full-rank, piecewise-linear two-parameter problem occurs at such a vertex. The bars show the fully optimized fits, not a finite subgradient run. “Exact fits” uses residual magnitude below 10⁻⁸.
2 An ℓ₁ penalty selects sparse coefficients
One equation, two unknowns. Least squares has a line of solutions; adding an ℓ₁ penalty selects a point on a coordinate axis.
This is a geometric example with n = 1 and d = 2. The quadratic term makes this objective non-Lipschitz globally; the theorem in experiment 5 is applied to a different function.
A diamond meets a loss contour
The dashed line is the set of exact fits. The diamond has radius ‖wλ‖₁.
Selected coefficients
Compare the sparse solution with the minimum-norm least-squares solution.
Exact solution and the role of the kink
For λ > 0 the unique minimizer is wλ = (0, max{0, 1 − λ/4}). Coordinate w₂ changes the prediction twice as much per unit of ℓ₁ cost as w₁, so the solution uses w₂ alone. For λ ≥ 4 both coefficients vanish. At λ = 0 the minimizer is not unique; the green point shows the sparse limiting choice (0, 1), and the blue diamond is (0.4, 0.8).
The diamond is the ℓ₁ ball through the penalized solution. It also illustrates the equivalent constrained fit at this radius. This is an example of sparsity, not a promise of exact support recovery for every dataset.
3 A whole set of supporting slopes
A subgradient defines a line that touches the graph and stays below it everywhere. Try slopes inside and outside the interval at a kink.
Absolute value
Blue: function. Green/red: proposed supporting line.
The subdifferential at w
The thick interval contains all valid slopes. The dot is your candidate.
Max rule and optimality
Absolute value is max{−w, w}; the hinge is max{0, 1 − w}. For a maximum of affine functions, the subdifferential is the convex hull of the slopes of the active pieces. The third example is max{−w − 0.5, 0.4w + 0.3, 1.5w − 0.8}. At a smooth point only one slope is valid.
Optimality requires 0 ∈ ∂f(w), not that every possible subgradient be zero. The validity indicator uses the exact active slopes, rather than checking just the visible plot window.
4 Uphill in value, closer in distance
The lecture example: choose a valid subgradient at (1, 0). A small step can increase the objective even as it moves closer to the minimizer.
g = (1, b), w⁺ = w − ηg = (1 − η, −ηb), w⋆ = (0, 0).
The step in parameter space
Diamonds are objective contours; the dashed circle marks distance 1.
Two measures of progress
Varying the step along the same selected direction. The dot is the chosen η.
What survives without descent
For 0 ≤ η ≤ 1, f(w − ηg) = 1 + η(2|b| − 1), while ‖w − ηg‖² = 1 − 2η + η²(1 + b²). For b = 2 the value rises at every positive step, but distance decreases when 0 < η < 2/5.
The subgradient inequality gives ⟨g, w − w⋆⟩ ≥ f(w) − f⋆. This angle condition underlies the distance-based proof. Large steps need not reduce distance, and a nonzero subgradient norm does not imply a positive objective gap at a kink.
5 Oscillating iterates, converging averages
Run the subgradient method on the same function. Compare the last point with the best point seen and the step-weighted average that the theorem controls.
G = √5, D = ‖w₀‖, f⋆ = 0.
Parameter path and weighted average
Click to change the start, or use the numeric inputs above. Axes have equal scale.
Objective gap
The bound applies to the average and best pre-update point, not the latest point.
max{f(w̄k), min0≤j<k f(wj)} ≤ [D² + G² Σj<k ηj²] / [2 Σj<k ηj].
Indexing, subgradient choices, and the guarantee
The display at k contains wk after k updates. Its average and best value use only w₀,…,wk−1. At k = 0 neither is defined. Every update uses g₁ = sign(w₁) and g₂ = 2 sign(w₂); at an exactly zero coordinate the demo selects g₁ = 0 or g₂ = 2, both valid subgradients. No near-zero values are rounded to zero.
The horizon-tuned step D/(G√T) remains fixed for the whole run. The bound at its final horizon is GD/√T; at intermediate k, the full displayed formula is used. Changing T restarts the run. For an initial point already at the optimum, the horizon-tuned option simply stays there.
A constant step can produce a cycle. The theorem's nonzero limiting upper bound is not an unavoidable error floor for every function or for every averaged sequence. The decreasing schedules have bounds that tend to zero. This simple example can converge faster than the worst-case guarantee.
The logarithmic chart puts exact zero and values below 10⁻⁵ on the bottom plotting row; the numeric readouts retain their values. The horizontal axis is always linear. A theorem bound on objective gap does not require the selected subgradient norm to go to zero.