The update contract
Compute a gradient from the current objective, transform it with the optimizer state, and apply a step whose scale preserves useful progress.
Direction is local. Learning is a path.Choose a surface and optimizer, then change learning rate, momentum, stochastic noise, and clipping. The point, gradient arrow, velocity, trail, loss, and convergence state all come from the analytic update shown below.
Training a model means choosing parameters that reduce an objective. Gradient descent does not inspect every possible setting. It evaluates the derivative at the current point, then moves opposite the local gradient. Repeating that simple operation produces a path through parameter space.
The simulator uses two visible parameters, x and z, so the objective can be drawn as terrain. The vertical coordinate is a compressed display of the analytic loss; the optimizer still receives the exact derivative of the original function. That distinction matters because visualization transforms should never silently change the algorithm being taught.
On the quadratic bowl, every gradient points toward one global minimum. This is the clean case: a modest learning rate converges, a tiny rate crawls, and an excessive rate overshoots. Momentum accumulates a velocity, accelerating along consistent slopes while damping some zig-zag motion.
The Rosenbrock function introduces a curved ravine. The shortest local direction points toward a valley wall, not straight along the valley toward the minimum. A step size that works on the bowl can oscillate or diverge here. The saddle has positive curvature in one direction and negative curvature in another, exposing why nearly flat gradients can delay escape. Himmelblau's function has multiple minima, so starting position influences the solution reached.
Noise is added deterministically from a seeded pseudo-random sequence, making runs reproducible. It approximates stochastic gradient variation rather than a particular mini-batch. Gradient clipping limits the update direction's norm before the optimizer uses it; clipping can prevent an explosion, but it also changes the effective step and does not repair a fundamentally poor objective or schedule.
Compute a gradient from the current objective, transform it with the optimizer state, and apply a step whose scale preserves useful progress.
Direction is local. Learning is a path.The gradient supplies direction and scale; the learning rate multiplies it. Too small wastes computation. Too large can cross the valley repeatedly or leave the stable region.
A velocity combines past updates with the current gradient. Consistent directions accumulate while alternating components can cancel.
Steep directions impose smaller stable steps than flat directions. Anisotropic curvature creates zig-zag trajectories and motivates preconditioning.
Track gradient norm, update norm, parameter scale, validation behavior, and numerical health. A falling training loss can still accompany overfitting.
A forward pass produces a scalar loss for the current parameters and data. In the lab, the selected analytic function returns that scalar directly. In a neural network, the loss depends on many layered computations and usually a mini-batch.
Backpropagation applies the chain rule efficiently through the computation graph. The resulting gradient contains one partial derivative per parameter. It describes the fastest local increase, so descent negates it.
An optimizer may add momentum, normalize coordinates, estimate moments, apply weight decay, clip norms, or follow a schedule. These transformations change the trajectory without changing the current loss surface.
The new parameter point changes the next loss and gradient. Stability is therefore dynamical: a sequence can approach, oscillate around, pass through, or escape a region depending on geometry and optimizer state.
Convergence in this teaching lab means a small gradient norm near a finite point. Production training also needs held-out metrics, reproducibility, checkpointing, numerical monitoring, and task-specific stopping criteria.
SGD applies the current gradient with no velocity memory. Mini-batch noise can help exploration, but the path may zig-zag across steep ravines and progress slowly along shallow directions.
CurrentClassical momentum carries a decaying velocity. It can accelerate through consistent gradients and reduce alternating motion, but excessive beta can produce long overshoots after the local geometry changes.
HistoryNesterov's method evaluates the gradient near the anticipated next position. This look-ahead can correct velocity earlier, though practical behavior still depends on implementation, schedules, and the objective.
Look aheadMethods such as Adam estimate coordinate-wise moments and rescale updates. They are powerful defaults, but momentum, epsilon, bias correction, weight decay, and learning-rate schedules remain meaningful choices.
ScaleOn a curved ravine, a step that looks reasonable in one direction can be unstable in the steep direction. The point crosses the valley, receives a gradient pointing back, and oscillates with growing amplitude. Clipping may contain the largest update, but lowering the learning rate addresses the underlying stability problem.
No. The lab optimizes two parameters on analytic teaching functions so the exact loss and gradient are transparent. Neural networks have far more parameters, stochastic mini-batches, layered computation graphs, and task-specific objectives. The geometric ideas transfer, but the scene is not a performance benchmark.
Rosenbrock and Himmelblau losses vary by orders of magnitude. The scene uses a logarithmic height transform so both valleys and peaks fit on screen. The optimizer receives the uncompressed analytic loss and gradient, preserving the update being taught.
No. Momentum can accelerate along consistent directions and damp zig-zag motion, but an unsuitable learning rate or beta can increase overshoot. It also carries stale direction when the local geometry changes.
A small gradient can occur near a minimum, maximum, saddle, plateau, or saturated region. Curvature, loss history, validation behavior, and perturbation tests help distinguish these cases.
No. Clipping limits extreme gradients and can protect recurrent or mixed-precision training, but persistent clipping changes most updates and may hide instability. Measure the clipped fraction and address the source.
A mini-batch gradient estimates the full-data gradient from a sample. Its variance depends on the data, batch size, sampling, and parameter state. That noise can disrupt convergence or help escape shallow structures.
Usually it is operational rather than proof of a global optimum: the objective and task metrics stop improving meaningfully, gradients and updates are controlled, and the validation behavior meets a stopping rule.
Optimization is a controlled dynamical system. Stable training comes from matching update rules, schedules, numerical safeguards, and measurements to the geometry and evidence of the run.
Explore agents that build and verify