Optimization

Gradient Descent — exercises

Pick a stable step size from the Hessian eigenvalues, run the iteration x ← x − η ∇f(x), and recognize the failure modes (divergence above 2/L, slow progress on ill-conditioned problems, traps on non-convex landscapes).

1 worked example · 7 practice problems · 2 check problems

Worked example: gradient descent on an ill-conditioned bowl

Problem. Minimize by gradient descent. Start at with learning rate . Compute the first three iterates by hand. Explain why converges fast and converges slowly. State the largest learning rate that doesn't diverge.

Diagnosis. Quadratic minimization is the canonical setting for analyzing gradient descent. The Hessian is constant (no curvature changes during the descent), and the convergence is governed entirely by its eigenvalues. With , the Hessian is — eigenvalues 2 and 20, condition number 10. Per-step contraction in direction is .

Predict before reading on: before doing the arithmetic: predict the contraction factor for each direction at . Which direction shrinks faster?

Iterations. Per-step contractions: for , for . Both contract — neither diverges — but contracts almost 5× faster.

Pattern. and . After steps, (long since converged) but (still 1.5% off). The well-conditioned direction is done; the ill-conditioned direction crawls. Total iterations to drive down to are .

Predict before reading on: we have . The stability bound is . Predict the failure mode at exactly, and at .

Failure modes. Stability bound: . At , the -direction has contraction factor — pure oscillation, no convergence. At , the -direction grows by factor 1.2 per step — divergent. The -direction is fine in all three cases; the worst-conditioned direction sets the stability boundary.

Verification.

import numpy as np
x = np.array([1.0, 1.0])
H = np.diag([2., 20.])           # Hessian
for k in range(4):
    print(f"iter {k}: x = {x}")
    x = x - 0.04 * (H @ x)
# iter 0: [1. 1.]
# iter 1: [0.92 0.2]
# iter 2: [0.8464 0.04]
# iter 3: [0.778688 0.008]

Articulate: state in one sentence the trade-off between stability (large diverges) and progress (small crawls). What does the Hessian condition number represent in this trade-off?


Practice problems

Seven problems, seven surfaces. Some are pure mechanics (run a few steps by hand), some test the spectral analysis (compute optimal ), some explore failure modes (non-smooth, non-convex), and the last two derive extensions of the basic algorithm.

P.1 1D quadratic minimization

Minimize by gradient descent starting at .

(a) What's the Hessian? What's the maximum stable learning rate?

(b) What learning rate converges to the minimum in one step?

(c) Run two iterations at the one-step-optimal and confirm.

Find the analogue: same eigenvalue analysis as the worked example, simpler because is 1D. With one eigenvalue, there's no condition-number penalty — you can hit the minimum exactly with the right step size.

show answer

(a) , so and stability requires .

(b) Contraction factor is , which equals zero at . One-step convergence at .

(c) . Already at the minimum after one step. — stays there. ✓

The general lesson: for a quadratic with a single eigenvalue , the optimal is . For multiple eigenvalues, you can't satisfy "one-step convergence" in every direction simultaneously, and the best you can do is compromise.

P.2 2D ill-conditioned, optimal lr from spectral analysis

A quadratic has Hessian .

(a) Compute the maximum stable constant learning rate.

(b) Compute the optimal constant learning rate where are the smallest and largest eigenvalues.

(c) State the resulting per-step contraction factor in the worst direction. How many iterations are needed to reduce the worst-direction error by a factor of ?

Find the analogue: the worked example used a specific and observed two different contraction rates. This problem picks to balance the contraction across all eigenvalues. Same spectral analysis, the question is now optimization rather than evaluation.

show answer

(a) Stability bound: .

(b) .

(c) Per-step contraction at : at the small eigenvalue, and at the large eigenvalue — equal by design. (This is the whole point of — it balances the two extreme contractions.)

This rate is where . For a target reduction of , the number of iterations is . Compare to at the worked example's sub-optimal , where the worst contraction was 0.92. The optimal step gives an order of magnitude fewer iterations.

P.3 non-smooth objective, oscillation around the minimum

Apply gradient descent to starting at with fixed . The subgradient is for .

(a) Run the iteration. What happens for ?

