TactivergeLite

Lite / Textbooks / Engineering Design and Optimization / Chapter 8

8. Gradient methods and convexity

Version 1 · Technically checked (automated checks only) · 3 source lessons · Full interactive version

Introduction

Gradient descent is the workhorse of modern optimisation, from tuning controllers to training networks. This chapter studies it closely: how the learning rate decides between creeping, zig-zagging and exploding, why convex problems have a single answer that descent will find, how Newton's method and momentum go faster, and how constraints such as a motor's current limit are handled with penalties or by building them into the problem.

Figure 8.1. Learning rate decides everything (described in words)

Gradient descent on f(x) = 2x² from x = 2 with three step sizes. With η = 0.1 the iterates shrink smoothly towards 0; with η = 0.4 they zig-zag in sign but still shrink; with η = 0.55 they grow to 4.15 after 4 steps. Descent is stable only for η < 0.5.

Explanation

Built from 3 School lessons. Each part is the lesson's own explanation.

8.1 Gradient descent and the learning rate

Blindfolded on a hillside, you can only feel the slope under your feet. How big should each step downhill be?

The update

The gradient ∇f points uphill, steepest. Gradient descent steps the other way: x ← x − η∇f(x). η, the learning rate or step size, scales the step. Repeat until the gradient is (nearly) zero or progress stalls.

Too small, too big, just right

Too small: correct but painfully slow. Too big: overshoot, oscillate, diverge. For a quadratic the boundary is exact: η < 2/L. In practice, start small, increase until the loss stops falling smoothly, then back off; or use a line search that picks η each step.

Narrow valleys

When curvature differs a lot between directions (an ill-conditioned problem), the steep direction limits η and the shallow direction then moves slowly: the zig-zag path in the explorer. Rescaling variables (preconditioning), momentum, or second-order methods fix this.

Derivation: When does gradient descent converge on a quadratic?
  1. Take f(x) = ½·a·x² with a > 0. Then f'(x) = a·x and the update is x_{k+1} = x_k − η·a·x_k = (1 − ηa)·x_k.

  2. So x_k = (1 − ηa)^k · x₀: a geometric sequence. It shrinks to 0 if and only if |1 − ηa| < 1, i.e. 0 < η < 2/a.

  3. Fastest: η = 1/a gives 1 − ηa = 0: one step. For 1/a < η < 2/a it overshoots and oscillates but still converges.

  4. In two dimensions, f = ½(a₁x² + a₂y²) gives two independent factors (1 − ηa₁) and (1 − ηa₂). Stability needs η < 2/max(aᵢ).

  5. With η limited by the steep direction, the shallow direction shrinks by (1 − a_min/a_max) per step at best. The condition number κ = a_max/a_min sets the pace: κ = 100 means about 100 steps per factor e.

  6. For a general smooth f, L (the largest curvature, the Lipschitz constant of the gradient) plays the role of a_max: η < 2/L.

Common mix-ups

Open the Lite lesson: Gradient descent and the learning rate

8.2 Convexity and local minima

Two engineers run the same optimiser on the same design problem and get different answers. Who is wrong?

Convex functions

f is convex if the straight line between any two points on its graph lies on or above the graph: f(θx + (1 − θ)y) ≤ θf(x) + (1 − θ)f(y). For twice-differentiable f this means f'' ≥ 0 (in 1-D) or a positive semi-definite Hessian. x², |x|, eˣ and ½xᵀAx with A positive semi-definite are convex.

Why convexity is precious

For a convex function on a convex set, every local minimum is a global minimum, and gradient methods with a sensible step converge to it from any start. You can also certify optimality: a zero gradient proves you are done.

Living with non-convexity

Non-convex functions can have many local minima, saddle points and flat regions. Practical responses: multiple random starts (report the spread of results), good initial guesses from physics, convex relaxations that give bounds, and global methods (simulated annealing, genetic algorithms) for small problems. Never present one run of a non-convex optimiser as 'the optimum'.

Common mix-ups

Open the Lite lesson: Convexity and local minima

8.3 Newton's method, momentum and constraints

Gradient descent takes 200 steps down a narrow valley. Newton's method takes one. What is it using that gradient descent ignores?

Second-order methods

Newton's method uses curvature to scale the step in every direction, so ill-conditioning disappears: the narrow valley looks round to it. Quasi-Newton methods (BFGS, L-BFGS) build an approximation of H⁻¹ from gradients, keeping most of the benefit at a fraction of the cost, and are the default for medium-sized smooth problems.

Momentum

Momentum keeps a running velocity: v ← βv − η∇f, x ← x + v. Along a consistent shallow direction the steps add up; across a steep gully they cancel. It is cheap, first-order, and widely used in training neural networks.

Constraints by penalty

To minimise f subject to g(x) ≤ 0, minimise f(x) + μ·max(0, g(x))². Small μ: the constraint is violated a little. Large μ: closer to feasible, but the problem becomes ill-conditioned and slow. Increase μ gradually, or use exact methods (Lagrange multipliers, projection, interior-point solvers) when feasibility is non-negotiable, such as a safety limit.

