Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

14. Optimization & Machine Learning: Smooth Optimization

CNRS & DMA, École Normale Supérieure

Chapter PDF · Complete book

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.

14.1 Motivation in Machine Learning

14.1.1 Unconstrained Optimization

Throughout most of this chapter, we consider unconstrained convex optimization problems of the form

infxRp  f(x),(14.1)\underset{x \in \mathbb{R}^p}{\inf}\; f(x), \tag{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

argminx  f(x):={xRp  ;  f(x)=inff},\underset{x}{\mathop{\mathrm{argmin}}}\; f(x) \mathrel{:=} \left\{ x \in \mathbb{R}^p \;;\; f(x) = \inf{f} \right\} ,

for the set of minimizers of ff, which may contain several points or be empty: argminf=\mathop{\mathrm{argmin}}f = \emptyset. When a minimizer exists, we write the optimization problem as

minxRp  f(x).(14.2)\underset{x \in \mathbb{R}^p}{\min}\; f(x). \tag{14.2}

In learning, f(x)f(x) is typically an empirical risk for regression or classification, and pp is the number of model parameters. For a linear model, the training sample is (ai,yi)i=1n(a_i,y_i)_{i=1}^n with feature vectors aiRpa_i \in \mathbb{R}^p.

Let ARn×pA \in \mathbb{R}^{n \times p} be the matrix with feature vectors aia_i 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.

14.1.2 Regression

For real-valued responses yiRy_i\in\mathbb{R}, the least-squares objective is

f(x)=12i=1n(yix,ai)2=12 ⁣Axy ⁣2,(14.3)f(x) = \frac{1}{2}\sum_{i=1}^n (y_i-\langle x,\,a_i\rangle)^2 = \frac{1}{2}|\!| Ax-y |\!|^2, \tag{14.3}

as illustrated in Figure 14.1.

Here u,v=i=1puivi\langle u,\,v\rangle=\sum_{i=1}^p u_i v_i is the canonical inner product in Rp\mathbb{R}^p and  ⁣ ⁣2=,|\!| \cdot |\!|^2=\langle \cdot,\,\cdot\rangle.

14.1.3 Classification

For classification, yi{1,1}y_i \in \{-1,1\}, in which case

f(x)=i=1n(yix,ai)=L(diag(y)Ax)(14.4)f(x) = \sum_{i=1}^n \ell(-y_i \langle x,\,a_i\rangle) = L( - \mathop{\mathrm{diag}}(y) A x ) \tag{14.4}

where \ell is a smooth convex surrogate for the 0-1 loss 1[0,)\mathbf{1}_{[0,\infty)}, counting zero margin as an error.

For instance, (u)=log(1+exp(u))/log2\ell(u)=\log(1+\exp(u))/\log 2 satisfies (u)1[0,)(u)\ell(u)\geqslant\mathbf{1}_{[0,\infty)}(u), with equality at u=0u=0. The normalization makes this upper bound tight at the decision boundary. The matrix diag(y)Rn×n\mathop{\mathrm{diag}}(y) \in \mathbb{R}^{n \times n} is the diagonal matrix with yiy_i along the diagonal (see Figure 14.1, panel 3). The separable loss function L:RnRL:\mathbb{R}^n\rightarrow\mathbb{R} is, for zRnz \in \mathbb{R}^n, L(z)=i(zi)L(z)=\sum_i \ell(z_i).

14.2 Basics of Convex Analysis

14.2.1 Existence of Solutions

Problem (14.1) need not have a minimizer. An objective ff may be unbounded below: for f(x)=x2f(x)=-x^2, the infimum is -\infty. The objective ff can also have a finite unattained infimum: for f(x)=exf(x)=e^{-x}, it is inff=0\inf f=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\Omega\subset\mathbb{R}^p. In finite dimensions, compactness means that Ω\Omega 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)+f(x) \rightarrow +\infty as  ⁣x ⁣+|\!| x |\!|\rightarrow+\infty. For any x0Rpx_0 \in \mathbb{R}^p, consider the sublevel set

Ω={xRp  ;  f(x)f(x0)}\Omega= \left\{ x \in \mathbb{R}^p \;;\; f(x) \leqslant f(x_0) \right\}

Coercivity makes this set bounded, and continuity of ff 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)f(x)=\min(1,x^2) has a unique minimizer but is not coercive.

Figure 14.3. Coercivity condition for least squares.

14.2.2 Convexity

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(x,y) \in (\mathbb{R}^p)^2,

t[0,1],f((1t)x+ty)(1t)f(x)+tf(y)(14.5)\forall \,t \in [0,1], \quad f((1-t)x + t y) \leqslant(1-t)f(x) + t f(y) \tag{14.5}

