Optimization Landscape Explorer
Run the Optimization Landscape Explorer MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
The blue curve is a cost function \(J(x)\) of a single parameter, and the red ball is the optimizer. Each step moves the ball downhill by the learning rate times the slope, \(x \leftarrow x - \eta J'(x)\), and it stops where the slope is nearly zero. Triangles mark every minimum with its cost: green for the global minimum (the lowest point of the whole curve) and orange for each local minimum (lower than its neighbors, but not the lowest).
Four landscapes are available:
- Convex bowl, \(J = 0.5x^2\). There is one valley, so every start reaches the global minimum.
- Two valleys, \(J = x^4 - 3x^2 + 0.5x\), the function plotted in the chapter. The global minimum is at \(x \approx -1.26\) (\(J \approx -2.87\)) and the local minimum at \(x \approx 1.18\) (\(J \approx -1.65\)).
- Many valleys, \(J = 0.2x^2 - 0.7\cos(3(x - 0.4))\). It has five minima; the global one is at \(x \approx 0.38\).
- Plateau, \(J = x^4/4 - 2x^3/3\). It has one minimum at \(x = 2\) and a flat spot at \(x = 0\), where the slope is zero but the curve goes on down afterwards. On a curve this plays the part that a saddle point plays on a surface.
With Add momentum checked the ball keeps 90% of its previous move: \(v \leftarrow 0.9v - \eta J'(x)\), then \(x \leftarrow x + v\). That lets it coast through shallow dips and across flat ground. It is not a guarantee: many starts still end in a local minimum.
The two strips under the plot record where each finished run started, green if it reached the global minimum and orange if it did not, with one strip for plain descent and one for momentum. The result panel keeps the count.
Not included: the learning rate and noise sliders from the original specification. Each landscape uses one fixed learning rate, shown under the title.
How to Use
- Read the prompt, predict where the ball will stop, then press Start. Use Step instead to advance one update at a time.
- Click the curve to choose a new starting point and run again. Repeat until the plain strip shows which starts reach the global minimum.
- Check Add momentum and press Start to repeat the same start with momentum. Compare the two strips.
- Choose Many valleys and look for starts that momentum rescues and starts that it does not.
- Choose Plateau, start on the left slope, and compare plain descent with momentum. Reset clears the strips.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Grade Level
High School (11-12) and College Freshman
Duration
10-15 minutes
Prerequisites
Gradient descent, the learning rate, and reading the graph of a function.
Bloom's Taxonomy Level
Analyze (L4)
Learning Objective
Students will be able to distinguish local minima from the global minimum and compare how the starting point and momentum affect which minimum gradient descent finds.
Activities
- Predict and run (4 min): On the two valleys landscape students predict the stopping point for three starts of their choice, run each one, and record whether the prediction was right.
- Map the starts (6 min): On the many valleys landscape students run at least eight starts spread across the curve with plain descent, repeat the same starts with momentum, and describe which starts changed outcome.
- Flat is not a minimum (4 min): On the plateau students run plain descent from the left slope and read the slope and the cost above the global minimum where it stalls, then repeat with momentum and explain the difference.
Assessment
Shown a sketch of a cost curve with three valleys and a marked starting point, students say where plain gradient descent will stop, whether that point is a local or the global minimum, and name one strategy from the chapter that could change the outcome.
References
- Wikipedia. Maxima and minima (local and global minima).
- Wikipedia. Stochastic gradient descent (section on momentum).
- Géron, A. Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow. O'Reilly. Chapter 11, Training Deep Neural Networks (momentum optimization).