Gradient Descent Complete Guide: Learning Rates, Variants, and Convergence
Understand why gradient descent works, how learning rate and batch size change the path, and when to use SGD, momentum, RMSProp, or Adam on real loss surfaces.
Gradient descent is the workhorse behind much of modern machine learning. Whether a model is fitting a straight line, recognizing an object in an image, or predicting the next token in a sentence, training usually means adjusting parameters so that a numerical measure of error becomes smaller. Gradient descent provides a practical rule for making those adjustments. The rule is simple enough to write in one line, but using it well requires understanding learning rates, noisy gradients, curved loss surfaces, convergence checks, and the behavior of popular optimizers such as momentum, RMSProp, and Adam.
Optimization Is the Engine of Machine Learning
A machine learning model maps inputs to predictions. Its parameters determine exactly how that mapping behaves. A linear regression model has coefficients and an intercept; a neural network may have millions or billions of weights and biases. Training selects parameter values that make the model's predictions useful.
To express "useful" mathematically, we define an objective function. In supervised learning, the objective often contains a loss that compares predictions with known targets. If the model parameters are collected in a vector , a typical empirical objective is
where is the model, is the loss for one example, is a regularization penalty, and controls the strength of regularization. Training asks for parameters that minimize :
This formulation separates the model from the training procedure. The model describes what predictions are possible. The objective says which predictions are preferred. The optimizer searches for suitable parameters.
For a tiny problem, one might solve the minimization analytically or evaluate every possible parameter value. Those approaches do not scale to high-dimensional models. Gradient descent instead uses local information: it asks how the objective changes near the current parameter vector, takes a step in a promising direction, and repeats.
Optimization is therefore not an optional final detail. It is the mechanism through which a model learns. A strong architecture with a poorly configured optimizer may never reach useful parameters, while an appropriate optimizer can make a difficult training problem manageable.
Gradients, Directional Derivatives, and Going Downhill
For a differentiable scalar function , the gradient is the vector of partial derivatives:
Each component measures how sensitive the objective is to a small change in one parameter while the other parameters are held fixed. The complete vector contains more information than a list of independent slopes: it identifies the direction of steepest local increase under the ordinary Euclidean notion of distance.
To see why, choose any unit direction with . The directional derivative is
By the Cauchy-Schwarz inequality, this quantity is at most , and the maximum occurs when points in the gradient direction. The minimum occurs for
Thus the negative gradient is the direction of steepest local decrease. This fact motivates the basic update
where is the learning rate at iteration .
The word "local" matters. A gradient describes the immediate neighborhood, not the entire landscape. A large step can leave that neighborhood and land at a point with a higher loss. A small enough step usually reduces a smooth objective, but an excessively small step wastes computation. Much of practical optimization is about choosing steps that are aggressive enough to make progress without becoming unstable.
The gradient can also be zero at several kinds of points. It is zero at a local minimum, but also at a local maximum or a saddle point. Consequently, a small gradient is evidence that movement has slowed, not proof that the globally best solution has been found.
Batch, Stochastic, and Mini-Batch Gradient Descent
When the objective is an average over training examples, the exact gradient is also an average:
How many terms we use in each update distinguishes the three main gradient descent regimes.
Batch gradient descent
Batch gradient descent computes the gradient using all training examples before every update. Its direction is deterministic for fixed parameters and data. Loss curves are usually smooth, and each update accurately reflects the stated training objective.
The drawback is cost. If the dataset contains ten million examples, every parameter update requires ten million forward and gradient calculations. The method may make only a few updates per hour even though each update is precise. Batch training is most attractive for small datasets, inexpensive models, or optimization problems where very accurate gradients are important.
Stochastic gradient descent
Pure stochastic gradient descent, or SGD, samples one example and updates with
One example's gradient is a noisy estimate of the full gradient. If examples are sampled uniformly, this estimate is unbiased:
Updates are cheap and begin immediately. Noise can help the optimizer leave shallow basins and saddle regions, but it also makes the path fluctuate. Near a minimum, a fixed learning rate may cause SGD to bounce indefinitely rather than settle.
Mini-batch gradient descent
Mini-batch training uses a subset of examples:
This is the standard choice for neural networks. A mini-batch uses vectorized hardware efficiently, averages away some example-level noise, and still allows many updates per pass through the data. Batch sizes such as 32, 64, 128, or 256 are common, but the best value depends on memory, architecture, data diversity, and optimization goals.
Increasing batch size reduces gradient variance, but it does not automatically reduce the number of epochs needed. Very large batches can require learning-rate adjustments and may converge to solutions with different generalization behavior. Compare experiments by both epochs and number of processed examples, and remember that an epoch means one pass through the training set.
Training data should normally be shuffled each epoch. Without shuffling, ordered labels or correlated time blocks can produce strongly biased sequences of updates. Time-series tasks are an exception when preserving temporal order is essential, though even there the sampling design should be deliberate.
The Learning Rate: Step Size Controls the Journey
The learning rate is often the most consequential optimizer setting. It converts a gradient, which gives a direction and sensitivity, into an actual parameter displacement.
When the learning rate is too small
A tiny learning rate produces safe but slow updates. The loss may decrease so gradually that training appears frozen. In an elongated valley, progress along the shallow direction can require an enormous number of iterations. Small steps also consume more computation and may leave a model undertrained when a fixed epoch budget expires.
A monotonically decreasing loss is not sufficient evidence that the learning rate is good. If increasing tenfold leads to the same or better final validation performance in one tenth of the time, the original value was inefficient.
When the learning rate is too large
A large learning rate can overshoot a minimum. On a one-dimensional quadratic , the update is
Convergence requires , or
If , the sign of alternates while its magnitude shrinks. If , oscillations grow and the algorithm diverges. In real training, divergence may appear as rapidly increasing loss, infinities, NaNs, or weights with exploding magnitudes.
Learning-rate schedules
A useful strategy is to start with a learning rate large enough to move quickly and then reduce it for fine adjustment. Common schedules include:
- Step decay: multiply by a factor at chosen epochs.
- Exponential decay: use for .
- Inverse-time decay: use .
- Cosine decay: smoothly reduce the rate following part of a cosine curve.
- Warmup: begin with a small rate and increase it over early iterations before applying decay.
- Reduce on plateau: lower the rate when a monitored metric stops improving.
Warmup is especially useful in large neural networks because early gradients and optimizer statistics can be unreliable. Cosine schedules are popular when the training budget is known. Plateau-based schedules are convenient when the required number of epochs is uncertain, though they add monitoring choices and may react to metric noise.
Classical convergence results for stochastic approximation often require learning rates satisfying
These conditions make steps persistent enough to reach the solution but eventually small enough for noise to settle. Practical deep learning schedules do not always follow this theory exactly, yet the underlying idea remains useful.
Adaptive learning rates
Adaptive optimizers maintain a separate effective step size for each parameter. Parameters with consistently large squared gradients receive smaller normalized updates, while parameters with sparse or small gradients may receive relatively larger ones. This can be valuable when features have different scales or gradients are sparse.
Adaptation does not eliminate the global learning rate. Adam with can still diverge, and Adam with can still crawl. Treat the base learning rate as an important hyperparameter even when the optimizer adapts it.
Convex and Non-Convex Loss Landscapes
A function is convex if every line segment between two points lies above the function:
For differentiable convex objectives, every local minimum is global. Linear regression with mean squared error is convex in its coefficients. Logistic regression with the usual cross-entropy objective is also convex in its parameters, assuming the model remains linear in those parameters. Gradient descent on a smooth convex objective has a comparatively clean theory.
Strong convexity provides an even more bowl-like landscape and supports faster convergence guarantees. If the Hessian eigenvalues lie between and , then an appropriate fixed learning rate can produce geometric, or linear, convergence in distance to the optimum.
Neural network objectives are non-convex. Layers multiply parameters together, activation functions introduce nonlinearities, and symmetries create many equivalent parameter settings. The landscape may contain multiple basins, saddle points, ridges, and flat regions. Gradient descent can no longer promise the global minimum.
This sounds alarming, but global optimization is not always necessary. Large neural networks often have many parameter configurations with similarly low training loss, and the quality that matters is validation performance rather than the mathematical status of one minimum. Stochasticity, overparameterization, normalization, residual connections, and carefully designed initialization can make these enormous non-convex problems surprisingly trainable.
Momentum, Nesterov, RMSProp, and Adam
All four methods begin with gradient information, but they transform it differently.
Momentum
Ordinary gradient descent reacts only to the current gradient. Momentum accumulates a velocity:
Some libraries place the learning rate or a factor inside the velocity definition, so formulas and hyperparameters should be interpreted in the context of the implementation.
Imagine a ball rolling down a ravine. Gradients that repeatedly point in a similar direction build velocity, accelerating progress. Gradients that alternate across the narrow walls partly cancel, reducing side-to-side oscillation. Momentum is therefore effective on poorly conditioned landscapes and often works well for convolutional networks. A typical is .
Choose momentum SGD when you want a simple optimizer, can tune the learning rate and schedule, and care about strong final generalization. It may need more tuning than Adam, but it remains a robust baseline.
Nesterov accelerated gradient
Nesterov momentum evaluates the gradient after looking ahead in the velocity direction:
The optimizer effectively asks, "If momentum carries me forward, what will the slope be there?" It can correct the velocity before fully committing to the move. In convex optimization, Nesterov acceleration has important theoretical guarantees. In deep learning, Nesterov momentum is a modest but sometimes useful refinement of classical momentum.
Pick Nesterov when momentum SGD already works and you want anticipatory damping around curved valleys. Do not expect it to rescue a fundamentally unsuitable learning rate.
RMSProp
RMSProp tracks an exponential moving average of squared gradients:
where the square is elementwise. The update is
Dividing by the recent root-mean-square gradient normalizes coordinates with persistently different gradient magnitudes. RMSProp is useful for nonstationary objectives and has historically worked well with recurrent neural networks. The small prevents division by zero and can affect numerical behavior in low-precision training.
Choose RMSProp when per-parameter scaling is helpful but you do not need Adam's explicit first-moment estimate. It is also appropriate when an established recipe for the architecture already uses it.
Adam
Adam combines momentum-like first moments with RMSProp-like second moments:
Because both moving averages start at zero, Adam applies bias corrections:
The update is
Defaults such as , , and are often reasonable starting points. Adam tends to make fast initial progress and handles sparse gradients well. It is a strong default for transformers, language models, and rapid experimentation.
Adam is not automatically superior in final test performance. Momentum SGD sometimes reaches solutions that generalize better after sufficient schedule tuning. For regularized neural networks, AdamW is generally preferred over adding naive L2 regularization to Adam because AdamW decouples weight decay from the adaptive gradient update.
A practical selection rule is: start with the optimizer supported by a reliable recipe for your model family. Otherwise, use Adam or AdamW for a quick, forgiving baseline; compare with momentum SGD when final generalization matters; consider RMSProp for recurrent or nonstationary settings; and use Nesterov as an enhancement when momentum is already suitable.
Local Minima, Saddle Points, and Plateaus
A local minimum has a loss no greater than nearby points. In one dimension, a differentiable local minimum usually has zero first derivative and positive second derivative. In multiple dimensions, a positive definite Hessian indicates positive curvature in every direction.
A saddle point also has a zero gradient, but curves upward in some directions and downward in others. For example,
has , yet the origin is not a minimum. High-dimensional non-convex landscapes contain many saddle points, and exact local maxima are usually less troublesome because there are many directions in which to escape.
Near a saddle, gradients can be tiny, causing long periods of slow movement. Mini-batch noise and momentum may help by perturbing the path or carrying velocity through the region. A plateau is a broad area where gradients are small. Plateaus may result from saturated activation functions, poor initialization, excessive regularization, or genuine flatness in the objective.
Not every flat region is bad. Flat directions can reflect redundant parameterizations, and a wide basin may be compatible with robust generalization. The operational question is whether the training and validation metrics are improving, not whether every Hessian eigenvalue is comfortably positive.
Worked 1D Numerical Example
Consider
Its derivative is , and the minimum is at . Start from with :
The first iterations are:
- Iteration 0: , gradient , loss .
- Iteration 1: , gradient , loss .
- Iteration 2: , gradient , loss .
- Iteration 3: , gradient , loss .
- Iteration 4: , gradient , loss .
- Iteration 5: , loss .
Each error is multiplied by , so convergence is geometric. If , one update reaches exactly for this particular quadratic. If , the error multiplier is ; its magnitude exceeds one, so the iterates alternate sides and diverge.
Worked 2D Numerical Example
Now consider an anisotropic quadratic:
The gradient is
Start at with . The coordinate updates are
The numerical path is:
- Iteration 0: , gradient , loss .
- Iteration 1: , gradient , loss .
- Iteration 2: , gradient , loss .
- Iteration 3: , gradient , loss .
- Iteration 4: , gradient , loss approximately .
The coordinate converges much faster because its curvature is larger. The learning rate cannot be increased freely to accelerate : stability in the steep direction imposes . This tension is the essence of poor conditioning.
The same iterations can be reproduced with NumPy:
import numpy as np
theta = np.array([4.0, 2.0])
learning_rate = 0.1
for step in range(5):
x, y = theta
loss = x**2 + 4 * y**2
gradient = np.array([2 * x, 8 * y])
print(step, theta.copy(), loss, gradient)
theta -= learning_rate * gradient
This small program also demonstrates a useful debugging habit: print or log the parameters, loss, and gradient separately. A wrong gradient can otherwise be hidden behind an apparently plausible loss value.
Feature Scaling and Hessian Conditioning
Feature scale affects optimization even when it does not change the expressive power of a model. Suppose one linear-regression feature ranges from 0 to 1 and another from 0 to 100,000. A unit change in the second coefficient has a far larger effect on predictions, so the objective curves much more sharply along that parameter direction.
The Hessian collects second derivatives:
Near a quadratic minimum, Hessian eigenvectors identify principal curvature directions, and eigenvalues describe how sharply the loss curves in those directions. The condition number is
for a positive definite Hessian. A large condition number means a long, narrow valley. A learning rate small enough to remain stable across the steep direction makes slow progress along the shallow direction, producing a zigzagging path.
Standardization transforms a feature approximately to
This often makes the curvature more balanced. Min-max scaling is another option, especially when bounded ranges are meaningful. Neural networks also benefit from normalized inputs, and normalization layers can improve intermediate activation scales.
Scaling is not merely cosmetic preprocessing. It acts like a basic form of preconditioning: it changes the coordinate system so that gradient descent can move efficiently. Adaptive optimizers partly compensate for coordinate-wise scale differences, but good input scaling still improves numerical stability and usually makes training easier.
Stopping Criteria and Loss-Curve Monitoring
An optimizer needs a rule for when to stop. Common criteria include:
- A fixed maximum number of iterations or epochs.
- A gradient norm below a threshold: .
- A small parameter change: .
- A small relative objective improvement.
- No validation improvement for a chosen patience period.
- A wall-clock or compute budget.
No single criterion is reliable in every setting. A small gradient may indicate a plateau rather than a useful minimum. Tiny parameter updates may simply reflect a tiny learning rate. Training loss can keep improving while validation loss worsens because of overfitting. In supervised neural-network training, a maximum epoch count combined with validation-based early stopping is often practical.
Monitor more than one curve. Record training loss, validation loss, the current learning rate, gradient norms, and task metrics such as accuracy or mean absolute error. If training loss falls while validation loss rises, the optimizer is still doing its job on the training objective, but generalization is deteriorating. Consider early stopping, stronger regularization, more data, or augmentation.
If both losses remain high and nearly flat, suspect an optimization issue, insufficient model capacity, or a data pipeline problem. If loss oscillates wildly, reduce the learning rate, inspect batch composition, and check gradient magnitudes. If the loss decreases smoothly but painfully slowly, raise the learning rate cautiously or improve scaling and conditioning.
Use smoothed curves for readability, but retain raw measurements. Heavy smoothing can hide spikes that precede divergence. Also compare metrics at consistent units: per mini-batch values are noisy, while epoch averages are easier to interpret.
Common Implementation Bugs
Using the wrong sign
The minimization update subtracts the gradient. Writing
performs gradient ascent and usually increases the loss. The sign can become confusing when maximizing a reward or log-likelihood. State explicitly whether the objective is minimized or maximized, and test the update on a simple quadratic with a known minimum.
Forgetting to normalize the loss or gradient
If a batch loss is summed rather than averaged, doubling the batch size doubles the gradient magnitude. The same nominal learning rate then behaves differently. Summed gradients are valid if the learning rate is designed for them, but accidental inconsistency creates hard-to-explain instability.
Training on unnormalized data
Features with radically different magnitudes create poor conditioning and can overflow intermediate calculations. Standardize numerical inputs based only on training-set statistics, then apply the same transformation to validation and test data. Do not recompute separate normalization statistics on each split.
Choosing an exploding learning rate
An excessive rate may work for several updates before entering a steep region and diverging. Watch for sudden loss spikes, non-finite gradients, and rapidly growing parameter norms. Lower the rate and consider gradient clipping when rare large gradients are expected, especially in recurrent networks.
Failing to clear accumulated gradients
Some automatic differentiation frameworks accumulate gradients by default. If gradients are not reset between steps, the optimizer unintentionally uses a sum across multiple batches. This can mimic a growing learning rate.
Updating parameters before measuring diagnostics
Logging a loss from before the update with parameters from after the update makes records inconsistent. Adopt a precise order and label values by step. This matters when validating a custom optimizer against hand calculations.
Data leakage and train/evaluation mode errors
Optimization can appear excellent when preprocessing has leaked validation information into training. Likewise, dropout and batch normalization behave differently in training and evaluation modes. Incorrect mode switching can make validation curves noisy or misleading even if parameter updates are correct.
Silent broadcasting or shape mistakes
Array libraries may broadcast incompatible-looking tensors without raising an error. The code runs, but the objective is not the intended one. Assert key shapes, compare analytical gradients with finite differences on a tiny problem, and write tests for one manually computed update.
Linear Regression as Gradient Descent
For a design matrix , targets , and coefficients , mean squared error can be written
Its gradient is
Gradient descent therefore updates
Linear regression also has a closed-form normal-equation solution under suitable conditions. Why use gradient descent? Matrix inversion can be expensive or numerically undesirable for very high-dimensional data, while mini-batch methods can process datasets too large for memory. The linear-regression case is also ideal for learning because the objective is convex and the gradient can be checked exactly.
The Hessian is , directly connecting feature correlations and scaling to conditioning. Highly correlated features create shallow directions, while large scale disparities create very different curvature magnitudes.
Neural Network Training as Gradient Descent
A neural network composes many parameterized functions. Backpropagation applies the chain rule efficiently to calculate gradients of the loss with respect to every weight and bias. Backpropagation is not itself an optimizer: it computes gradients. SGD, Adam, or another optimizer decides how to use those gradients.
A typical training step performs these operations:
- Select a mini-batch.
- Run a forward pass to obtain predictions.
- Compute the loss.
- Run backpropagation to obtain gradients.
- Optionally clip or otherwise transform gradients.
- Apply the optimizer update.
- Update the learning-rate schedule if required.
Deep networks add complications such as vanishing and exploding gradients. Initialization schemes, ReLU-like activations, normalization, residual connections, and gradient clipping all help gradients remain informative. The optimizer cannot repair a completely broken gradient path; architecture and optimization must work together.
Regularization also interacts with training. Dropout changes the stochastic objective seen by each mini-batch. Weight decay pulls parameters toward zero. Data augmentation changes sampled inputs. Early stopping limits how long the optimizer fits training-specific details. These techniques influence both the landscape and the eventual solution.
Practice with Solver360
Reading equations becomes much more useful when paired with experimentation. Open the free Gradient Descent Calculator and begin with a one-dimensional quadratic. Change the starting point while keeping the learning rate fixed. Then keep the starting point fixed and gradually increase the learning rate.
Look for three regimes: slow monotonic progress, convergent oscillation, and divergent oscillation. Relate each observed path to the quadratic multiplier . Next, compare a circular two-dimensional bowl with an elongated one. The elongated contours should reveal why a single global learning rate zigzags when curvature differs by direction.
Try these focused exercises:
- Find the largest stable learning rate for a selected quadratic and compare it with .
- Add momentum and observe whether oscillation across a narrow valley decreases.
- Move the initial point near a saddle and compare deterministic and noisy updates.
- Rescale one variable and inspect how the path changes without changing the location of the optimum.
- Compare fixed, decaying, and adaptive learning rates using the same update budget.
- Record loss by iteration and decide which stopping rule would terminate at a sensible point.
The goal is not to declare one optimizer universally best. It is to connect visible behavior to gradient direction, curvature, noise, and step size. That mental model transfers directly to real model training.
Frequently Asked Questions
Does gradient descent always find the global minimum?
No. For a differentiable convex objective, appropriate gradient descent settings can converge to a global minimum because every local minimum is global. Stronger assumptions determine the convergence rate. In non-convex problems such as neural networks, the optimizer may reach a local minimum, a nearly flat region, or a point that is merely good enough. It can also fail through an unsuitable learning rate or poor numerical behavior.
The absence of a global guarantee does not make gradient descent ineffective. Modern models often have many low-loss solutions, and exact global optimality on training loss is less important than performance on unseen data. Initialization, stochastic mini-batches, architecture, schedules, and regularization all shape which solution is reached. Judge success with training diagnostics and held-out evaluation rather than assuming a mathematical guarantee that does not apply.
How should I choose the initial learning rate?
Begin with a value recommended for the optimizer and model family, then test orders of magnitude. For Adam, values near are common starting points; for momentum SGD, the useful value depends strongly on batch size, normalization, and architecture. These are starting heuristics, not laws.
A learning-rate range test can be informative: start very small, increase the rate over a short run, and identify where loss begins decreasing rapidly and where it becomes unstable. Choose a value below the unstable region, then verify it in a full training run. Compare multiple seeds when stochastic variation is meaningful. If batch size changes substantially, retune the rate rather than assuming the original value transfers unchanged.
Why does my loss increase occasionally even when training is healthy?
Mini-batch gradients optimize sampled estimates of the objective, not the exact full-dataset loss. One update can improve the current batch while worsening another, and difficult batches can report higher loss than easy ones. Data augmentation and dropout add further randomness. Occasional increases are therefore normal.
Focus on the trend of epoch-level training loss and validation metrics. Sharp, increasingly frequent spikes may indicate an excessive learning rate, numerical instability, corrupted examples, or a problematic batch. Logging gradient norms and batch identifiers can distinguish ordinary noise from systematic failures. Avoid reacting to every fluctuation by changing hyperparameters; use a sufficiently long observation window.
What is the difference between gradient clipping and lowering the learning rate?
Lowering the learning rate scales every update. Gradient clipping changes only gradients that exceed a threshold. Norm clipping commonly replaces by
where is the maximum norm. This protects training from rare extreme gradients while leaving ordinary updates unchanged. Lowering the learning rate may unnecessarily slow all steps.
Clipping is especially useful for exploding gradients in recurrent models or occasional outliers. It should not be used to conceal persistent instability. If almost every gradient is clipped, investigate the learning rate, data scale, initialization, loss reduction, and architecture. Also log the unclipped norm so the clipping operation does not hide the underlying issue.
Is Adam always better than SGD?
No. Adam often reaches a useful solution quickly and requires less initial tuning, especially with sparse gradients or transformer-like architectures. Momentum SGD can sometimes achieve better final generalization, particularly in computer vision recipes that use carefully tuned schedules and weight decay.
The comparison must be fair. Giving Adam a tuned schedule while leaving SGD at a default learning rate says little about the optimizers themselves. Compare validation performance under similar compute budgets and competent settings. Established model recipes are valuable because optimizer, schedule, batch size, normalization, and regularization are interdependent. When uncertain, AdamW is a practical first baseline and momentum SGD is a valuable second experiment.
How do batch size and learning rate interact?
A larger batch averages more examples, reducing gradient variance and often permitting a larger learning rate. Some recipes scale the learning rate linearly with batch size, while others use square-root scaling. Neither rule is universal. Very large batches may need warmup because a high rate is dangerous during unstable early training.
Batch size also changes the number of updates per epoch. Doubling it halves the number of updates in one pass through the dataset, so comparing only by epochs can be misleading. Hardware throughput may improve with larger batches until memory or communication limits dominate. Tune batch size for both statistical behavior and system efficiency, then retune the learning rate and schedule.
What does it mean if the gradient norm is nearly zero but the loss is high?
Several explanations are possible. The optimizer may be near a saddle point or plateau. Saturating activations can suppress gradients. A parameter may be disconnected from the computational graph. The loss may include a nondifferentiable or incorrectly implemented operation. Poor initialization can also place the network in a region where signals vanish.
Check gradients layer by layer rather than only as one global norm. Verify the loss on a tiny batch, inspect activation distributions, and confirm that parameters require gradients and participate in the forward pass. Try overfitting a handful of examples; failure to do so often reveals an implementation or optimization problem. Raising the learning rate is not a reliable fix when the gradients are structurally broken.
Should I stop when training loss stops decreasing?
Not necessarily. A temporary plateau may end after a scheduled learning-rate change, and noisy mini-batch loss can conceal slow improvement. Conversely, training loss may continue decreasing after validation performance has begun to worsen. Stopping should reflect the actual goal.
For supervised learning, monitor a validation metric with patience and preserve the best checkpoint. Patience should be long enough to tolerate noise and scheduled transitions. Also retain a maximum epoch or compute limit. For convex deterministic optimization, gradient norm or relative objective change may be more appropriate. Whatever rule you choose, define it before interpreting the curve so that stopping is not based on wishful reading of random fluctuations.
Why does feature scaling matter if the model could learn compensating weights?
The final predictive function may indeed be expressible with compensating weights, but the path used to find those weights depends on the coordinate system. Unequal feature scales create unequal curvature. A stable learning rate for the steep direction then moves too slowly along a shallow direction.
Scaling improves conditioning, making a single learning rate more effective across parameters. It also reduces floating-point problems and makes regularization more comparable across coefficients. Adaptive optimizers help but do not remove every benefit. Fit scaling statistics on training data only, store them with the model, and apply exactly the same transformation during validation and deployment.
Summary and Next Reading
Gradient descent turns learning into a sequence of informed parameter updates. The negative gradient is the steepest local descent direction, while the learning rate determines whether steps are efficient, hesitant, oscillatory, or unstable. Batch gradients provide accuracy, stochastic gradients provide cheap noisy progress, and mini-batches offer the practical balance used in most neural-network systems.
Curvature explains much of optimizer behavior. Convex objectives offer global guarantees, while non-convex landscapes introduce saddles, plateaus, and many basins. Feature scaling improves Hessian conditioning. Momentum builds velocity, Nesterov looks ahead, RMSProp normalizes with recent squared gradients, and Adam combines first- and second-moment estimates. None is universally best; model family, data, compute budget, and validation performance should guide the choice.
Reliable training requires more than selecting an optimizer name. Monitor loss, validation metrics, learning rate, and gradient norms. Use coherent stopping criteria. Test gradients on small known problems, normalize data, check signs and reduction conventions, and treat non-finite values as evidence to investigate rather than something to ignore.
For next reading, study backpropagation to understand how neural networks compute gradients, convex optimization for formal convergence results, Hessian eigenvalues and preconditioning for a deeper account of curvature, and regularization for the distinction between minimizing training error and generalizing well. Then return to the Gradient Descent Calculator and use controlled experiments to connect those ideas to visible optimization paths.
Continue reading
Calculus for Machine Learning: Derivatives, Gradients, and the Chain Rule
How derivatives, partials, gradients, Jacobians, and the chain rule turn a loss into parameter updates — the calculus behind backpropagation.
Loss Functions in Machine Learning: MSE, MAE, Likelihood, and Cross-Entropy
What a loss actually optimizes: MSE and MAE for regression, log loss and cross-entropy for classification, and how regularization adds extra terms.