(b) Describe the long-run behavior in one sentence.

(c) Propose a modification that does converge to the minimum.

Find the analogue: the worked example had chosen to be smaller than the stability bound. Here there's no smooth Hessian to set the bound — the gradient is a step function. What goes wrong?

show answer

(a) Iteration: . Once we cross zero, the gradient direction flips and we bounce back. The iterate enters a stable oscillation between and .

(b) Fixed- gradient descent on a non-smooth objective oscillates around the minimum with amplitude rather than converging. The minimum value is never reached — only points where .

(c) Fix: use a diminishing step size . The classical choice is with , which is exactly the Robbins-Monro condition for stochastic-approximation convergence. The iterates then converge to the minimum, though slowly. An alternative is the proximal operator , which gives exact convergence for non-smooth convex at any fixed . For this is the soft-thresholding operator and underlies modern sparse-recovery algorithms (ISTA, FISTA).

P.4 non-convex landscape, two basins from same lr

Consider (the non-convex example from the concept page). Run gradient descent with from two starting points: and .

(a) Locate the stationary points by hand (roots of ).

(b) Predict which stationary point each trajectory will reach. Explain.

(c) State the function values at the two minima. Which is the global minimum?

Find the analogue: the worked example was convex — gradient descent finds the unique minimum from any start. This problem is non-convex. The algorithm is the same; the answer depends on initialization.

show answer

(a) . Numerical roots: (local min), (local max), (global min).

(b) From : , so the gradient pushes to the left, away from the local max at +0.126. Trajectory falls into the left basin, converging to .

From : , gradient pushes to the right, away from the local max. Trajectory falls into the right basin, converging to .

(c) , . The local minimum at is actually the global minimum — surprisingly, the deeper basin is the one further from zero. (This is what the concept-page figure shows.) The starting point determines which basin you find; gradient descent has no way to know there's a deeper one elsewhere.

P.5 heavy-ball momentum from a physics analogy

Polyak's heavy-ball method adds momentum to gradient descent:

Derive this from a physical analogy. Specifically: a ball of mass at position in a potential , subject to a friction force , satisfies . Discretize this ODE with explicit Euler at step size and show it produces the heavy-ball update. Identify and in terms of .

Find the analogue: the basic GD step is the over-damped limit (no inertia: , just ). Adding back mass gives a ball that rolls past local features rather than getting stuck on them. This is the same "physics analogy" intuition used to motivate momentum in deep learning.

show answer

Explicit Euler discretization with step : and .

Substitute into the ODE :

Solve for :

Divide through by . After algebra:

Reading off: .

Physical reading: ("momentum coefficient") is the relative weight of mass to (mass + friction step) — heavier ball means more momentum carry-over. ("learning rate") inherits an from the second-derivative term, hence the quadratic scaling of step size with time step. Setting gives and vanilla gradient descent at step — over-damped limit.

This is the same kind of derivation that motivates Nesterov's accelerated gradient (a more careful discretization that achieves the optimal rate for strongly convex problems, faster than heavy-ball's ). Both are second-order ODE discretizations dressed up as first-order updates.

P.6 diagonal preconditioning to fix conditioning

Take the worked example's . Find a diagonal preconditioner matrix such that the transformed problem on has a perfectly-conditioned Hessian (all eigenvalues equal).

Write out the preconditioned iteration for this . What's its convergence rate?

Find the analogue: ill-conditioning is what limited the worked example to while crawled. Preconditioning rescales the axes so the Hessian becomes the identity, eliminating the conditioning problem entirely.

show answer

Choose so that — actually the cleanest statement is: substitute :

With , .

Eigenvalues all 1, condition number 1. Optimal gives one-step convergence (in space). The iteration in space looks like vanilla GD on a unit-Hessian problem — boring, which is the point.

In space, the preconditioned step is , which is one step of Newton's method. So preconditioning is Newton's method in disguise when you precondition with . Practical preconditioners are cheap approximations to — diagonal preconditioning (Jacobi), incomplete Cholesky, or learned preconditioners — that get most of the benefit without the cost of inverting . Modern optimizers (Adam, RMSprop) are exactly diagonal preconditioners that estimate from running second-moment estimates of the gradient.

