Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Gradient descent practice

Original practice questions (PDF)

1. Descent at a safe step size

Let f:ℝn→ℝf:\mathbb R^n\to\mathbb R be LL-smooth. For x+=x−t∇f(x)x^+=x-t\nabla f(x) with 0<t≤1/L0<t\le 1/L, use the smoothness upper bound to show f(x+)≤f(x)−t2∥∇f(x)∥22.f(x^+)\le f(x)-\tfrac t2\|\nabla f(x)\|_2^2.

Solution to exercise 1

With g=∇f(x)g=\nabla f(x), plug x+−x=−tgx^+-x=-tg into the bound. This gives f(x+)≤f(x)−t(1−Lt/2)∥g∥22f(x^+)\le f(x)-t(1-Lt/2)\|g\|_2^2. Since Lt≤1Lt\le1, the coefficient in parentheses is at least 1/21/2.

2. Termination of Armijo backtracking

Let ff be LL-smooth, with c,β∈(0,1)c,\beta\in(0,1). Start from t=1t=1, and multiply by β\beta until f(x−t∇f(x))≤f(x)−ct∥∇f(x)∥22.f(x-t\nabla f(x))\le f(x)-ct\|\nabla f(x)\|_2^2. Show that 0<t≤2(1−c)/L0<t\le 2(1-c)/L suffices, and bound the number of backtracks.

Solution to exercise 2

The smoothness bound gives decrease at least t(1−Lt/2)∥∇f(x)∥22t(1-Lt/2)\|\nabla f(x)\|_2^2. The sufficient inequality 1−Lt/2≥c1-Lt/2\ge c is equivalent to t≤2(1−c)/Lt\le 2(1-c)/L. Writing t‾=2(1−c)/L\bar t=2(1-c)/L, the number of reductions is at most max⁡{0,⌈log⁡(t‾)/log⁡(β)⌉}\max\{0,\lceil \log(\bar t)/\log(\beta)\rceil\}, the first nonnegative index with βk≤t‾\beta^k\le\bar t.

3. Exact line search on a quadratic

For f(x)=12x⊺Ax−b⊺xf(x)=\tfrac12x^\intercal Ax-b^\intercal x with A≽0A\succeq0, let g=Ax−b≠0g=Ax-b\ne0 and p=−gp=-g. Assuming g⊺Ag>0g^\intercal Ag>0, find the minimizer of f(x+tp)f(x+tp) over t≥0t\ge0.

Solution to exercise 3

The line objective equals f(x)−tg⊺g+12t2g⊺Agf(x)-t\,g^\intercal g+\tfrac12t^2g^\intercal Ag. It is a strictly convex quadratic minimized at t⋆=(g⊺g)/(g⊺Ag)>0t^\star=(g^\intercal g)/(g^\intercal Ag)>0.

4. Gradient descent from an upper model

Assume ff is LL-smooth with L>0L>0. Minimize the upper model my(z)=f(y)+∇f(y)⊺(z−y)+L2∥z−y∥22m_y(z)=f(y)+\nabla f(y)^\intercal(z-y)+\tfrac L2\|z-y\|_2^2 in zz. How does the minimizer give the gradient step with step size 1/L1/L?

Solution to exercise 4

The model gradient is ∇f(y)+L(z−y)\nabla f(y)+L(z-y). Its unique zero is z⋆=y−∇f(y)/Lz^\star=y-\nabla f(y)/L, the gradient step of length 1/L1/L. Since my(y)=f(y)m_y(y)=f(y) and mym_y majorizes ff, minimizing it controls the actual objective.

5. Gradient and curvature of squared error

For f(x)=∥Ax−b∥22f(x)=\|Ax-b\|_2^2, compute its gradient and Hessian. Prove smoothness with L=2λmax(A⊺A)L=2\lambda_{\max}(A^\intercal A), and give the condition for strong convexity on all of ℝn\mathbb R^n.

Solution to exercise 5

The derivatives are ∇f(x)=2A⊺(Ax−b)\nabla f(x)=2A^\intercal(Ax-b) and ∇2f(x)=2A⊺A\nabla^2 f(x)=2A^\intercal A. The operator norm of the Hessian bounds the Lipschitz constant of the gradient. Strong convexity holds exactly when A⊺A≻0A^\intercal A\succ0, equivalently when AA has full column rank. Its strong-convexity constant is then 2λmin(A⊺A)2\lambda_{\min}(A^\intercal A).

6. Gradient smoothness of logistic loss

Let f(x)=∑i=1mlog⁡(1+ebiai⊺x)f(x)=\sum_{i=1}^m\log(1+e^{b_i a_i^\intercal x}), where bi∈{−1,1}b_i\in\{-1,1\} and row ii of AA is ai⊺a_i^\intercal. Write σi=(1+e−biai⊺x)−1\sigma_i=(1+e^{-b_i a_i^\intercal x})^{-1}.

  1. Show that ∇2f(x)=∑iσi(1−σi)aiai⊺\nabla^2 f(x)=\sum_i \sigma_i(1-\sigma_i)a_i a_i^\intercal.
  2. Bound the gradient Lipschitz constant and give a sufficient condition for strong convexity on a compact convex domain.
