School/□ Systems Engineer/Week 30
Searching a design landscape: grids, gradients and local minima
Rolling downhill finds a valley fast. But is it the deepest valley?
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
When a cost comes from a simulation, there is no formula to differentiate and no corners to check. You search. How you search decides whether you find a great design in minutes, a mediocre one, or nothing before the deadline.
- ◇ Compare grid search and gradient descent by evaluations needed and reliability.
- ◇ Carry out a gradient-descent step and explain the role of the learning rate.
- ◇ Recognise local minima and use restarts or coarse grids to guard against them.
2.Discover
Gradient descent from x₀ = 1: where does it end? Move x₀ to 5. Now try η = 4 and watch it overshoot. Switch to grid search: what is the smallest k that finds the global valley near 7.4, and how many evaluations does it cost?
Loading the interactive…
Can't use the interactive? Read a description instead
The explorer plots an illustrative cost against one design parameter x from 0 to 10, with a local valley near x = 2.3 (cost about 1.52), a ridge near 3.8, and the deepest valley near 7.4 (cost about 0.61). Gradient descent from x₀ = 1 ends in the shallow valley; from x₀ = 5 it reaches the deep one; with a learning rate above about 3 it overshoots. Grid search with k points evaluates the cost k times and finds the deep valley once the spacing is fine enough.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
The energy cost of a design is f(x) = 2·(x − 2)². Starting from x₀ = 4 with learning rate η = 0.25, take one gradient-descent step x₁ = x₀ − η·f′(x₀). What is x₁? (3 decimal places.)
4.Predict
A grid search uses 20 values per parameter. How many simulations for a design with 4 parameters?
Guess first. Being wrong here is how the surprise works.
5.Understand
Grid search: thorough and expensive
Evaluate the cost on a regular grid and keep the best. It needs no derivatives, handles noisy or discontinuous costs, and with fine enough spacing can't miss a wide valley. But its cost is k^d evaluations, and its resolution is the grid spacing: the true optimum can sit between grid points. Use it for one to three parameters, or as a coarse first look.
Gradient descent: fast and local
Step against the slope: x ← x − η·f′(x). Near a minimum the slope shrinks, so steps shrink. Each step needs the gradient, which you can estimate with finite differences (two evaluations per parameter). It scales to many parameters, but it only ever goes downhill, so it settles in whichever valley it starts in.
The learning rate
η sets the step size. Too small and progress is painfully slow. Too large and the step jumps over the valley floor, bouncing or diverging. For f = a(x − b)², steps converge only if η < 1/a. In practice engineers try a few η values, or shrink η when the cost stops falling.
Guarding against local minima
A local minimum beats its neighbours but not the whole landscape. Defences: a coarse grid to find promising regions, then gradient descent to polish (a hybrid); several random restarts; or global methods (simulated annealing, genetic algorithms) that sometimes accept uphill moves. Always report the method and its limits: 'best found', not 'optimal'.
Explain it another way
Lost in fog on a hillside, you feel which way the ground slopes and step downhill. You'll reach a valley, but maybe not the lowest one in the region.
Gradient descent x_{k+1} = x_k − η∇f(x_k). Converges linearly for smooth, strongly convex f with suitable η; only to a stationary point otherwise. Grid search cost O(k^d); finite-difference gradients cost O(d) per step.
For f(x) = a(x − b)²: x_{k+1} − b = (1 − 2aη)(x_k − b). The error shrinks each step if |1 − 2aη| < 1, i.e. 0 < η < 1/a. At η = 1/(2a) one step lands exactly on the minimum.
Antenna designers often start with a coarse parameter sweep in an electromagnetic simulator, then hand the best few candidates to a local optimiser to fine-tune the geometry.
Worked example 1
f(x) = 2(x − 3)², x₀ = 7, η = 0.1. Take two steps.
f′(x) = 4(x − 3). Step 1: f′(7) = 16, x₁ = 7 − 1.6 = 5.4. Step 2: f′(5.4) = 9.6, x₂ = 5.4 − 0.96 = 4.44. The error shrinks by 1 − 2·2·0.1 = 0.6 each step.
Common mix-ups
- Gradient descent finds the best design.
✓ It finds a nearby stationary point, usually a local minimum. Restarts or global search are needed to be confident. - A finer grid is always worth it.
✓ Its cost grows as k^d; for more than a few parameters, a fine grid is unaffordable.
6.Watch
→ Watch the picture of a ball rolling on a cost surface; ignore the neural-network details and focus on what the gradient tells you.
The clearest picture of rolling downhill on a cost surface, and of why a step can land you in a local valley.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
You grid-search a design with 4 parameters, trying 5 values of each. One simulation takes 0.01 s. How long does the full grid take, in seconds?
Practice 3
Gradient descent's cost goes up and down and then grows each step. What is the most likely cause?
Practice 4
Gradient descent from three random starts gives costs 1.52, 0.61 and 1.52. What should you report?
Practice 5 · a fresh version every time
RK4 has global error roughly proportional to h^4. With step h = 0.1 s the error is 2.4 mm. Estimate the error with step h = 0.025 s, in mm. (4 significant figures.) The run will take about 4× as long.
8.Apply it
In the greenhouse Build Level 4, treat (setpoint, Kp) as design variables and energy as the cost subject to the comfort constraint. Do a 5 × 5 grid, then refine around the best point by hand-stepping downhill. Report evaluations used and best found.
9.Reflect
Concepts: Optimisation and gradient descent · Constrained optimisation and linear programming · Algorithms, searching and complexity