P.7 linear systems via Richardson iteration

Show that solving a symmetric positive-definite linear system is equivalent to minimizing the quadratic .

(a) Compute the gradient and show that the unique minimizer satisfies .

(b) Write out gradient descent on this quadratic. It produces a famous iterative linear-system solver — name it.

(c) State the stable learning-rate range in terms of the eigenvalues of .

Find the analogue: same spectral-analysis machinery as the worked example, applied to a quadratic that has a linear system at its critical point rather than a "pure" minimum. Solving and minimizing are the same problem.

show answer

(a) (using symmetry of ). Setting this to zero gives , and the Hessian is positive definite by assumption, so the critical point is the unique global minimum.

(b) Gradient descent: . This is the Richardson iteration for . It's one of the oldest iterative linear solvers; the modern descendants are Jacobi, Gauss-Seidel, and (most importantly) the conjugate gradient method, which is gradient descent's smarter cousin specifically tuned for SPD linear systems.

(c) With eigenvalues of , stability requires , i.e., . Optimal constant gives convergence rate with — exactly the same as for general quadratic minimization. Conjugate gradient improves this to per step, which is why it's the algorithm of choice for large sparse SPD systems in scientific computing.


Check problems

Two problems that don't pattern-match to the practice set. The first derives a result the page asserts but doesn't prove; the second tests when the basic algorithm "succeeds."

Check 1 derivation

For the quadratic with symmetric positive-definite having eigenvalues , derive the optimal constant learning rate for gradient descent.

(a) Show that the per-iteration error-reduction operator is .

(b) Derive as the minimizer of over .

(c) Compute the resulting worst-direction contraction factor and show it equals where .

show solution sketch

(a) Let with . The GD update is . Substituting and using : . So . ✓

(b) Decompose in the eigenbasis of : with . Then , so each component contracts by . The worst-case contraction (over all components) is with .

This function of is piecewise linear. For , all are positive, max is at : gives , decreasing in . For , all are negative, max is at : gives , increasing in . In between, the max is , minimized where the two are equal:

(c) At : contraction

This is the "textbook" worst-case rate for constant-step gradient descent on a strongly convex quadratic. It depends only on the condition number , not on the dimension of the problem. Conjugate gradient achieves ; Nesterov's accelerated gradient achieves the same; the gap between them and plain GD is what makes the latter unsuitable for large ill-conditioned problems in serious numerical work.

Check 2 articulation

"Gradient descent converged" and "we found the global minimum" are different claims. In 150–250 words, explain the distinction using the non-convex example from P.4. Your answer should:

  • Define what "converged" means operationally (in terms of the gradient norm and/or successive iterates).
  • Explain what gradient descent can guarantee under mild conditions.
  • Explain what it cannot guarantee, and why this is a property of the loss surface rather than of the algorithm.
  • Name two practical strategies that partially address the gap (without claiming they solve it).
show solution sketch

"Converged" means the iterates have stopped moving meaningfully — operationally, the gradient norm has dropped below a tolerance, or is below a tolerance. Gradient descent on a smooth function with a stable step size will reach this state. What it produces is a stationary point: a place where .

What gradient descent guarantees (under mild conditions: smooth , bounded below, ): a sequence whose gradient norm goes to zero, with limit points that are stationary. For convex , every stationary point is a global minimum, so convergence implies optimality.

What it can't guarantee: in P.4's , there are three stationary points — a local max at , a local min at , and a global min at . Starting at drives the iterate into the local-min basin. The algorithm converges; the gradient at the limit is zero; the loss is locally minimized — and yet it's not the best basin. This is a property of the loss surface (multiple basins of attraction), not the algorithm. No first-order local-search method, with any step-size schedule, can fix this.

Practical strategies that partially address the gap: (i) multiple random restarts — sample many initial , run GD from each, keep the best result. Costs the single-run cost; helps but no guarantee of finding the global min. (ii) Stochastic noise (SGD or Langevin dynamics) — adding gradient noise lets the iterates jump small barriers and find deeper basins; this is half the reason deep-learning models generalize. Neither strategy provides a worst-case guarantee. Global optimization on non-convex landscapes remains open.