Recent from talks
Nothing was collected or created yet.
Gradient descent
View on Wikipedia| Part of a series on |
| Machine learning and data mining |
|---|
Gradient descent is a method for unconstrained mathematical optimization. It is a first-order iterative algorithm for minimizing a differentiable multivariate function.
The idea is to take repeated steps in the opposite direction of the gradient (or approximate gradient) of the function at the current point, because this is the direction of steepest descent. Conversely, stepping in the direction of the gradient will lead to a trajectory that maximizes that function; the procedure is then known as gradient ascent. It is particularly useful in machine learning for minimizing the cost or loss function.[1] Gradient descent should not be confused with local search algorithms, although both are iterative methods for optimization.
Gradient descent is generally attributed to Augustin-Louis Cauchy, who first suggested it in 1847.[2] Jacques Hadamard independently proposed a similar method in 1907.[3][4] Its convergence properties for non-linear optimization problems were first studied by Haskell Curry in 1944,[5] with the method becoming increasingly well-studied and used in the following decades.[6][7]
A simple extension of gradient descent, stochastic gradient descent, serves as the most basic algorithm used for training most deep networks today.
Description
[edit]
Gradient descent is based on the observation that if the multi-variable function is defined and differentiable in a neighborhood of a point , then decreases fastest if one goes from in the direction of the negative gradient of at . It follows that, if
for a small enough step size or learning rate , then . In other words, the term is subtracted from because we want to move against the gradient, toward the local minimum. With this observation in mind, one starts with a guess for a local minimum of , and considers the sequence such that
We have a monotonic sequence
so the sequence converges to the desired local minimum. Note that the value of the step size is allowed to change at every iteration.
It is possible to guarantee the convergence to a local minimum under certain assumptions on the function (for example, convex and Lipschitz) and particular choices of . Those include the sequence
as in the Barzilai-Borwein method,[8][9] or a sequence satisfying the Wolfe conditions (which can be found by using line search). When the function is convex, all local minima are also global minima, so in this case gradient descent can converge to the global solution.
This process is illustrated in the adjacent picture. Here, is assumed to be defined on the plane, and that its graph has a bowl shape. The blue curves are the contour lines, that is, the regions on which the value of is constant. A red arrow originating at a point shows the direction of the negative gradient at that point. Note that the (negative) gradient at a point is orthogonal to the contour line going through that point. We see that gradient descent leads us to the bottom of the bowl, that is, to the point where the value of the function is minimal.
An analogy for understanding gradient descent
[edit]
The basic intuition behind gradient descent can be illustrated by a hypothetical scenario. People are stuck in the mountains and are trying to get down (i.e., trying to find the global minimum). There is heavy fog such that visibility is extremely low. Therefore, the path down the mountain is not visible, so they must use local information to find the minimum. They can use the method of gradient descent, which involves looking at the steepness of the hill at their current position, then proceeding in the direction with the steepest descent (i.e., downhill). If they were trying to find the top of the mountain (i.e., the maximum), then they would proceed in the direction of steepest ascent (i.e., uphill). Using this method, they would eventually find their way down the mountain or possibly get stuck in some hole (i.e., local minimum or saddle point), like a mountain lake. However, assume also that the steepness of the hill is not immediately obvious with simple observation, but rather it requires a sophisticated instrument to measure, which the people happen to have at that moment. It takes quite some time to measure the steepness of the hill with the instrument. Thus, they should minimize their use of the instrument if they want to get down the mountain before sunset. The difficulty then is choosing the frequency at which they should measure the steepness of the hill so as not to go off track.
In this analogy, the people represent the algorithm, and the path taken down the mountain represents the sequence of parameter settings that the algorithm will explore. The steepness of the hill represents the slope of the function at that point. The instrument used to measure steepness is differentiation. The direction they choose to travel in aligns with the gradient of the function at that point. The amount of time they travel before taking another measurement is the step size.
Choosing the step size and descent direction
[edit]Since using a step size that is too small would slow convergence, and a too large would lead to overshoot and divergence, finding a good setting of is an important practical problem. Philip Wolfe also advocated using "clever choices of the [descent] direction" in practice.[10] While using a direction that deviates from the steepest descent direction may seem counter-intuitive, the idea is that the smaller slope may be compensated for by being sustained over a much longer distance.
To reason about this mathematically, consider a direction and step size and consider the more general update:
- .
Finding good settings of and requires some thought. First of all, we would like the update direction to point downhill. Mathematically, letting denote the angle between and , this requires that To say more, we need more information about the objective function that we are optimising. Under the fairly weak assumption that is continuously differentiable, we may prove that:[11]
| 1 |
This inequality implies that the amount by which we can be sure the function is decreased depends on a trade off between the two terms in square brackets. The first term in square brackets measures the angle between the descent direction and the negative gradient. The second term measures how quickly the gradient changes along the descent direction.
In principle inequality (1) could be optimized over and to choose an optimal step size and direction. The problem is that evaluating the second term in square brackets requires evaluating , and extra gradient evaluations are generally expensive and undesirable. Some ways around this problem are:
- Forgo the benefits of a clever descent direction by setting , and use line search to find a suitable step-size , such as one that satisfies the Wolfe conditions. A more economic way of choosing learning rates is backtracking line search, a method that has both good theoretical guarantees and experimental results. Note that one does not need to choose to be the gradient; any direction that has positive inner product with the gradient will result in a reduction of the function value (for a sufficiently small value of ).
- Assuming that is twice-differentiable, use its Hessian to estimate Then choose and by optimising inequality (1).
- Assuming that is Lipschitz, use its Lipschitz constant to bound Then choose and by optimising inequality (1).
- Build a custom model of for . Then choose and by optimising inequality (1).
- Under stronger assumptions on the function such as convexity, more advanced techniques may be possible.
Usually by following one of the recipes above, convergence to a local minimum can be guaranteed. When the function is convex, all local minima are also global minima, so in this case gradient descent can converge to the global solution.
Solution of a linear system
[edit]
Gradient descent can be used to solve a system of linear equations
reformulated as a quadratic minimization problem. If the system matrix is real symmetric and positive-definite, an objective function is defined as the quadratic function, with minimization of
so that
For a general real matrix , linear least squares define
In traditional linear least squares for real and the Euclidean norm is used, in which case
The line search minimization, finding the locally optimal step size on every iteration, can be performed analytically for quadratic functions, and explicit formulas for the locally optimal are known.[6][13]
For example, for real symmetric and positive-definite matrix , a simple algorithm can be as follows,[6]
To avoid multiplying by twice per iteration, we note that implies , which gives the traditional algorithm,[14]
The method is rarely used for solving linear equations, with the conjugate gradient method being one of the most popular alternatives. The number of gradient descent iterations is commonly proportional to the spectral condition number of the system matrix (the ratio of the maximum to minimum eigenvalues of ), while the convergence of conjugate gradient method is typically determined by a square root of the condition number, i.e., is much faster. Both methods can benefit from preconditioning, where gradient descent may require less assumptions on the preconditioner.[14]
Geometric behavior and residual orthogonality
[edit]In steepest descent applied to solving , where is symmetric positive-definite, the residual vectors are orthogonal across iterations:
Because each step is taken in the steepest direction, steepest-descent steps alternate between directions aligned with the extreme axes of the elongated level sets. When is large, this produces a characteristic zig–zag path. The poor conditioning of is the primary cause of the slow convergence, and orthogonality of successive residuals reinforces this alternation.