Derivation: Newton's step from a quadratic model
  1. Near x_k, approximate f by its second-order Taylor expansion: f(x_k + d) ≈ f(x_k) + f'(x_k)·d + ½f''(x_k)·d².

  2. Minimise the model over d: derivative f'(x_k) + f''(x_k)·d = 0, so d = −f'(x_k)/f''(x_k).

  3. Newton update: x_{k+1} = x_k − f'(x_k)/f''(x_k). In n dimensions: x ← x − H⁻¹∇f, with H the Hessian.

  4. It is Newton–Raphson root-finding applied to f' = 0, which you met for solving equations.

  5. Cost: forming and solving with H is O(n²) memory and O(n³) time per step, versus O(n) for a gradient step. Trade: few expensive steps versus many cheap ones.

  6. Caution: if f'' ≤ 0 the step can go uphill; practical methods add a line search or modify H.

Common mix-ups

Open the Lite lesson: Newton's method, momentum and constraints

Worked examples

Gradient descent and the learning rate: example 1

f(x) = 2(x − 3)², x₀ = 7, η = 0.1. Find x₁ and x₂.

Solution

f'(x) = 4(x − 3). x₁ = 7 − 0.1×16 = 5.4. x₂ = 5.4 − 0.1×9.6 = 4.44. Each step multiplies the distance to 3 by 1 − 0.4 = 0.6: 4 → 2.4 → 1.44 ✓.

Convexity and local minima: example 1

Is f(x) = x⁴ − 2x² convex?

Solution

f''(x) = 12x² − 4, negative for |x| < 0.577. Not convex. It has minima at x = ±1 and a local maximum at x = 0, just like the double well.

Newton's method, momentum and constraints: example 1

Newton's method on f(x) = x⁴ from x₀ = 1. Find x₁ and x₂.

Solution

f' = 4x³, f'' = 12x². Step: x − 4x³/12x² = x − x/3 = (2/3)x. x₁ = 0.667, x₂ = 0.444. Only linear here, because f'' = 0 at the minimum: Newton's quadratic speed needs f'' > 0 there.

Interactive figures, in words

Figure 8.2 from Gradient descent and the learning rate

On the round bowl, find the learning rate that reaches the centre in one step. Switch to the narrow valley with b = 4: raise η until it diverges, and note the value. Then set b = 10 and see why a safe η crawls along the valley floor.

The explorer draws elliptical contours and the path of each gradient step. On f = ½(x² + 4y²) with η = 0.3, the y-coordinate shrinks by |1 − 1.2| = 0.2 per step and x by 0.7; at η = 0.6 the y-factor is |1 − 2.4| = 1.4 and the path diverges.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. f(x, y) = ½(3x² + 12y²). What is the largest learning rate for which gradient descent converges? (Strict upper bound.)
    Answer it in “Gradient descent and the learning rate”
  2. Gradient descent zig-zags slowly down a long, narrow valley. The most direct cure is…
    Answer it in “Gradient descent and the learning rate”
  3. For f(x) = ½·5x², which learning rate reaches the minimum in exactly one step from any start?
    Answer it in “Gradient descent and the learning rate”
  4. Which function is convex on all real x?
    Answer it in “Convexity and local minima”
  5. Your optimiser returns a point with zero gradient on a convex objective. What can you conclude?
    Answer it in “Convexity and local minima”
  6. You tune a robot arm design with a non-convex objective. What is the honest report?
    Answer it in “Convexity and local minima”
  7. For a problem with a million variables, why is plain Newton's method rarely used?
    Answer it in “Newton's method, momentum and constraints”
  8. A motor current must never exceed its rating. Which constraint method suits that best?
    Answer it in “Newton's method, momentum and constraints”

Engineering applications

Controller auto-tuning

Auto-tuners adjust controller gains to reduce a cost such as overshoot plus settling time. The cost surface is rarely convex, so good tuners start from several points and report the spread.

Trajectory optimisation

Robot arms plan smooth paths by minimising effort subject to joint limits. Limits that must never be broken are built in as hard constraints, not left to a penalty that might be outweighed.

Watch (optional)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Derivative (rate of change)
The derivative of a quantity is its instantaneous rate of change: the gradient of its graph at a point. Field Guide
Efficiency
Efficiency is the fraction of input energy or power that comes out as useful output. The rest becomes heat, sound or other losses. Field Guide
PID controller
A PID controller adds proportional, integral and derivative actions: present error, accumulated past error and predicted future error. Field Guide

Project: Tune a design by descent

Choose a design with two continuous variables and a cost you can compute, such as a stand's mass with a tipping penalty. Implement gradient descent, try three learning rates and several starting points, and report the best design, whether the problem appears convex, and how sure you are.

Deliverables

Write it up on paper or in your own notes. Lite never stores what you write.

References

← 7. Linear programming and searchContents →