The graph lies below each secant, and above each tangent when differentiable; see Figure 14.4.

If xx^\star is a local minimizer of a convex ff, then xx^\star is a global minimizer, i.e. xargminfx^\star \in \mathop{\mathrm{argmin}}f.

Convexity is preserved by several useful operations. If ff and gg are convex and a,ba, b are positive, then af+bga f + b g and max(f,g)\max(f,g) are convex. If g:RqRg : \mathbb{R}^q \rightarrow \mathbb{R} is convex and BRq×p,bRqB \in \mathbb{R}^{q \times p}, b \in \mathbb{R}^q, then the affine composition f(x)=g(Bx+b)f(x) = g(B x+b) is convex.

Thus the squared loss (14.3) is convex, since  ⁣ ⁣2/2|\!| \cdot |\!|^2/2 is a sum of convex squares.

Similarly, convexity of \ell implies convexity of LL 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=(1t)x+tyx_t=(1-t)x+ty and t=(1t)f(x)+tf(y)\ell_t=(1-t)f(x)+tf(y), with 0<t<10<t<1.

Figure 14.5. Comparison of convex functions f:RpRf : \mathbb{R}^p \rightarrow \mathbb{R} (for p=1p=1) and convex sets CRpC \subset \mathbb{R}^p (for p=2p=2).

Strict convexity.