Solution to exercise 6

Differentiate the iith term to get biσiaib_i\sigma_i a_i. Its Hessian is bi2σi(1−σi)aiai⊺b_i^2\sigma_i(1-\sigma_i)a_i a_i^\intercal, and bi2=1b_i^2=1. Since 0≤σi(1−σi)≤1/40\le\sigma_i(1-\sigma_i)\le1/4, the Hessian is bounded above by A⊺A/4A^\intercal A/4, so one may take L=λmax(A⊺A)/4L=\lambda_{\max}(A^\intercal A)/4. On any compact domain these positive continuous weights are bounded below by a common positive constant. If AA has full column rank, the Hessian is then uniformly positive definite, giving strong convexity there.

7. Exact rate on a scalar-curvature quadratic

For f(x)=12∥x∥22f(x)=\tfrac12\|x\|_2^2, gradient descent gives xk+1=(1−t)xkx_{k+1}=(1-t)x_k. For which t>0t>0 do the iterates converge to the minimizer from every starting point? What is the rate?

Solution to exercise 7

Since xk=(1−t)kx0x_k=(1-t)^kx_0, convergence for every start holds when |1−t|<1|1-t|<1, or 0<t<20<t<2. The distance contracts by |1−t||1-t| and the objective by (1−t)2(1-t)^2 per step. At t=1t=1 there is one-step convergence. For a nonzero start t=2t=2 gives an alternating sequence and t>2t>2 gives divergence.

8. The steepest direction

For differentiable f:ℝn→ℝf:\mathbb R^n\to\mathbb R, explain why the negative gradient gives the direction of steepest decrease at xx.

Solution to exercise 8

Among unit directions dd, the directional derivative is ∇f(x)⊺d\nabla f(x)^\intercal d. Cauchy–Schwarz bounds it below by −∥∇f(x)∥2-\|\nabla f(x)\|_2, attained by d=−∇f(x)/∥∇f(x)∥2d=-\nabla f(x)/\|\nabla f(x)\|_2 when the gradient is nonzero. If the gradient is zero, all first-order directional derivatives vanish.

9. The units of a gradient step

If xx is a position in meters and f(x)f(x) is energy in joules, what are the units of ∇f(x)\nabla f(x) and the step size tt in x+=x−t∇f(x)x^+=x-t\nabla f(x)? What do the units suggest about how problem scaling affects step-size choice?

Solution to exercise 9

Each partial derivative is energy change per displacement, in joules per meter. For t∇f(x)t\nabla f(x) to be a displacement, tt has units square meters per joule. Rescaling the energy or position coordinates changes gradient magnitudes and therefore the numerical step size needed for a similar move.

10. Independent motion in eigendirections

Let f(x)=12x⊺Axf(x)=\tfrac12x^\intercal Ax with A≽0A\succeq0. Show that gradient descent updates each eigendirection independently. If the spectrum lies in [μ,L][\mu,L], explain how the spectrum determines the convergence rate.

Solution to exercise 10

Along a unit eigenvector of eigenvalue λ\lambda, the coefficient is multiplied by 1−tλ1-t\lambda. The distance contraction factor for μ>0\mu>0 is at most max⁡{|1−tμ|,|1−tL|}\max\{|1-t\mu|,|1-tL|\}, and the objective contraction factor is at most its square. At t=1/Lt=1/L the distance bound is 1−μ/L1-\mu/L. If μ=0\mu=0, null-space components stay fixed. When 0<t<2/L0<t<2/L, the positive-curvature components decay, so the iterates approach a minimizer.

11. Decrease from minimizing the model

Derive the gradient update by minimizing the smoothness upper bound f(y)≤f(x)+∇f(x)⊺(y−x)+L2∥y−x∥22.f(y)\le f(x)+\nabla f(x)^\intercal(y-x)+\tfrac L2\|y-x\|_2^2. What is minimized at each step, and why does 0<t≤1/L0<t\le1/L give descent?

Solution to exercise 11

Minimizing the right-hand quadratic gives y=x−∇f(x)/Ly=x-\nabla f(x)/L. The same upper-bound argument applies for a smaller positive step, because mx(x−tg)−mx(x)=−t(1−Lt/2)∥g∥22m_x(x-tg)-m_x(x)=-t(1-Lt/2)\|g\|_2^2. For 0<t≤1/L0<t\le1/L the modeled change is negative when g≠0g\ne0, and ff lies below this model.

12. Oscillation during training

While minimizing a smooth loss with gradient descent, you see the objective decrease for a few steps and then rise. What might the oscillation suggest about the step size? How could a smoothness estimate or the Armijo rule help?

Solution to exercise 12

The current step may be too large for the curvature the iterates encounter. With a valid Lipschitz constant LL for the gradient, a full-gradient step t≤1/Lt\le1/L guarantees decrease away from a stationary point. Without such a constant, backtrack until the trial step gives the Armijo decrease. The oscillation is a reason to check the step size and whether the gradients are exact.