Machine Learning
Gradient Descent — Optimization (Explained)
Narrow valley: x² + 10y²
Ill-conditioned: plain gradient descent zig-zags; momentum and Adam cope better.
Settings
Start: (-1.80, 1.20)
Results
| Optimiser | Final point | f(x, y) | Distance to nearest minimum | Status |
|---|---|---|---|---|
| Gradient descent | (-0.0000, 0.0000) | 2.286e-9 | 4.78e-5 | Converged |
| Momentum (β = 0.9) | (-0.0067, 0.0016) | 7.153e-5 | 6.92e-3 | Not there yet |
| Adam (β₁ = 0.9, β₂ = 0.999) | (-0.0024, -0.0036) | 1.337e-4 | 4.33e-3 | Not there yet |
How to use this tool
- 1Choose a function; the cross marks its minimum (or minima).
- 2Click the map to choose a starting point (orange).
- 3Pick the optimisers to compare and set the learning rate and number of steps.
- 4Scrub through the steps and compare the loss curves; too large a learning rate makes a method diverge.
Frequently asked questions
Yes. The update rules match PyTorch’s torch.optim (SGD with momentum and Nesterov, RMSprop with ρ = 0.9, Adam with β₁ = 0.9 and β₂ = 0.999), step for step.
If the learning rate is too large for the steepness of the function, each step overshoots the minimum by more than the last. On x² + 10y² this happens when the learning rate exceeds 0.1.
Non-convex functions such as Himmelblau’s have several valleys; gradient methods only follow the slope downhill from where they start.
No. Everything is calculated in your browser; nothing you enter is sent to MuhammadLab.
Related tools
Logistic Regression — Classification Basics
Train logistic regression with gradient descent on 2D data: probability map, threshold, confusion matrix and ROC.
Random Forests — Bagging for Trees
Train a random forest on 2D data and compare it with single trees: decision regions, OOB accuracy and feature importance.
Naive Bayes — Fast Probabilistic Classification
See naive Bayes at work: Gaussian NB on 2D data with class means and spreads, and a spam filter with per-word evidence.