When ff is convex, one can strengthen the condition (14.5) and impose that the inequality is strict for distinct x,yx,y and t]0,1[t\in]0,1[ (see Figure 14.4, panels 3 and 4), i.e.

t]0,1[,f((1t)x+ty)<(1t)f(x)+tf(y).(14.6)\forall \,t \in ]0,1[, \quad f((1-t)x + t y) < (1-t)f(x) + t f(y). \tag{14.6}

A minimizer xx^\star is then unique if it exists. Otherwise, two minimizers x1x2x_1^\star \neq x_2^\star would satisfy f(x1+x22)<f(x1)f(\frac{x_1^\star+x_2^\star}{2}) < f(x_1^\star) by strict convexity, contradicting optimality.

14.2.3 Convex Sets

A set ΩRp\Omega\subset \mathbb{R}^p is convex if every pair (x,y)Ω2(x,y) \in \Omega^2 satisfies (1t)x+tyΩ(1-t)x + t y \in \Omega for all t[0,1]t \in [0,1].

A function ff is convex exactly when its epigraph epi(f):={(x,t)Rp+1  ;  tf(x)}\text{epi}(f) \mathrel{:=} \left\{ (x,t) \in \mathbb{R}^{p+1} \;;\; t \geqslant f(x) \right\} is a convex set.

14.3 Derivative and gradient

14.3.1 Gradient

Figure 14.6. The gradient as a vector field.

When all coordinate derivatives of ff exist, define

f(x):=(f(x)x1,,f(x)xp)Rp\nabla f(x) \mathrel{:=}\left( \frac{ \partial f(x)}{\partial x_1} , \ldots, \frac{ \partial f(x)}{\partial x_p} \right)^\top \in \mathbb{R}^p

as the gradient vector. The map f:RpRp\nabla f : \mathbb{R}^p \rightarrow \mathbb{R}^p is a vector field, and its coordinate derivatives are defined by

f(x)xk:=limη0f(x+ηδk)f(x)η\frac{ \partial f(x)}{\partial x_k} \mathrel{:=}\lim_{\eta \rightarrow 0} \frac{f(x+\eta \delta_k)-f(x)}{\eta}

where δk=(0,,0,1,0,,0)Rp\delta_k=(0,\ldots,0,1,0,\ldots,0)^\top \in \mathbb{R}^p is the kkth canonical basis vector.

Existence of the coordinate derivatives, hence of f(x)\nabla f(x), does not imply differentiability of ff. Differentiability of ff at xx requires

f(x+ε)=f(x)+ε,f(x)+o( ⁣ε ⁣).(14.7)f(x+\varepsilon) = f(x) + \langle \varepsilon,\,\nabla f(x)\rangle + o(|\!| \varepsilon |\!|). \tag{14.7}

The remainder notation R(ε)=o( ⁣ε ⁣)R(\varepsilon) = o(|\!| \varepsilon |\!|) means decay faster than the perturbation ε\varepsilon as it tends to 0: R(ε) ⁣ε ⁣0\frac{R(\varepsilon)}{|\!| \varepsilon |\!|} \rightarrow 0 as ε0\varepsilon\rightarrow 0. Coordinate derivatives concern the behavior of ff along the axes, whereas differentiability requires the expansion for every sequence ε0\varepsilon\rightarrow 0.

For example, f(x)=2x1x2(x1+x2)x12+x22f(x)=\frac{2 x_1 x_2 (x_1+x_2)}{x_1^2+x_2^2} with f(0)=0f(0)=0 has both coordinate derivatives equal to zero at the origin. Yet f(t,t)=2tf(t,t)=2t, so the linear expansion with zero gradient fails.

The vector f(x)\nabla f(x) is uniquely determined by (14.7). To prove differentiability of ff and compute f(x)\nabla f(x), it therefore suffices to establish an expansion

f(x+ε)=f(x)+ε,g+o( ⁣ε ⁣),f(x+\varepsilon) = f(x) + \langle \varepsilon,\,g\rangle + o(|\!| \varepsilon |\!|),

which identifies f(x)=g\nabla f(x)=g.

For differentiable functions, convexity is equivalent to the graph lying above every tangent affine function.

14.3.2 First Order Conditions

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\nabla f(x)=0 but xx is not a local minimum. For instance x=0x=0 for f(x)=x2f(x)=-x^2 (here xx is a maximizer) or f(x)=x3f(x)=x^3 (here xx 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 ff 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\nabla f(x)=0, a system of pp equations in pp unknowns.

An explicit solution is often unavailable, but the equation still characterizes the minimizers xx^\star.

14.3.3 Least Squares

The gradient of the least-squares objective (14.3) follows by expanding the squared norm:

f(x+ε)=12 ⁣Axy+Aε ⁣2=12 ⁣Axy ⁣2+Axy,Aε+12 ⁣Aε ⁣2=f(x)+ε,A(Axy)+o( ⁣ε ⁣).\begin{aligned} f(x+\varepsilon) &= \frac{1}{2}|\!| Ax-y+A\varepsilon |\!|^2 = \frac12|\!| Ax-y |\!|^2+\langle Ax-y,\,A\varepsilon\rangle + \frac{1}{2}|\!| A\varepsilon |\!|^2 \\ &=f(x) + \langle \varepsilon,\,A^\top(Ax-y)\rangle + o(|\!| \varepsilon |\!|). \end{aligned}

We used  ⁣Aε ⁣2=o( ⁣ε ⁣)|\!| A\varepsilon |\!|^2 = o(|\!| \varepsilon |\!|) and the transpose AA^\top.

The transpose exchanges rows and columns, A=(Aj,i)i=1,,nj=1,,pA^\top = (A_{j,i})_{i=1,\ldots,n}^{j=1,\ldots,p}. Its essential role in gradient calculations is the adjoint identity

(u,v)Rp×Rn,Au,vRn=u,AvRp.\forall \,(u,v) \in \mathbb{R}^{p} \times \mathbb{R}^n, \quad \langle A u,\,v\rangle_{\mathbb{R}^n} = \langle u,\,A^\top v\rangle_{\mathbb{R}^p}.

Computing gradients of functions involving linear operators requires such a transposition step.

This computation shows that

f(x)=A(Axy).(14.8)\nabla f(x) = A^\top (A x - y). \tag{14.8}

Hence every minimizer xx^\star of f(x)f(x) satisfies the normal equations (AA)x=Ay(A^\top A) x^\star = A^\top y.

If AARp×pA^\star A \in \mathbb{R}^{p \times p} is invertible, then ff has a single minimizer, namely

x=(AA)1Ay.(14.9)x^\star = (A^\top A)^{-1} A^\top y. \tag{14.9}

Thus xx^\star depends linearly on yy. The operator (AA)1A(A^\top A)^{-1} A^\star is the Moore–Penrose pseudoinverse of AA; an ordinary inverse is unavailable when pnp \neq n.

The condition that AAA^\top A is invertible is equivalent to ker(A)={0}\ker(A)=\{0\}, since

AAx=0 ⁣Ax ⁣2=AAx,x=0Ax=0.A^\top A x = 0 \quad\Longrightarrow\quad|\!| Ax |\!|^2 = \langle A^\top A x,\,x\rangle = 0 \quad\Longrightarrow\quad A x= 0.

When n<pn<p, the system is underdetermined and injectivity is impossible. If npn\geqslant p and the entries of AA have a joint density, then ker(A)={0}\ker(A)=\{0\} almost surely. In general, injectivity is equivalent to the feature vectors aia_i spanning Rp\mathbb{R}^p.

Assume the feature vectors are centered, iai=0\sum_i a_i=0. Otherwise, replace each aia_i by aima_i-m, where m:=n1iaim\mathrel{:=}n^{-1}\sum_i a_i is the empirical mean. Write C:=AAC\mathrel{:=}A^\top A. Then C/nC/n is the empirical covariance matrix of the point cloud. With ai=(ai,1,,ai,p)a_i=(a_{i,1},\ldots,a_{i,p})^\top and A=(ai,j)i,jA=(a_{i,j})_{i,j}, its entries are

(k,){1,,p}2,Ck,n=1ni=1nai,kai,.\forall \,(k,\ell) \in \{1,\ldots,p\}^2, \quad \frac{C_{k,\ell}}{n} = \frac{1}{n} \sum_{i=1}^n a_{i,k} a_{i,\ell}.

In particular, Ck,k/nC_{k,k}/n is the variance along the axis kk. More generally, for any unit vector uRpu \in \mathbb{R}^p, Cu,u/n0\langle C u,\,u\rangle/n \geqslant 0 is the variance along the axis uu.

For instance, in dimension p=2p=2,

Cn=1n(i=1nai,12i=1nai,1ai,2i=1nai,1ai,2i=1nai,22).\frac{C}{n} = \frac{1}{n} \begin{pmatrix} \sum_{i=1}^n a_{i,1}^2 & \sum_{i=1}^n a_{i,1} a_{i,2} \\ \sum_{i=1}^n a_{i,1}a_{i,2} & \sum_{i=1}^n a_{i,2}^2 \end{pmatrix}.

Since CC is symmetric, choose an orthogonal matrix U=(u1,,up)U=(u_1,\ldots,u_p) whose columns are eigenvectors of C/nC/n. If (C/n)uk=λkuk(C/n)u_k=\lambda_k u_k, then C/n=Udiag(λk)UC/n=U\mathop{\mathrm{diag}}(\lambda_k)U^\top and U1=UU^{-1}=U^\top. In these coordinates, the quadratic form is a weighted sum of squares:

1nCx,x=Udiag(λk)Ux,x=diag(λk)(Ux),(Ux)=k=1pλkx,uk2.(14.10)\frac{1}{n} \langle Cx,\,x\rangle = \langle U \mathop{\mathrm{diag}}(\lambda_k) U^\top x,\,x\rangle = \langle \mathop{\mathrm{diag}}(\lambda_k) (U^\top x),\,(U^\top x)\rangle = \sum_{k=1}^p \lambda_k \langle x,\,u_k\rangle^2. \tag{14.10}

Here (Ux)k=x,uk( U^\top x )_k = \langle x,\,u_k\rangle is the coordinate kk of xx in the basis UU. Since Cx,x= ⁣Ax ⁣2\langle Cx,\,x\rangle=|\!| Ax |\!|^2, this shows that all eigenvalues are nonnegative.

Order the eigenvalues as λ1λ2λp\lambda_1 \geqslant\lambda_2 \geqslant\ldots \geqslant\lambda_p. Projection of aia_i onto the leading mm 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=2m=2) or three dimensions (m=3m=3).

When CC is positive definite, its covariance ellipsoid has principal axes (uk)k(u_k)_k and semiaxes proportional to the standard deviations λk\sqrt{\lambda_k}.

This ellipsoid closely describes a Gaussian cloud with density proportional to exp(n2C1a,a)\exp(-\frac n2\langle C^{-1}a,\,a\rangle).

For the quadratic objective 12Cx,x\frac{1}{2}\langle Cx,\,x\rangle in f(x)f(x), the level ellipsoid {x  ;  1nCx,x1}\left\{ x \;;\; \frac{1}{n}\langle Cx,\,x\rangle \leqslant 1 \right\} has the same principal axes but reciprocal widths 1/λk1/\sqrt{\lambda_k}.

Figure 14.8 shows the reciprocal axis widths in dimension p=2p=2. If CC is singular, the covariance ellipsoid is degenerate and the quadratic sublevel sets are unbounded along ker(C)\ker(C).

14.3.5 Classification

For the classification objective (14.4), assume LL is differentiable and apply (14.7) at diag(y)Ax-\mathop{\mathrm{diag}}(y) Ax:

f(x+ε)=L(diag(y)Axdiag(y)Aε)=L(diag(y)Ax)+L(diag(y)Ax),diag(y)Aε+o( ⁣diag(y)Aε ⁣).\begin{aligned} f(x+\varepsilon) &= L( -\mathop{\mathrm{diag}}(y) Ax -\mathop{\mathrm{diag}}(y) A\varepsilon) \\ &= L(-\mathop{\mathrm{diag}}(y) Ax) + \langle \nabla L( -\mathop{\mathrm{diag}}(y) Ax),\, -\mathop{\mathrm{diag}}(y) A\varepsilon\rangle + o(|\!| \mathop{\mathrm{diag}}(y) A\varepsilon |\!|). \end{aligned}

Using the fact that o( ⁣diag(y)Aε ⁣)=o( ⁣ε ⁣)o(|\!| \mathop{\mathrm{diag}}(y) A\varepsilon |\!|) = o(|\!| \varepsilon |\!|), one obtains

f(x+ε)=f(x)+L(diag(y)Ax),diag(y)Aε+o( ⁣ε ⁣)=f(x)+Adiag(y)L(diag(y)Ax),ε+o( ⁣ε ⁣),\begin{aligned} f(x+\varepsilon) &= f(x) + \langle \nabla L( -\mathop{\mathrm{diag}}(y) Ax),\,-\mathop{\mathrm{diag}}(y) A\varepsilon\rangle + o(|\!| \varepsilon |\!|) \\ &= f(x) + \langle -A^\top \mathop{\mathrm{diag}}(y) \nabla L( -\mathop{\mathrm{diag}}(y) Ax),\,\varepsilon\rangle + o(|\!| \varepsilon |\!|), \end{aligned}

Using (AB)=BA(AB)^\top = B^\top A^\top and diag(y)=diag(y)\mathop{\mathrm{diag}}(y)^\top=\mathop{\mathrm{diag}}(y) gives

f(x)=Adiag(y)L(diag(y)Ax).\nabla f(x) = -A^\top \mathop{\mathrm{diag}}(y) \nabla L( -\mathop{\mathrm{diag}}(y) Ax).

Since L(z)=i(zi)L(z)=\sum_i\ell(z_i), its gradient is L(z)=((zi))i=1n\nabla L(z)=(\ell'(z_i))_{i=1}^n. For the normalized logistic loss, (u)=eu/((1+eu)log2)\ell'(u)=e^u/((1+e^u)\log 2). Evaluated at the negative margin u=yix,aiu=-y_i\langle x,\,a_i\rangle, this scaled sigmoid is large for incorrectly classified observations and weights their contribution to the gradient.

14.3.6 Chain Rule

More generally, for f(x)=g(Bx)f(x) = g(Bx) with BRq×pB \in \mathbb{R}^{q \times p} and g:RqRg : \mathbb{R}^q \rightarrow \mathbb{R},

f(x+ε)=g(Bx+Bε)=g(Bx)+g(Bx),Bε+o( ⁣Bε ⁣)=f(x)+ε,Bg(Bx)+o( ⁣ε ⁣),f(x+\varepsilon) = g(Bx + B\varepsilon) = g(Bx) + \langle \nabla g(Bx),\,B \varepsilon\rangle + o(|\!| B \varepsilon |\!|) = f(x) + \langle \varepsilon,\,B^\top \nabla g(Bx)\rangle + o(|\!| \varepsilon |\!|),

which shows that

(gB)=BgB(14.11)\nabla ( g \circ B ) = B^\top \circ \nabla g \circ B \tag{14.11}

where “” denotes the composition of functions.

Nonlinear compositions require the differential. For F:RpRqF : \mathbb{R}^p \rightarrow \mathbb{R}^q, its differential at xx is the linear map F(x):RpRq\partial F(x) : \mathbb{R}^{p} \rightarrow \mathbb{R}^q. We represent it by its Jacobian matrix, also denoted F(x)\partial F(x), with dimensions F(x)Rq×p\partial F(x) \in \mathbb{R}^{q \times p}.

Writing F(x)=(F1(x),,Fq(x))F(x)=(F_1(x), \ldots, F_q(x)), the Jacobian entries are

(i,j){1,,q}×{1,,p},[F(x)]i,j:=Fi(x)xj.\forall \,(i,j) \in \{1,\ldots,q\} \times \{1,\ldots,p\}, \quad [ \partial F(x) ]_{i,j} \mathrel{:=}\frac{\partial F_i(x)}{\partial x_j}.

The map FF is differentiable at xx when it admits the expansion

F(x+ε)=F(x)+[F(x)](ε)+o( ⁣ε ⁣).(14.12)F(x+\varepsilon) = F(x) + [\partial F(x)](\varepsilon) + o(|\!| \varepsilon |\!|). \tag{14.12}

Here [F(x)](ε)[\partial F(x)](\varepsilon) 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=1q=1, i.e. if f:RpRf : \mathbb{R}^p \rightarrow \mathbb{R}, then the differential f(x)R1×p\partial f(x) \in \mathbb{R}^{1 \times p} and the gradient f(x)Rp×1\nabla f(x) \in \mathbb{R}^{p \times 1} are linked by equating the Taylor expansions (14.12) and (14.7)

εRp,[f(x)](ε)=f(x),εf(x)=f(x).\forall \,\varepsilon\in \mathbb{R}^p, \quad [\partial f(x)](\varepsilon) = \langle \nabla f(x),\,\varepsilon\rangle \quad\Leftrightarrow\quad \partial f(x)=\nabla f(x)^\top.

The differential satisfies the following chain rule

(GH)(x)=[G(H(x))]×[H(x)]\partial( G \circ H)(x) = [\partial G(H(x))] \times [\partial H(x)]

where “×\times” is the matrix product. For instance, if H:RpRqH : \mathbb{R}^p \rightarrow \mathbb{R}^q and G=g:RqRG = g : \mathbb{R}^q \mapsto \mathbb{R}, then f=gH:RpRf = g \circ H : \mathbb{R}^p \rightarrow \mathbb{R} and one can compute its gradient as follows

f(x)=(f(x))=([g(H(x))]×[H(x)])=[H(x)]×[g(H(x))]=[H(x)]×g(H(x)).\nabla f(x) = (\partial f(x))^\top = \left( [\partial g(H(x))] \times [\partial H(x)] \right)^\top = [\partial H(x)]^\top \times [\partial g(H(x))]^\top = [\partial H(x)]^\top \times \nabla g(H(x)).

When H(x)=BxH(x)=Bx is linear, one recovers formula (14.11).

14.4 Gradient Descent Algorithm

14.4.1 Steepest Descent Direction

The Taylor expansion (14.7) approximates ff near xx by an affine function:

f(z)=Tx(z)+o( ⁣xz ⁣)whereTx(z):=f(x)+f(x),zx,f(z) = T_x(z) + o(|\!| x-z |\!|) \quad \text{where} \quad T_x(z) \mathrel{:=}f(x) + \langle \nabla f(x),\,z-x\rangle,

Figure 14.9 illustrates the approximation. First-order methods use ff through its local model TxT_x.

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)\nabla f(x) points uphill locally, so f(x)-\nabla f(x) is a descent direction. At a fixed point xx, examine ff along the ray

τR+=[0,+[f(xτf(x))R.\tau \in \mathbb{R}^+ = [0,+\infty[ \longmapsto f(x-\tau \nabla f(x)) \in \mathbb{R}.

If ff is differentiable at xx, one has

f(xτf(x))=f(x)τf(x),f(x)+o(τ)=f(x)τ ⁣f(x) ⁣2+o(τ).f(x-\tau \nabla f(x)) = f(x) - \tau \langle \nabla f(x),\,\nabla f(x)\rangle + o(\tau) = f(x) - \tau |\!| \nabla f(x) |\!|^2 + o(\tau).

If f(x)=0\nabla f(x)=0, then xx is stationary and is a global minimizer when ff is convex. Otherwise, for sufficiently small τ\tau,

f(xτf(x))<f(x)f(x-\tau \nabla f(x)) < f(x)

so the step from xx to xτf(x)x-\tau \nabla f(x) decreases the objective.

14.4.2 Gradient Descent

Starting from x0Rpx_0 \in \mathbb{R}^p, gradient descent iterates

xk+1:=xkτkf(xk)(14.13)x_{k+1} \mathrel{:=}x_k - \tau_k \nabla f(x_k) \tag{14.13}

The parameter τk>0\tau_k>0 is the step size, or learning rate. A sufficiently small τk\tau_k decreases ff at a nonstationary iterate. Choosing τk\tau_k balances stable descent against progress per step.

One may fix τk=τ\tau_k=\tau or adapt τk\tau_k at each iteration; see Figure 14.10.

Figure 14.10. Effect of the step size τ\tau on gradient descent (panel 1) and exact line search (panel 2).

14.5 Convergence Analysis

14.5.1 Quadratic Case

Convergence analysis for the quadratic case.

We first analyze gradient descent for the quadratic objective

f(x)=12 ⁣Axy ⁣2=12Cx,xx,b+cstwhere{C:=AARp×p,b:=AyRp.f(x) = \frac{1}{2}|\!| Ax-y |\!|^2 = \frac{1}{2} \langle Cx,\,x\rangle - \langle x,\,b\rangle + \text{cst} \quad \text{where} \quad \left\{ \begin{array}{l} C \mathrel{:=}A^\top A \in \mathbb{R}^{p \times p}, \\ b \mathrel{:=}A^\top y \in \mathbb{R}^p. \end{array} \right.

We already saw that in (14.9) if ker(A)={0}\ker(A)=\{0\}, which is equivalent to CC being invertible, then there exists a single global minimizer x=(AA)1Ay=C1bx^\star = (A^\top A)^{-1} A^\top y =C^{-1}b.

The quadratic 12Cx,xx,b\frac{1}{2} \langle Cx,\,x\rangle - \langle x,\,b\rangle is convex exactly when the symmetric matrix CC is positive semidefinite, as follows from the spectral decomposition (14.10).

Figure 14.11. Contraction constant h(τ)h(\tau) for a quadratic function.

Note that when the inverse condition number ξ:=μ/L1\xi\mathrel{:=}\mu/L\ll1 is small (which is the typical setup for ill-posed problems), then the contraction constant appearing in (14.16) scales like

ρ~12ξ.(14.17)\tilde\rho \sim 1-2\xi. \tag{14.17}

We also use ε\varepsilon 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)O(\rho^k) in (14.15) is called linear convergence in optimization. The bound is global because it holds for every kk, rather than only sufficiently large kk.

If ker(A){0}\ker(A) \neq \{0\}, then CC has zero eigenvalues and the minimizer set is infinite.

A linear rate still follows because the increments xk+1xkx_{k+1}-x_k are orthogonal to ker(A)\ker(A), while the kernel component remains equal to that of x0x_0. The preceding proof applies on the orthogonal complement, with μ\mu replaced by the smallest positive eigenvalue of CC. 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.

14.5.2 General Case

We now extend the convergence analysis to general smooth convex functions.

The Hessian replaces the constant matrix CC of a quadratic objective.

Hessian.

For a twice continuously differentiable function, the Hessian matrix is

(2f)(x)=(2f(x)xixj)1i,jpRp×p.(\partial^2 f)(x) = \left( \frac{\partial^2 f(x)}{\partial x_i \partial x_j} \right)_{1 \leqslant i,j \leqslant p} \in \mathbb{R}^{p \times p}.

Each entry differentiates the iith component of the gradient with respect to the jjth coordinate. Equality of mixed partial derivatives makes 2f(x)\partial^2 f(x) symmetric.

Twice differentiability of ff at xx implies the Taylor expansion

f(x+ε)=f(x)+f(x),ε+122f(x)ε,ε+o( ⁣ε ⁣2).(14.18)f(x+\varepsilon) = f(x) + \langle \nabla f(x),\,\varepsilon\rangle + \frac{1}{2} \langle \partial^2 f(x) \varepsilon,\,\varepsilon\rangle + o(|\!| \varepsilon |\!|^2). \tag{14.18}

Thus ff has a local quadratic approximation near xx.

The Hessian is the unique symmetric matrix in this expansion. If an expansion has the form below with a symmetric matrix HH,

f(x+ε)=f(x)+f(x),ε+12Hε,ε+o( ⁣ε ⁣2).f(x+\varepsilon) = f(x) + \langle \nabla f(x),\,\varepsilon\rangle + \frac{1}{2} \langle H \varepsilon,\,\varepsilon\rangle + o(|\!| \varepsilon |\!|^2).

comparison with (14.18) identifies 2f(x)=H\partial^2 f(x)=H, avoiding separate computation of all p2p^2 partial derivatives.

Equivalently, differentiate the gradient:

f(x+ε)=f(x)+[2f(x)](ε)+o( ⁣ε ⁣)\nabla f(x+\varepsilon) = \nabla f(x) + [\partial^2 f(x)](\varepsilon) + o(|\!| \varepsilon |\!|)

where [2f(x)](ε)Rp[\partial^2 f(x)](\varepsilon) \in \mathbb{R}^p is the product of the Hessian 2f(x)\partial^2 f(x) with ε\varepsilon.

A twice differentiable function ff on Rp\mathbb{R}^p is convex exactly when, at every xx, the Hessian 2f(x)\partial^2 f(x) is positive semidefinite.

Positive definiteness everywhere implies strict convexity of ff, but is not necessary: x4x^4 is strictly convex on R\mathbb{R} although its second derivative vanishes at x=0x=0.

For a quadratic objective f(x)=12Cx,xx,uf(x)=\frac12\langle Cx,\,x\rangle-\langle x,\,u\rangle, the gradient f(x)=Cxu\nabla f(x) = Cx-u gives the constant Hessian 2f(x)=C\partial^2 f(x) = C.

For the classification function, one has

f(x)=Adiag(y)L(diag(y)Ax).\nabla f(x) = -A^\top \mathop{\mathrm{diag}}(y) \nabla L( -\mathop{\mathrm{diag}}(y) Ax).

and thus

f(x+ε)=Adiag(y)L(diag(y)Axdiag(y)Aε)=f(x)Adiag(y)[2L(diag(y)Ax)](diag(y)Aε)+o( ⁣ε ⁣)\begin{aligned} \nabla f(x+\varepsilon) &= -A^\top \mathop{\mathrm{diag}}(y) \nabla L( -\mathop{\mathrm{diag}}(y) Ax-\mathop{\mathrm{diag}}(y)A\varepsilon) \\ &= \nabla f(x) -A^\top \mathop{\mathrm{diag}}(y) [\partial^2 L( -\mathop{\mathrm{diag}}(y) Ax)]( -\mathop{\mathrm{diag}}(y) A\varepsilon) + o(|\!| \varepsilon |\!|) \end{aligned}

Since L(u)=((ui))\nabla L(u) = (\ell'(u_i)) one has 2L(u)=diag((ui))\partial^2 L(u)=\mathop{\mathrm{diag}}(\ell''(u_i)). This means that

2f(x)=Adiag(y)×diag((diag(y)Ax))×diag(y)A.\partial^2 f(x) = A^\top \mathop{\mathrm{diag}}(y) \times \mathop{\mathrm{diag}}( \ell''(-\mathop{\mathrm{diag}}(y) Ax) ) \times \mathop{\mathrm{diag}}(y) A.

This matrix is symmetric positive semidefinite when \ell is convex, because \ell'' is nonnegative.

For convergence analysis, uniform Hessian bounds play the role of the spectral bounds on CC in the quadratic case. We require these bounds on 2f(x)\partial^2 f(x) at every xx.

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>0L>0, quantify the smoothness of ff by requiring an LL-Lipschitz gradient:

(x,x)(Rp)2, ⁣f(x)f(x) ⁣L ⁣xx ⁣.(RL)\forall \,(x,x') \in (\mathbb{R}^p)^2, \quad |\!| \nabla f(x)-\nabla f(x') |\!| \leqslant L |\!| x-x' |\!|. \tag{$\mathcal{R}_L$}

A linear convergence guarantee for the iterates follows from a uniform lower curvature bound. We impose this by assuming that ff is μ\mu-strongly convex

(x,x)(Rp)2,f(x)f(x),xxμ ⁣xx ⁣2.(Sμ)\forall \,(x,x')\in (\mathbb{R}^p)^2, \quad \langle \nabla f(x)-\nabla f(x'),\, x-x' \rangle \geqslant\mu |\!| x-x' |\!|^2. \tag{$\mathcal{S}_\mu$}

For C2\mathcal{C}^2 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)\partial^2 f(x) in [μ,L][\mu,L]. The upper bound is also equivalent to  ⁣2f(x) ⁣opL|\!| \partial^2 f(x) |\!|_{\text{op}} \leqslant L where  ⁣ ⁣op|\!| \cdot |\!|_{\text{op}} is the operator norm, i.e. the largest singular value.

In the special case of a quadratic function of the form 12Cx,xb,x\frac12\langle Cx,\,x\rangle-\langle b,\,x\rangle (with CC symmetric positive semidefinite), 2f(x)=C\partial^2 f(x)=C is constant, so that [μ,L][\mu,L] can be chosen to be the range of the eigenvalues of CC.

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\varepsilon\ll 1, the rate (14.26) has the same qualitative dependence as the quadratic rate (14.17):

LL+μ=(1+ε)12112ε.\sqrt{ \frac{L}{L+\mu} } = (1+\varepsilon)^{-\frac{1}{2}} \sim 1 - \frac{1}{2}\varepsilon.

14.5.3 Acceleration

For a convex function with an LL-Lipschitz gradient, ordinary gradient descent has a worst-case O(1/k)O(1/k) objective bound. Accelerated methods combine a gradient step with extrapolation. Starting from y0=x0y_0=x_0 and 0<s1/L0<s\leqslant 1/L, one example is

xk+1=yksf(yk),yk+1=xk+1+βk(xk+1xk),βk=kk+3.x_{k+1}=y_k-s\nabla f(y_k),\qquad y_{k+1}=x_{k+1}+\beta_k(x_{k+1}-x_k),\qquad \beta_k=\frac{k}{k+3}.

This is a Nesterov-type scheme. It differs from the heavy-ball method, which evaluates the gradient at xkx_k and adds momentum to that step. The accelerated scheme satisfies

f(xk)f(x)=O( ⁣x0x ⁣2sk2).f(x_k)-f(x^\star)=O\left(\frac{|\!| x_0-x^\star |\!|^2}{s k^2}\right).

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\tau=\sqrt s and t=kτt=k\tau. Since βk1=(k1)/(k+2)\beta_{k-1}=(k-1)/(k+2),

xk+12xk+xk1τ2+3(k+2)τxkxk1τ+f(yk)=0.\frac{x_{k+1}-2x_k+x_{k-1}}{\tau^2} +\frac{3}{(k+2)\tau}\frac{x_k-x_{k-1}}{\tau} +\nabla f(y_k)=0.

If the interpolated iterates converge smoothly as τ0\tau\to0, the limit solves

x(t)+3tx(t)+f(x(t))=0,x(0)=x0,x(0)=0.x''(t)+\frac3t x'(t)+\nabla f(x(t))=0,\qquad x(0)=x_0,\quad x'(0)=0.

The term 3x(t)/t3x'(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\alpha/t for α3\alpha\geqslant 3 also admit O(t2)O(t^{-2}) objective estimates under the usual convexity assumptions.