Training a model often reduces to minimizing a differentiable objective, so the geometry of that objective determines how optimization algorithms progress. Starting from regression and classification, we develop convexity, derivatives, and optimality conditions, then derive gradient descent and practical step-size rules. Quadratic examples guide the convergence analysis, which extends to smooth convex objectives and explains the effects of conditioning, strong convexity, and acceleration.
Throughout most of this chapter, we consider unconstrained convex optimization problems of the form
x∈Rpinff(x),(14.1)
and seek algorithms that approximate a minimizer, when one exists, with a low cost per iteration.
The first-order methods studied here use gradient information. We write
xargminf(x):={x∈Rp;f(x)=inff},
for the set of minimizers of f, which may contain several points or be empty: argminf=∅. When a minimizer exists, we write the optimization problem as
x∈Rpminf(x).(14.2)
In learning, f(x) is typically an empirical risk for regression or classification, and p is the number of model parameters. For a linear model, the training sample is (ai,yi)i=1n with feature vectors ai∈Rp.
Let A∈Rn×p be the matrix with feature vectors ai as its rows.
Figure 14.1. Panels 1 and 2: linear regression and a linear classifier. Panel 3: the 0-1 loss and its normalized logistic and hinge upper bounds, both tight at zero margin.
where ℓ is a smooth convex surrogate for the 0-1 loss 1[0,∞), counting zero margin as an error.
For instance, ℓ(u)=log(1+exp(u))/log2 satisfies ℓ(u)⩾1[0,∞)(u), with equality at u=0. The normalization makes this upper bound tight at the decision boundary. The matrix diag(y)∈Rn×n is the diagonal matrix with yi along the diagonal (see Figure 14.1, panel 3). The separable loss function L:Rn→R is, for z∈Rn, L(z)=∑iℓ(zi).
Problem (14.1) need not have a minimizer. An objective f may be unbounded below: for f(x)=−x2, the infimum is −∞. The objective f can also have a finite unattained infimum: for f(x)=e−x, it is inff=0.
Figure 14.2. Left: no minimizer. Middle: multiple minimizers. Right: a unique minimizer.
A continuous function attains its minimum on a nonempty compact set Ω⊂Rp. In finite dimensions, compactness means that Ω is closed and bounded. Lower semicontinuity suffices for attainment, but we use continuity here. For unconstrained minimization, coercivity provides a compact set to which the search can be restricted: f(x)→+∞ as ∣∣x∣∣→+∞. For any x0∈Rp, consider the sublevel set
Ω={x∈Rp;f(x)⩽f(x0)}
Coercivity makes this set bounded, and continuity of f makes it closed. For a continuous convex function, coercivity is in fact equivalent to a nonempty bounded minimizer set. Convexity matters: f(x)=min(1,x2) has a unique minimizer but is not coercive.
Figure 14.3. Coercivity condition for least squares.
Convexity is central to optimization because every local minimizer is global, and many convex problems admit efficient algorithms. A function is convex if, for every pair (x,y)∈(Rp)2,
∀t∈[0,1],f((1−t)x+ty)⩽(1−t)f(x)+tf(y)(14.5)
The graph lies below each secant, and above each tangent when differentiable; see Figure 14.4.
If x⋆ is a local minimizer of a convex f, then x⋆ is a global minimizer, i.e. x⋆∈argminf.
Convexity is preserved by several useful operations. If f and g are convex and a,b are positive, then af+bg and max(f,g) are convex. If g:Rq→R is convex and B∈Rq×p,b∈Rq, then the affine composition f(x)=g(Bx+b) is convex.
Thus the squared loss (14.3) is convex, since ∣∣⋅∣∣2/2 is a sum of convex squares.
Similarly, convexity of ℓ implies convexity of L and of the classification objective (14.4).
Figure 14.4. Convex and nonconvex functions; strictly convex and convex but not strictly convex functions. Here xt=(1−t)x+ty and ℓt=(1−t)f(x)+tf(y), with 0<t<1.
Figure 14.5. Comparison of convex functions f:Rp→R (for p=1) and convex sets C⊂Rp (for p=2).
Strict convexity.
When f is convex, one can strengthen the condition (14.5) and impose that the inequality is strict for distinct x,y and t∈]0,1[ (see Figure 14.4, panels 3 and 4), i.e.
∀t∈]0,1[,f((1−t)x+ty)<(1−t)f(x)+tf(y).(14.6)
A minimizer x⋆ is then unique if it exists. Otherwise, two minimizers x1⋆=x2⋆ would satisfy f(2x1⋆+x2⋆)<f(x1⋆) by strict convexity, contradicting optimality.
When all coordinate derivatives of f exist, define
∇f(x):=(∂x1∂f(x),…,∂xp∂f(x))⊤∈Rp
as the gradient vector. The map ∇f:Rp→Rp is a vector field, and its coordinate derivatives are defined by
∂xk∂f(x):=η→0limηf(x+ηδk)−f(x)
where δk=(0,…,0,1,0,…,0)⊤∈Rp is the kth canonical basis vector.
Existence of the coordinate derivatives, hence of ∇f(x), does not imply differentiability of f. Differentiability of f at x requires
f(x+ε)=f(x)+⟨ε,∇f(x)⟩+o(∣∣ε∣∣).(14.7)
The remainder notation R(ε)=o(∣∣ε∣∣) means decay faster than the perturbation ε as it tends to 0: ∣∣ε∣∣R(ε)→0 as ε→0. Coordinate derivatives concern the behavior of f along the axes, whereas differentiability requires the expansion for every sequence ε→0.
For example, f(x)=x12+x222x1x2(x1+x2) with f(0)=0 has both coordinate derivatives equal to zero at the origin. Yet f(t,t)=2t, so the linear expansion with zero gradient fails.
The vector ∇f(x) is uniquely determined by (14.7). To prove differentiability of f and compute ∇f(x), it therefore suffices to establish an expansion
f(x+ε)=f(x)+⟨ε,g⟩+o(∣∣ε∣∣),
which identifies ∇f(x)=g.
For differentiable functions, convexity is equivalent to the graph lying above every tangent affine function.
A vanishing gradient is necessary for local optimality, and will also guide the algorithms developed below.
Note that the converse is not true in general, since one might have ∇f(x)=0 but x is not a local minimum. For instance x=0 for f(x)=−x2 (here x is a maximizer) or f(x)=x3 (here x is neither a maximizer nor a minimizer; it is a stationary inflection point), see Fig. 14.7.
Stationarity alone therefore neither certifies a local minimum nor guarantees convergence of a numerical method to that point. Both depend on the local geometry.
Convexity of f makes stationarity sufficient as well as necessary.
Figure 14.7. Local extrema (panel 1), a stationary inflection point (panel 2), and a global minimizer (panel 3).
For a differentiable convex objective, minimization is therefore equivalent to solving ∇f(x)=0, a system of p equations in p unknowns.
An explicit solution is often unavailable, but the equation still characterizes the minimizers x⋆.
The transpose exchanges rows and columns, A⊤=(Aj,i)i=1,…,nj=1,…,p. Its essential role in gradient calculations is the adjoint identity
∀(u,v)∈Rp×Rn,⟨Au,v⟩Rn=⟨u,A⊤v⟩Rp.
Computing gradients of functions involving linear operators requires such a transposition step.
This computation shows that
∇f(x)=A⊤(Ax−y).(14.8)
Hence every minimizer x⋆ of f(x) satisfies the normal equations (A⊤A)x⋆=A⊤y.
If A⋆A∈Rp×p is invertible, then f has a single minimizer, namely
x⋆=(A⊤A)−1A⊤y.(14.9)
Thus x⋆ depends linearly on y. The operator (A⊤A)−1A⋆ is the Moore–Penrose pseudoinverse of A; an ordinary inverse is unavailable when p=n.
The condition that A⊤A is invertible is equivalent to ker(A)={0}, since
A⊤Ax=0⟹∣∣Ax∣∣2=⟨A⊤Ax,x⟩=0⟹Ax=0.
When n<p, the system is underdetermined and injectivity is impossible. If n⩾p and the entries of A have a joint density, then ker(A)={0} almost surely. In general, injectivity is equivalent to the feature vectors ai spanning Rp.
Assume the feature vectors are centered, ∑iai=0. Otherwise, replace each ai by ai−m, where m:=n−1∑iai is the empirical mean. Write C:=A⊤A. Then C/n is the empirical covariance matrix of the point cloud. With ai=(ai,1,…,ai,p)⊤ and A=(ai,j)i,j, its entries are
∀(k,ℓ)∈{1,…,p}2,nCk,ℓ=n1i=1∑nai,kai,ℓ.
In particular, Ck,k/n is the variance along the axis k. More generally, for any unit vector u∈Rp, ⟨Cu,u⟩/n⩾0 is the variance along the axis u.
Since C is symmetric, choose an orthogonal matrix U=(u1,…,up) whose columns are eigenvectors of C/n. If (C/n)uk=λkuk, then C/n=Udiag(λk)U⊤ and U−1=U⊤. In these coordinates, the quadratic form is a weighted sum of squares:
Here (U⊤x)k=⟨x,uk⟩ is the coordinate k of x in the basis U. Since ⟨Cx,x⟩=∣∣Ax∣∣2, this shows that all eigenvalues are nonnegative.
Figure 14.8. Left: point clouds (ai)i and their principal directions. Right: the quadratic part of f(x).
Order the eigenvalues as λ1⩾λ2⩾…⩾λp. Projection of ai onto the leading m eigenvectors gives principal component analysis (PCA), the optimal linear reconstruction in squared error. It is used for compression, dimensionality reduction, and visualization in two dimensions (m=2) or three dimensions (m=3).
When C is positive definite, its covariance ellipsoid has principal axes (uk)k and semiaxes proportional to the standard deviations λk.
This ellipsoid closely describes a Gaussian cloud with density proportional to exp(−2n⟨C−1a,a⟩).
For the quadratic objective 21⟨Cx,x⟩ in f(x), the level ellipsoid {x;n1⟨Cx,x⟩⩽1} has the same principal axes but reciprocal widths 1/λk.
Figure 14.8 shows the reciprocal axis widths in dimension p=2. If C is singular, the covariance ellipsoid is degenerate and the quadratic sublevel sets are unbounded along ker(C).
Since L(z)=∑iℓ(zi), its gradient is ∇L(z)=(ℓ′(zi))i=1n. For the normalized logistic loss, ℓ′(u)=eu/((1+eu)log2). Evaluated at the negative margin u=−yi⟨x,ai⟩, this scaled sigmoid is large for incorrectly classified observations and weights their contribution to the gradient.
Nonlinear compositions require the differential. For F:Rp→Rq, its differential at x is the linear map ∂F(x):Rp→Rq. We represent it by its Jacobian matrix, also denoted ∂F(x), with dimensions ∂F(x)∈Rq×p.
Writing F(x)=(F1(x),…,Fq(x)), the Jacobian entries are
∀(i,j)∈{1,…,q}×{1,…,p},[∂F(x)]i,j:=∂xj∂Fi(x).
The map F is differentiable at x when it admits the expansion
F(x+ε)=F(x)+[∂F(x)](ε)+o(∣∣ε∣∣).(14.12)
Here [∂F(x)](ε) denotes matrix-vector multiplication. The matrix in this expansion is unique, so the expansion can also be used to compute the differential.
For the special case q=1, i.e. if f:Rp→R, then the differential ∂f(x)∈R1×p and the gradient ∇f(x)∈Rp×1 are linked by equating the Taylor expansions (14.12) and (14.7)
∀ε∈Rp,[∂f(x)](ε)=⟨∇f(x),ε⟩⇔∂f(x)=∇f(x)⊤.
The differential satisfies the following chain rule
∂(G∘H)(x)=[∂G(H(x))]×[∂H(x)]
where “×” is the matrix product. For instance, if H:Rp→Rq and G=g:Rq↦R, then f=g∘H:Rp→R and one can compute its gradient as follows
Figure 14.9 illustrates the approximation. First-order methods use f through its local model Tx.
Figure 14.9. Panels 1 and 2: first-order Taylor approximations in one and two dimensions. Panels 3 and 4: the gradient is orthogonal to the level set; the diagram illustrates the proof.
Figure 14.9. Panels 1 and 2: first-order Taylor approximations in one and two dimensions. Panels 3 and 4: the gradient is orthogonal to the level set; the diagram illustrates the proof.
A nonzero gradient ∇f(x) points uphill locally, so −∇f(x) is a descent direction. At a fixed point x, examine f along the ray
The parameter τk>0 is the step size, or learning rate. A sufficiently small τk decreases f at a nonstationary iterate. Choosing τk balances stable descent against progress per step.
One may fix τk=τ or adapt τk at each iteration; see Figure 14.10.
Figure 14.10. Effect of the step size τ on gradient descent (panel 1) and exact line search (panel 2).
We already saw that in (14.9) if ker(A)={0}, which is equivalent to C being invertible, then there exists a single global minimizer x⋆=(A⊤A)−1A⊤y=C−1b.
The quadratic 21⟨Cx,x⟩−⟨x,b⟩ is convex exactly when the symmetric matrix C is positive semidefinite, as follows from the spectral decomposition (14.10).
Figure 14.11. Contraction constant h(τ) for a quadratic function.
Note that when the inverse condition number ξ:=μ/L≪1 is small (which is the typical setup for ill-posed problems), then the contraction constant appearing in (14.16) scales like
ρ~∼1−2ξ.(14.17)
We also use ε below for this inverse condition number. The condition number is the ratio of the largest to the smallest singular value, and its minimum value is 1, attained by orthogonal matrices.
The geometric decay O(ρk) in (14.15) is called linear convergence in optimization. The bound is global because it holds for every k, rather than only sufficiently large k.
If ker(A)={0}, then C has zero eigenvalues and the minimizer set is infinite.
A linear rate still follows because the increments xk+1−xk are orthogonal to ker(A), while the kernel component remains equal to that of x0. The preceding proof applies on the orthogonal complement, with μ replaced by the smallest positive eigenvalue of C. This eigenvalue may be very small, giving a contraction factor close to one. The spectral argument also relies on the quadratic structure. We therefore give a different analysis that provides a sublinear bound on the objective value.
We now extend the convergence analysis to general smooth convex functions.
The Hessian replaces the constant matrix C of a quadratic objective.
Hessian.
For a twice continuously differentiable function, the Hessian matrix is
(∂2f)(x)=(∂xi∂xj∂2f(x))1⩽i,j⩽p∈Rp×p.
Each entry differentiates the ith component of the gradient with respect to the jth coordinate. Equality of mixed partial derivatives makes ∂2f(x) symmetric.
Twice differentiability of f at x implies the Taylor expansion
Thus f has a local quadratic approximation near x.
The Hessian is the unique symmetric matrix in this expansion. If an expansion has the form below with a symmetric matrix H,
f(x+ε)=f(x)+⟨∇f(x),ε⟩+21⟨Hε,ε⟩+o(∣∣ε∣∣2).
comparison with (14.18) identifies ∂2f(x)=H, avoiding separate computation of all p2 partial derivatives.
Equivalently, differentiate the gradient:
∇f(x+ε)=∇f(x)+[∂2f(x)](ε)+o(∣∣ε∣∣)
where [∂2f(x)](ε)∈Rp is the product of the Hessian ∂2f(x) with ε.
A twice differentiable function f on Rp is convex exactly when, at every x, the Hessian ∂2f(x) is positive semidefinite.
Positive definiteness everywhere implies strict convexity of f, but is not necessary: x4 is strictly convex on R although its second derivative vanishes at x=0.
For a quadratic objective f(x)=21⟨Cx,x⟩−⟨x,u⟩, the gradient ∇f(x)=Cx−u gives the constant Hessian ∂2f(x)=C.
Since ∇L(u)=(ℓ′(ui)) one has ∂2L(u)=diag(ℓ′′(ui)). This means that
∂2f(x)=A⊤diag(y)×diag(ℓ′′(−diag(y)Ax))×diag(y)A.
This matrix is symmetric positive semidefinite when ℓ is convex, because ℓ′′ is nonnegative.
For convergence analysis, uniform Hessian bounds play the role of the spectral bounds on C in the quadratic case. We require these bounds on ∂2f(x) at every x.
Integrating these local bounds yields global inequalities that support an analysis similar to the quadratic one.
Smoothness and strong convexity.
Figure 14.12. Quadratic upper and lower bounds for a smooth strongly convex function.
For L>0, quantify the smoothness of f by requiring an L-Lipschitz gradient:
∀(x,x′)∈(Rp)2,∣∣∇f(x)−∇f(x′)∣∣⩽L∣∣x−x′∣∣.(RL)
A linear convergence guarantee for the iterates follows from a uniform lower curvature bound. We impose this by assuming that f is μ-strongly convex
For C2 functions, these conditions are equivalent to uniform Hessian bounds.
Equation (14.19) places the objective between a lower quadratic tangent model from strong convexity and an upper quadratic tangent model from smoothness.
Condition (14.20) places every eigenvalue of ∂2f(x) in [μ,L]. The upper bound is also equivalent to ∣∣∂2f(x)∣∣op⩽L where ∣∣⋅∣∣op is the operator norm, i.e. the largest singular value.
In the special case of a quadratic function of the form 21⟨Cx,x⟩−⟨b,x⟩ (with C symmetric positive semidefinite), ∂2f(x)=C is constant, so that [μ,L] can be chosen to be the range of the eigenvalues of C.
Convergence analysis.
For a general smooth convex function, gradient descent admits a sublinear objective bound. Strong convexity gives a linear rate for the iterates. Other structural assumptions can also yield faster rates, but are outside this analysis.
Without strong convexity, the minimizer need not be unique.
For poor conditioning, ε≪1, the rate (14.26) has the same qualitative dependence as the quadratic rate (14.17):
For a convex function with an L-Lipschitz gradient, ordinary gradient descent has a worst-case O(1/k) objective bound. Accelerated methods combine a gradient step with extrapolation. Starting from y0=x0 and 0<s⩽1/L, one example is
This is a Nesterov-type scheme. It differs from the heavy-ball method, which evaluates the gradient at xk and adds momentum to that step. The accelerated scheme satisfies
f(xk)−f(x⋆)=O(sk2∣∣x0−x⋆∣∣2).
This is a worst-case guarantee; it does not ensure that every individual trajectory is faster. If strong convexity is known, appropriately tuned acceleration or restart can give a linear rate.
A formal continuous-time limit explains the momentum schedule. Set τ=s and t=kτ. Since βk−1=(k−1)/(k+2),
If the interpolated iterates converge smoothly as τ→0, the limit solves
x′′(t)+t3x′(t)+∇f(x(t))=0,x(0)=x0,x′(0)=0.
The term 3x′(t)/t is a time-dependent friction. Its decay permits inertial motion while retaining an accelerated energy bound. The coefficient 3 is not the only admissible choice: related dynamics with friction α/t for α⩾3 also admit O(t−2) objective estimates under the usual convexity assumptions.