As shown in the image on the right, steepest descent converges slowly due to the high condition number of , and the orthogonality of residuals forces each new direction to undo the overshoot from the previous step. The result is a path that zigzags toward the solution. This inefficiency is one reason conjugate gradient or preconditioning methods are preferred.[15]
Solution of a non-linear system
[edit]Gradient descent can also be used to solve a system of nonlinear equations. Below is an example that shows how to use the gradient descent to solve for three unknown variables, x1, x2, and x3. This example shows one iteration of the gradient descent.
Consider the nonlinear system of equations
Let us introduce the associated function
where
One might now define the objective function
which we will attempt to minimize. As an initial guess, let us use
We know that
where the Jacobian matrix is given by
We calculate:
Thus
and

Now, a suitable must be found such that
This can be done with any of a variety of line search algorithms. One might also simply guess which gives
Evaluating the objective function at this value, yields
The decrease from to the next step's value of
is a sizable decrease in the objective function. Further steps would reduce its value further until an approximate solution to the system was found.
Comments
[edit]Gradient descent works in spaces of any number of dimensions, even in infinite-dimensional ones. In the latter case, the search space is typically a function space, and one calculates the Fréchet derivative of the functional to be minimized to determine the descent direction.[7]
That gradient descent works in any number of dimensions (finite number at least) can be seen as a consequence of the Cauchy–Schwarz inequality, i.e. the magnitude of the inner (dot) product of two vectors of any dimension is maximized when they are colinear. In the case of gradient descent, that would be when the vector of independent variable adjustments is proportional to the gradient vector of partial derivatives.
The gradient descent can take many iterations to compute a local minimum with a required accuracy, if the curvature in different directions is very different for the given function. For such functions, preconditioning, which changes the geometry of the space to shape the function level sets like concentric circles, cures the slow convergence. Constructing and applying preconditioning can be computationally expensive, however.
The gradient descent can be modified via momentums[16] (Nesterov, Polyak,[17] and Frank–Wolfe[18]) and heavy-ball parameters (exponential moving averages[19] and positive-negative momentum[20]). The main examples of such optimizers are Adam, DiffGrad, Yogi, AdaBelief, etc.
Methods based on Newton's method and inversion of the Hessian using conjugate gradient techniques can be better alternatives.[21][22] Generally, such methods converge in fewer iterations, but the cost of each iteration is higher. An example is the BFGS method which consists in calculating on every step a matrix by which the gradient vector is multiplied to go into a "better" direction, combined with a more sophisticated line search algorithm, to find the "best" value of For extremely large problems, where the computer-memory issues dominate, a limited-memory method such as L-BFGS should be used instead of BFGS or the steepest descent.
While it is sometimes possible to substitute gradient descent for a local search algorithm, gradient descent is not in the same family: although it is an iterative method for local optimization, it relies on an objective function’s gradient rather than an explicit exploration of a solution space.
Gradient descent can be viewed as applying Euler's method for solving ordinary differential equations to a gradient flow. In turn, this equation may be derived as an optimal controller[23] for the control system with given in feedback form .
Modifications
[edit]Gradient descent can converge to a local minimum and slow down in a neighborhood of a saddle point. Even for unconstrained quadratic minimization, gradient descent develops a zig–zag pattern of subsequent iterates as iterations progress, resulting in slow convergence. Multiple modifications of gradient descent have been proposed to address these deficiencies.
Fast gradient methods
[edit]Yurii Nesterov has proposed[24] a simple modification that enables faster convergence for convex problems and has been since further generalized. For unconstrained smooth problems, the method is called the fast gradient method (FGM) or the accelerated gradient method (AGM). Specifically, if the differentiable function is convex and is Lipschitz, and it is not assumed that is strongly convex, then the error in the objective value generated at each step by the gradient descent method will be bounded by . Using the Nesterov acceleration technique, the error decreases at .[25][26] It is known that the rate for the decrease of the cost function is optimal for first-order optimization methods. Nevertheless, there is the opportunity to improve the algorithm by reducing the constant factor. The optimized gradient method (OGM)[27] reduces that constant by a factor of two and is an optimal first-order method for large-scale problems.[28]
For constrained or non-smooth problems, Nesterov's FGM is called the fast proximal gradient method (FPGM), an acceleration of the proximal gradient method.
Momentum or heavy ball method
[edit]Trying to break the zig-zag pattern of gradient descent, the momentum or heavy ball method uses a momentum term in analogy to a heavy ball sliding on the surface of values of the function being minimized,[6] or to mass movement in Newtonian dynamics through a viscous medium in a conservative force field.[29] Gradient descent with momentum remembers the solution update at each iteration, and determines the next update as a linear combination of the gradient and the previous update. For unconstrained quadratic minimization, a theoretical convergence rate bound of the heavy ball method is asymptotically the same as that for the optimal conjugate gradient method.[6]
This technique is used in stochastic gradient descent and as an extension to the backpropagation algorithms used to train artificial neural networks.[30][31] In the direction of updating, stochastic gradient descent adds a stochastic property. The weights can be used to calculate the derivatives.
Extensions
[edit]Gradient descent can be extended to handle constraints by including a projection onto the set of constraints. This method is only feasible when the projection is efficiently computable on a computer. Under suitable assumptions, this method converges. This method is a specific case of the forward–backward algorithm for monotone inclusions (which includes convex programming and variational inequalities).[32]
Gradient descent is a special case of mirror descent using the squared Euclidean distance as the given Bregman divergence.[33]
Theoretical properties
[edit]The properties of gradient descent depend on the properties of the objective function and the variant of gradient descent used (for example, if a line search step is used). The assumptions made affect the convergence rate, and other properties, that can be proven for gradient descent.[34] For example, if the objective is assumed to be strongly convex and lipschitz smooth, then gradient descent converges linearly with a fixed step size.[1] Looser assumptions lead to either weaker convergence guarantees or require a more sophisticated step size selection.[34]
Examples
[edit]See also
[edit]- Backtracking line search
- Conjugate gradient method
- Stochastic gradient descent
- Rprop
- Delta rule
- Wolfe conditions
- Preconditioning
- Broyden–Fletcher–Goldfarb–Shanno algorithm
- Davidon–Fletcher–Powell formula
- Nelder–Mead method
- Gauss–Newton algorithm
- Hill climbing
- Quantum annealing
- CLS (continuous local search)
- Neuroevolution
References
[edit]- ^ a b Boyd, Stephen; Vandenberghe, Lieven (2004-03-08). Convex Optimization. Cambridge University Press. doi:10.1017/cbo9780511804441. ISBN 978-0-521-83378-3.
- ^ Lemaréchal, C. (1 January 2012). "Cauchy and the gradient method" (PDF). In Grötschel, M. (ed.). Optimization Stories. Documenta Mathematica Series. Vol. 6 (1st ed.). EMS Press. pp. 251–254. doi:10.4171/dms/6/27. ISBN 978-3-936609-58-5. Archived from the original (PDF) on 2018-12-29. Retrieved 2020-01-26.
- ^ Hadamard, Jacques (1908). "Mémoire sur le problème d'analyse relatif à l'équilibre des plaques élastiques encastrées". Mémoires présentés par divers savants éstrangers à l'Académie des Sciences de l'Institut de France. 33.
- ^ Courant, R. (1943). "Variational methods for the solution of problems of equilibrium and vibrations". Bulletin of the American Mathematical Society. 49 (1): 1–23. doi:10.1090/S0002-9904-1943-07818-4.
- ^ Curry, Haskell B. (1944). "The Method of Steepest Descent for Non-linear Minimization Problems". Quart. Appl. Math. 2 (3): 258–261. doi:10.1090/qam/10667.
- ^ a b c d e Polyak, Boris (1987). Introduction to Optimization.
- ^ a b Akilov, G. P.; Kantorovich, L. V. (1982). Functional Analysis (2nd ed.). Pergamon Press. ISBN 0-08-023036-9.
- ^ Barzilai, Jonathan; Borwein, Jonathan M. (1988). "Two-Point Step Size Gradient Methods". IMA Journal of Numerical Analysis. 8 (1): 141–148. doi:10.1093/imanum/8.1.141.
- ^ Fletcher, R. (2005). "On the Barzilai–Borwein Method". In Qi, L.; Teo, K.; Yang, X. (eds.). Optimization and Control with Applications. Applied Optimization. Vol. 96. Boston: Springer. pp. 235–256. ISBN 0-387-24254-6.
- ^ Wolfe, Philip (April 1969). "Convergence Conditions for Ascent Methods". SIAM Review. 11 (2): 226–235. doi:10.1137/1011036.
- ^ Bernstein, Jeremy; Vahdat, Arash; Yue, Yisong; Liu, Ming-Yu (2020-06-12). "On the distance between two neural networks and the stability of learning". arXiv:2002.03432 [cs.LG].
- ^ Haykin, Simon S. Adaptive filter theory. Pearson Education India, 2008. - p. 108-142, 217-242
- ^ Saad, Yousef (2003). Iterative methods for sparse linear systems (2nd ed.). Philadelphia, Pa.: Society for Industrial and Applied Mathematics. pp. 195. ISBN 978-0-89871-534-7.
- ^ a b Bouwmeester, Henricus; Dougherty, Andrew; Knyazev, Andrew V. (2015). "Nonsymmetric Preconditioning for Conjugate Gradient and Steepest Descent Methods". Procedia Computer Science. 51: 276–285. arXiv:1212.6680. doi:10.1016/j.procs.2015.05.241.
- ^ Holmes, M. (2023). Introduction to Scientific Computing and Data Analysis, 2nd Ed. Springer. ISBN 978-3-031-22429-4.
- ^ Abdulkadirov, Ruslan; Lyakhov, Pavel; Nagornov, Nikolay (January 2023). "Survey of Optimization Algorithms in Modern Neural Networks". Mathematics. 11 (11): 2466. doi:10.3390/math11112466. ISSN 2227-7390.
- ^ Diakonikolas, Jelena; Jordan, Michael I. (January 2021). "Generalized Momentum-Based Methods: A Hamiltonian Perspective". SIAM Journal on Optimization. 31 (1): 915–944. arXiv:1906.00436. doi:10.1137/20M1322716. ISSN 1052-6234.
- ^ Meyer, Gerard G. L. (November 1974). "Accelerated Frank–Wolfe Algorithms". SIAM Journal on Control. 12 (4): 655–663. doi:10.1137/0312050. ISSN 0036-1402.
- ^ Kingma, Diederik P.; Ba, Jimmy (2017-01-29), Adam: A Method for Stochastic Optimization, arXiv:1412.6980
- ^ Xie, Zeke; Yuan, Li; Zhu, Zhanxing; Sugiyama, Masashi (2021-07-01). "Positive-Negative Momentum: Manipulating Stochastic Gradient Noise to Improve Generalization". Proceedings of the 38th International Conference on Machine Learning. PMLR: 11448–11458. arXiv:2103.17182.
- ^ Press, W. H.; Teukolsky, S. A.; Vetterling, W. T.; Flannery, B. P. (1992). Numerical Recipes in C: The Art of Scientific Computing (2nd ed.). New York: Cambridge University Press. ISBN 0-521-43108-5.
- ^ Strutz, T. (2016). Data Fitting and Uncertainty: A Practical Introduction to Weighted Least Squares and Beyond (2nd ed.). Springer Vieweg. ISBN 978-3-658-11455-8.
- ^ Ross, I.M. (July 2019). "An optimal control theory for nonlinear optimization". Journal of Computational and Applied Mathematics. 354: 39–51. doi:10.1016/j.cam.2018.12.044. S2CID 127649426.
- ^ Nesterov, Yurii (2004). Introductory Lectures on Convex Optimization : A Basic Course. Springer. ISBN 1-4020-7553-7.
- ^ Vandenberghe, Lieven (2019). "Fast Gradient Methods" (PDF). Lecture notes for EE236C at UCLA.
- ^ Walkington, Noel J. (2023). "Nesterov's Method for Convex Optimization". SIAM Review. 65 (2): 539–562. doi:10.1137/21M1390037. ISSN 0036-1445.
- ^ Kim, D.; Fessler, J. A. (2016). "Optimized First-order Methods for Smooth Convex Minimization". Mathematical Programming. 151 (1–2): 81–107. arXiv:1406.5468. doi:10.1007/s10107-015-0949-3. PMC 5067109. PMID 27765996. S2CID 207055414.
- ^ Drori, Yoel (2017). "The Exact Information-based Complexity of Smooth Convex Minimization". Journal of Complexity. 39: 1–16. arXiv:1606.01424. doi:10.1016/j.jco.2016.11.001. S2CID 205861966.
- ^ Qian, Ning (January 1999). "On the momentum term in gradient descent learning algorithms". Neural Networks. 12 (1): 145–151. CiteSeerX 10.1.1.57.5612. doi:10.1016/S0893-6080(98)00116-6. PMID 12662723. S2CID 2783597.
- ^ "Momentum and Learning Rate Adaptation". Willamette University. Retrieved 17 October 2014.
- ^ Geoffrey Hinton; Nitish Srivastava; Kevin Swersky. "The momentum method". Coursera. Retrieved 2 October 2018. Part of a lecture series for the Coursera online course Neural Networks for Machine Learning Archived 2016-12-31 at the Wayback Machine.
- ^ Combettes, P. L.; Pesquet, J.-C. (2011). "Proximal splitting methods in signal processing". In Bauschke, H. H.; Burachik, R. S.; Combettes, P. L.; Elser, V.; Luke, D. R.; Wolkowicz, H. (eds.). Fixed-Point Algorithms for Inverse Problems in Science and Engineering. New York: Springer. pp. 185–212. arXiv:0912.3522. ISBN 978-1-4419-9568-1.
- ^ "Mirror descent algorithm".
- ^ a b Bubeck, Sébastien (2015). "Convex Optimization: Algorithms and Complexity". arXiv:1405.4980 [math.OC].
Further reading
[edit]- Boyd, Stephen; Vandenberghe, Lieven (2004). "Unconstrained Minimization" (PDF). Convex Optimization. New York: Cambridge University Press. pp. 457–520. ISBN 0-521-83378-7.
- Chong, Edwin K. P.; Żak, Stanislaw H. (2013). "Gradient Methods". An Introduction to Optimization (Fourth ed.). Hoboken: Wiley. pp. 131–160. ISBN 978-1-118-27901-4.
- Himmelblau, David M. (1972). "Unconstrained Minimization Procedures Using Derivatives". Applied Nonlinear Programming. New York: McGraw-Hill. pp. 63–132. ISBN 0-07-028921-2.
External links
[edit]- Using gradient descent in C++, Boost, Ublas for linear regression
- Series of Khan Academy videos discusses gradient ascent
- Online book teaching gradient descent in deep neural network context
- Archived at Ghostarchive and the Wayback Machine: "Gradient Descent, How Neural Networks Learn". 3Blue1Brown. October 16, 2017 – via YouTube.
- Garrigos, Guillaume; Gower, Robert M. (2023). "Handbook of Convergence Theorems for (Stochastic) Gradient Methods". arXiv:2301.11235 [math.OC].
Gradient descent
View on GrokipediaFundamentals
Definition and Intuition
Gradient descent is an iterative first-order optimization algorithm designed to minimize a differentiable objective function by repeatedly updating parameters in the direction opposite to the gradient, which points toward the local increase of the function. This approach relies solely on evaluations of the function and its first derivatives, making it computationally efficient for high-dimensional problems where higher-order information, such as Hessians, is impractical to compute. Intuitively, gradient descent can be likened to navigating down a foggy mountain: at each step, one assesses the steepest downhill slope based on the terrain immediately underfoot—the gradient—and takes a step in the opposite direction, gradually approaching the valley floor, which represents a local minimum.[5] This analogy highlights the method's reliance on local information to make globally informed progress, though it may zigzag or slow down in rugged landscapes with flat regions or narrow valleys.[5] In optimization problems, gradient descent serves to locate local minima of the objective function, a task central to fields like machine learning, where it tunes model parameters to minimize loss functions measuring prediction errors.[5] Its simplicity and scalability have made it foundational for training neural networks and other data-driven models.[5] The technique traces its origins to Augustin-Louis Cauchy, who in 1847 introduced it as a method for solving systems of equations by iteratively reducing residuals along descent directions.[6] It was later generalized in the 20th century, notably by Jacques Hadamard in 1907, who applied similar iterative gradient-based steps to variational problems in analysis.Mathematical Formulation
Gradient descent seeks to minimize an objective function that is differentiable, with the parameters representing the variables to optimize. This formulation arises in unconstrained optimization problems where the goal is to find .[7] The gradient of the function, denoted , is the vector of partial derivatives: This vector points in the direction of steepest ascent, so the method proceeds by moving in the opposite direction to reduce . The core update rule of gradient descent is the iterative step where indexes the iteration, is an initial parameter vector, and is the step size (also called the learning rate) at step .[7] In the basic form, is fixed as a constant , though more advanced schemes adjust it dynamically. Convergence of this method relies on certain assumptions about . Specifically, must be continuously differentiable, ensuring the gradient exists and is well-behaved everywhere in the domain.[7] Additionally, the gradient is assumed to be Lipschitz continuous with constant , meaning for all . Under these conditions, if is convex and , the iterates converge to a minimizer at a rate of in function value.[7] To illustrate the formulation, consider the quadratic objective where is symmetric positive definite and . The gradient simplifies to , and applying the update rule yields a sequence that solves the linear system in the limit as , provided , where is the largest eigenvalue of . This example highlights how gradient descent systematically reduces the function value toward the unique minimum .[7]Standard Batch Gradient Descent
Algorithm Description
Batch gradient descent, also known as vanilla gradient descent, is an iterative optimization algorithm that minimizes an objective function by repeatedly computing the gradient using the entire training dataset and updating the parameters in the direction opposite to the gradient. The process begins with the selection of an initial parameter vector θ₀, which is often chosen randomly from a normal or uniform distribution to avoid poor starting points that could lead to suboptimal convergence, or set to zero for simplicity in certain convex problems.[8][9] In each iteration, the algorithm evaluates the gradient of the loss function ∇f(θ) with respect to the parameters θ across all n training samples, ensuring a precise estimate of the direction of steepest descent for the full dataset. The parameters are then updated according to the rule θ ← θ - η ∇f(θ), where η is the learning rate, a positive scalar that controls the step size and must be carefully chosen to balance convergence speed and stability. This full-batch computation repeats until a convergence criterion is met, such as the norm of the gradient falling below a small tolerance ε (e.g., ||∇f(θ)|| < ε), indicating that the parameters are near a stationary point, or after a fixed number of iterations to prevent excessive computation.[8][9] The following pseudocode outlines the core procedure:Initialize parameters θ ← θ₀ (e.g., random or zero)
Set learning rate η > 0 and tolerance ε > 0
While ||∇f(θ)|| ≥ ε:
Compute [gradient](/page/Gradient) ∇f(θ) = (1/n) Σ_{i=1}^n ∇f(θ; x_i, y_i) over entire [dataset](/page/Data_set)
Update θ ← θ - η ∇f(θ)
Return θ
Initialize parameters θ ← θ₀ (e.g., random or zero)
Set learning rate η > 0 and tolerance ε > 0
While ||∇f(θ)|| ≥ ε:
Compute [gradient](/page/Gradient) ∇f(θ) = (1/n) Σ_{i=1}^n ∇f(θ; x_i, y_i) over entire [dataset](/page/Data_set)
Update θ ← θ - η ∇f(θ)
Return θ
Linear Systems Solution
Batch gradient descent applied to linear regression problems provides an iterative method for solving linear systems of the form , where is an matrix with , by minimizing the least-squares objective . The gradient of this objective is , and each iteration updates , where is typically chosen via exact line search to minimize along the direction, yielding .[7] This process is equivalent to gradient descent on the quadratic function , assuming is symmetric positive definite (which holds if has full column rank). The minimizer satisfies the normal equations , and the method converges linearly to this solution, with the error reduction factor bounded by , where and are the smallest and largest eigenvalues of .[7] Geometrically, each iteration of steepest descent projects the current residual onto a direction aligned with the negative gradient , which is simpler than the -orthogonal projections in conjugate gradient methods but still reduces the residual norm progressively. The update direction at step is parallel to , and successive residuals satisfy under exact line search, ensuring orthogonality between the new residual and the previous residual (and thus the previous update direction).[10][7] For a fixed step size , convergence is guaranteed if , where is the largest eigenvalue of ; the optimal fixed step size that minimizes the worst-case convergence rate is . This choice ensures monotonic decrease in the objective for symmetric positive definite and achieves the tightest linear convergence bound among constant-step variants.[7]Stochastic and Mini-Batch Variants
Stochastic Gradient Descent
Stochastic gradient descent (SGD) approximates the gradient of the objective function by using the gradient from a single randomly selected training example at each iteration . The parameter update is given by where is the learning rate. This approach, introduced as a stochastic approximation method, enables efficient optimization for large-scale problems by avoiding the need to compute the full gradient over the entire dataset.[11][12] The stochastic gradient serves as an unbiased estimator of the true gradient , satisfying , where the expectation is taken over the random selection of . Despite this unbiasedness, the estimator exhibits high variance, which introduces noise into the optimization trajectory and can cause oscillations around the minimum. This variance is a key characteristic that distinguishes SGD from batch gradient descent, where the full gradient provides a low-variance but computationally expensive update.[11][12] To ensure convergence, particularly in non-convex settings, the learning rate is typically scheduled to decay over iterations, such as , where is an initial rate. Under suitable assumptions like Lipschitz continuity of the gradients and bounded variance, this scheduling yields an expected convergence rate of for the gradient norm .[13] SGD offers significant advantages in computational efficiency, with each iteration requiring only time complexity, where is the parameter dimension, making it scalable to massive datasets processed on-the-fly. The inherent noise from the stochastic estimates also aids in escaping sharp local minima, promoting exploration of the loss landscape toward better solutions. For instance, in logistic regression for binary classification, the update uses the gradient of the cross-entropy loss for one data point , given by , where is the sigmoid function.[12][14]Mini-Batch Gradient Descent
Mini-batch gradient descent is a variant of gradient descent that computes the gradient estimate as the average over a small subset, or mini-batch, of the training data, serving as a compromise between the full-batch approach and stochastic gradient descent. This method updates the model parameters using the rule , where is the mini-batch size, is the learning rate at iteration , and is the gradient of the loss function for the -th example in the batch.[5] The choice of mini-batch size balances computational efficiency, gradient accuracy, and training stability, with reducing to stochastic gradient descent and (the full dataset size) corresponding to batch gradient descent; in deep learning applications, typical values range from 32 to 256, often selected as powers of 2 to align with hardware memory allocation. Smaller batches introduce more noise in the gradient estimate, which can act as a form of regularization but may necessitate smaller learning rates to maintain stability, while larger batches provide more accurate gradients at the cost of increased memory usage.[5] Compared to stochastic gradient descent, mini-batch gradient descent exhibits lower gradient variance due to the averaging over multiple samples, which reduces the noise by a factor of approximately , though this variance remains higher than in full-batch gradient descent; this trade-off enables more stable updates while still allowing for frequent parameter adjustments. Additionally, mini-batches facilitate parallel computation on GPUs, as the gradients for samples within a batch can be computed simultaneously, improving training throughput for large-scale models.[5] Training with mini-batch gradient descent typically proceeds in epochs, where each epoch constitutes one complete pass through the entire training dataset, divided into non-overlapping mini-batches; to ensure unbiased gradient estimates and prevent overfitting to data order, the dataset is randomly shuffled before forming mini-batches at the start of each epoch. Empirically, this approach yields smoother convergence curves than stochastic gradient descent by mitigating erratic updates, while being faster than full-batch gradient descent for large datasets due to reduced per-iteration computation time and better hardware utilization.[5]Accelerated and Modified Methods
Momentum Method
The momentum method, also known as the heavy-ball method, modifies standard gradient descent by incorporating a velocity term that accumulates momentum from past updates, thereby accelerating convergence particularly in challenging landscapes.[15] Introduced by Boris T. Polyak in 1964 for solving systems of linear equations and optimizing quadratic functions, this technique draws an analogy to a heavy ball rolling down a potential valley, where inertia from prior motion helps overcome local oscillations and maintain progress along the primary descent direction.[15][9] The update rule for the momentum method is defined as follows: where is the momentum coefficient that weights the previous velocity, is the learning rate, and represents the accumulated velocity (initialized to zero).[15][9] This formulation effectively averages gradients over recent steps, smoothing the trajectory and reducing sensitivity to noise in the gradient estimates compared to vanilla gradient descent.[9] For quadratic objective functions with eigenvalues bounded between strong convexity parameter and smoothness constant , Polyak derived optimal hyperparameters to achieve accelerated convergence, including , which yields a geometric convergence rate superior to that of standard gradient descent for high condition numbers .[15] In practical implementations, especially in machine learning, a fixed momentum coefficient of is commonly used, often in conjunction with a decaying learning rate (e.g., linearly or exponentially reduced over iterations) to stabilize training and prevent divergence.[9] This method significantly reduces the number of iterations needed for convergence in ill-conditioned problems, where narrow ravines in the loss landscape cause standard gradient descent to oscillate and progress slowly; the momentum term dampens these oscillations while building speed in the flatter dimensions.[15]Nesterov Accelerated Gradient
Nesterov Accelerated Gradient (NAG), also known as Nesterov's method, is an optimization technique that enhances the momentum method by incorporating a lookahead step to evaluate the gradient at an anticipated future position, thereby achieving faster convergence rates for convex optimization problems.[17] Introduced by Yurii Nesterov in 1983, this approach addresses limitations in classical gradient descent by accelerating the search process through a combination of momentum and predictive adjustments.[17] The core intuition behind NAG lies in its use of a "lookahead" mechanism, where the gradient is computed not at the current parameters but at a point extrapolated based on previous momentum, allowing the algorithm to anticipate and reduce overshooting in the optimization trajectory. This predictive evaluation helps dampen oscillations and directs updates more efficiently toward the minimum, particularly in scenarios with smooth convex functions.[18] The update rules for NAG are defined as follows: Here, represents the parameters at iteration , is the learning rate, is the momentum coefficient (typically set to a value like 0.9), and is the gradient of the objective function evaluated at the lookahead point .[18] Theoretically, NAG achieves an optimal convergence rate of for smooth convex functions, improving upon the rate of vanilla gradient descent and providing a quadratic speedup in terms of iterations required to reach a given accuracy.[17] In implementation, NAG is equivalent to the standard momentum method but differs by adjusting the point of gradient computation to the lookahead position, which can be realized with minimal modifications to momentum-based code.[18] This method is commonly employed in optimization tasks in machine learning, including computer vision.Adaptive Optimization Techniques
RMSprop
RMSprop is an adaptive variant of gradient descent that normalizes the learning rate for each parameter by the root mean square of recent gradient magnitudes, enabling efficient handling of parameters with disparate scales and sparse updates. Proposed by Geoffrey Hinton in a 2012 lecture series on neural networks for machine learning, it addresses limitations in earlier adaptive methods like AdaGrad by using an exponentially decaying average rather than a cumulative sum of squared gradients, preventing premature decay of the learning rate. This makes RMSprop particularly suited to non-stationary optimization problems, such as training recurrent neural networks (RNNs), where gradient statistics shift over time.[19] The core of RMSprop lies in its update mechanism for the exponentially weighted moving average of squared gradients, denoted , which captures the magnitude of recent gradients without accumulating all past information: Here, represents the gradient of the objective function with respect to the parameters at timestep , and is the decay rate that controls the memory of past gradients. The parameters are then updated as: where is the global learning rate and is a small constant to avoid division by zero. Typical hyperparameter values include for the decay rate, for the learning rate, and for numerical stability. These choices ensure a balance between adapting to recent gradient information and maintaining robustness across iterations. Intuitively, RMSprop scales the effective learning rate inversely with the root mean square of recent gradients, allowing larger steps in directions where gradients are small or sparse—such as in high-dimensional spaces with many near-zero components—while constraining updates where gradients are large. This per-parameter adaptation reduces the need for manual hyperparameter tuning, as the algorithm automatically compensates for varying gradient scales across different model components. Compared to standard stochastic gradient descent, which can suffer from high variance in noisy or sparse settings, RMSprop provides more stable progress by normalizing these fluctuations. Among its key advantages, RMSprop excels in environments with ill-conditioned or non-stationary objectives by adapting learning rates dynamically, leading to faster convergence without the aggressive decay seen in cumulative methods. It has been widely adopted in deep learning frameworks for its simplicity and effectiveness in training models on complex datasets, though it requires careful selection of the decay rate to avoid over-smoothing recent gradients.Adam Optimizer
The Adam optimizer is a stochastic gradient-based optimization algorithm designed for training machine learning models, particularly deep neural networks, by adaptively estimating lower-order moments of the gradients. Introduced by Diederik P. Kingma and Jimmy Ba in 2014, it combines the concepts of momentum from classical gradient descent variants and adaptive learning rates from methods like RMSprop, enabling efficient convergence in noisy or sparse gradient environments.[20] At its core, Adam maintains adaptive estimates of the first moment (mean) and second moment (uncentered variance) of the gradients, which allow for per-parameter learning rates that adjust dynamically based on the historical gradient information. This provides a robust mechanism for handling the varying scales and noise typical in deep learning optimization, leading to faster training and better generalization compared to fixed-rate methods.[20] The update rule for Adam proceeds in two main steps: first computing exponentially decaying averages of the gradient and its square, followed by bias correction to account for initialization biases, especially in early iterations. Specifically, the first moment estimate is updated as: and the second moment estimate as: where is the stochastic gradient at timestep , and are exponential decay rates. Bias-corrected estimates are then: Finally, the parameters are updated via: with learning rate and small constant for numerical stability. This formulation ensures that the effective learning rate is inversely proportional to the root-mean-square of recent gradients, promoting stability.[20] Default hyperparameters recommended for Adam include , , , and , which have been shown to work well across a variety of deep learning tasks without extensive tuning.[20] Due to its empirical effectiveness and ease of implementation, Adam has become one of the most widely adopted optimizers in neural network training, and both Adam and its variant AdamW have become the default optimizers for training large-parameter AI models, such as transformers and large language models, with its original paper garnering over 150,000 citations as of 2024.[21][22][23] A notable variant is AdamW, proposed by Ilya Loshchilov and Frank Hutter in 2017, which decouples weight decay regularization from the adaptive learning rate updates to better align with the original intent of L2 regularization in stochastic settings. AdamW has become the undisputed default optimizer for training large language models due to its superior regularization properties. This modification improves generalization in tasks like natural language processing and computer vision by applying weight decay directly to parameters rather than incorporating it into the gradient, often leading to superior performance over standard Adam when regularization is needed.[24][25]Theoretical Analysis
Convergence Properties
Gradient descent exhibits well-established convergence properties under specific assumptions on the objective function . For a convex and -smooth function (meaning the gradient is Lipschitz continuous with constant ), batch gradient descent with step size converges to the global minimum at a sublinear rate of , where is the number of iterations; specifically, the function value satisfies , with denoting the minimizer.[26] This rate is derived from the descent lemma and convexity, ensuring monotonic decrease toward the optimum. For -strongly convex and -smooth functions, batch gradient descent achieves linear convergence, with under appropriate step sizes. In the stochastic setting, for convex and -smooth objectives, stochastic gradient descent (SGD) achieves an expected convergence rate of to the global minimum, assuming bounded variance in the stochastic gradients; this slower rate compared to batch methods arises from the inherent noise, but appropriate step size schedules like diminishing yield the bound , where is an average of iterates.[26] Variance reduction techniques can improve this, but the standard SGD rate holds under these assumptions.[27] Accelerated variants, such as Nesterov's accelerated gradient, attain faster rates for strongly convex objectives. For -strongly convex and -smooth functions (with condition number ), Nesterov's method converges at , specifically , by incorporating momentum to achieve optimal first-order oracle complexity.[28] For non-convex -smooth functions, gradient descent converges to a stationary point where in expectation (for SGD) or deterministically, requiring iterations; however, no global minimum guarantee exists, as local minima or saddles may trap the algorithm.[26] In SGD, the inherent noise enables escape from saddle points with high probability, facilitating progress toward better stationary points in non-convex landscapes. Recent analyses in the 2020s for over-parameterized models, such as deep neural networks, reveal that gradient descent induces implicit regularization, converging to solutions that minimize norms or promote sparsity beyond explicit penalties; for instance, in over-parameterized linear regression, full-batch GD preferentially finds minimum-norm solutions, akin to regularization, under interpolation regimes. These results highlight how continuous-time limits and initialization scales influence the implicit bias toward generalized solutions in high dimensions.Geometric Interpretations
Gradient descent can be geometrically interpreted as following the direction of steepest descent on the surface defined by the objective function, often visualized using contour plots that represent level sets of constant function value. In such plots, particularly for ill-conditioned quadratic functions with elongated valleys, the algorithm's path exhibits a characteristic zigzagging behavior, where updates alternate between the two principal axes of the valley, leading to slow progress toward the minimum.[29] This oscillation arises because each gradient step is orthogonal to the previous one, causing the trajectory to bounce between the valley walls rather than proceeding directly downhill.[29] In the linear case, where gradient descent solves systems of the form by minimizing the quadratic , the update directions span the Krylov subspace generated by the initial residual and powers of . Specifically, the residuals at successive iterations are mutually orthogonal, ensuring that each new residual is perpendicular to all previous ones, which geometrically projects the error onto increasingly refined subspaces orthogonal to the range of prior updates. Furthermore, these residuals are perpendicular to for previous iterates , reflecting the method's progressive orthogonalization against the matrix-weighted gradients.[29] The momentum method introduces a geometric smoothing to these trajectories by incorporating a velocity term that accumulates past updates, akin to a heavy ball rolling down the optimization landscape. In quadratic bowls, this results in less oscillatory paths compared to vanilla gradient descent, as the inertia dampens the zigzagging and allows the algorithm to maintain direction through flat regions or narrow passes, leading to more direct convergence along the valley floor.[30] Visualizations of such dynamics reveal coupled oscillatory modes where momentum parameters control the damping of ripples, enabling larger effective step sizes without divergence.[30] Stochastic gradient descent produces jagged trajectories due to the noisy estimates of the gradient from individual samples, causing the path to deviate erratically around the true minimum in contour plots. Despite this noise, multiple stochastic runs average to approximate the smoother trajectory of full-batch gradient descent, providing a geometric intuition for why the method converges in expectation while exploring the landscape more broadly.[5] Two-dimensional visualizations of gradient descent on non-convex functions, such as the Rosenbrock banana-shaped surface, illustrate convergence basins as regions from which trajectories flow toward local minima, with the algorithm's path curving along contours to settle in the nearest attractor. At saddle points, where the gradient vanishes but curvature changes sign, pure gradient descent may slow dramatically, but stochastic perturbations enable escapes by injecting noise that pushes the trajectory out of the flat direction, as seen in simulated paths that veer toward lower regions rather than stagnating.[5][31]References
- https://arxiv.org/pdf/1609.04747
