Dictionary of Applied Machine Learning

gradient descent

Typeset PDF version — the authoritative form of this entry

Gradient descent (GD) is an iterative algorithm for minimizing a differentiable function $f: \reals^{\nrfeatures} \rightarrow \reals$. Each iteration updates the current estimate by a step along the negative gradient, scaled by a step size $\lrate$. Such a gradient step can be interpreted as the application of an operator that is parameterized by the step size and the underlying function. GD and its variants are widely used to train parametric models in deep learning.

Definition

Many machine learning (ML) applications amount to solving an optimization problem: an objective function $f: \reals^{\nrfeatures} \rightarrow \reals$ measures the quality of the vector $\weights \in \reals^{\nrfeatures}$ of model parameters, which is the optimization variable. When training a deep net for image recognition, for example, $f(\weights)$ is the average loss incurred by the network on a training set of labeled images.

In many important cases, the objective function is differentiable: at every point $\weights$ there exists a gradient $\nabla f(\weights) \in \reals^{\nrfeatures}$, the vector of partial derivatives of $f$ at $\weights$, which determines a local linear approximation of $f$ (see differentiable).

GD uses this local linear approximation to iteratively improve the current choice of the model parameters: starting from an initialization $\weights^{(0)}$, GD generates a sequence of estimates $\weights^{(0)}, \weights^{(1)}, \weights^{(2)}, \ldots$ that ideally converge to a minimum of $f$. GD and its variants are the standard solvers for model training in deep learning (Goodfellow et al., 2016).

At each iteration $\iteridx$, GD refines the current estimate $\weights^{(\iteridx)}$ by stepping in the direction of steepest descent of the local linear approximation to $f$ at $\weights^{(\iteridx)}$. This direction is the negative gradient $\nabla f(\weights^{(\iteridx)})$, giving the update \begin{equation} \label{equ_def_GD_step_dict} \weights^{(\iteridx+1)} = \weights^{(\iteridx)} - \lrate \nabla f(\weights^{(\iteridx)}) \text{,} \end{equation} where $\lrate > 0$ is a step size. For a sufficiently small $\lrate$, each step decreases the function value, $f(\weights^{(\iteridx+1)}) \le f(\weights^{(\iteridx)})$, with strict decrease whenever $\nabla f(\weights^{(\iteridx)}) \neq \mathbf{0}$ (Boyd and Vandenberghe, 2004, Sect. 9.3). Fig. 1 illustrates a single GD step.

Figure 1 of the entry gd
Figure 1: A single gradient step \(\eqref{equ_def_GD_step_dict}\) toward the minimizer $\widehat{\weights}$ of $f(\weights)$. The curve depicts the function $f$. The straight line is its local linear approximation at the current estimate $\weights^{(\iteridx)}$. A change $\Delta \weights$ of the estimate $\weights^{(\iteridx)}$ changes this approximation by $\big(\Delta \weights\big)^{\top} \nabla f(\weights^{(\iteridx)})$. Stepping against the gradient by $-\lrate \nabla f(\weights^{(\iteridx)})$ yields the next estimate $\weights^{(\iteridx+1)}$
With a constant step size $\lrate$, held fixed across iterations, a single step is described by the GD step operator $\gdstep{\lrate}(\weights) = \weights - \lrate \nabla f(\weights)$, so GD is the fixed-point iteration $\weights^{(\iteridx+1)} = \gdstep{\lrate}(\weights^{(\iteridx)})$. Its fixed points, where $\gdstep{\lrate}(\weights) = \weights$, are exactly the stationary points $\nabla f(\weights) = \mathbf{0}$. For convex $f$, these are the minima according to the zero-gradient condition (Boyd and Vandenberghe, 2004, Sect. 4.2.3).

Consider shrinking the step size $\lrate$ in the GD step \(\eqref{equ_def_GD_step_dict}\) toward zero. This results in iterates $\weights^{(\iteridx)}$ becoming approximately the values of a continuous-time trajectory $\weights(\tau)$. This trajectory satisfies the ordinary differential equation $\dot{\weights}(\tau) = -\nabla f(\weights(\tau))$, which is known as gradient flow. In particular, GD is the explicit Euler discretization of this gradient flow with step $\lrate$ (Helmke and Moore, 1994). Indeed, replacing the time derivative $\dot{\weights}(\tau)$ by the difference quotient $\big(\weights^{(\iteridx+1)} - \weights^{(\iteridx)}\big)/\lrate$ recovers the update \(\eqref{equ_def_GD_step_dict}\). Fig. 2 illustrates how, for a small step size, the GD iterates closely follow the gradient flow trajectory.

Figure 2 of the entry gd
Figure 2: GD as the explicit Euler discretization of gradient flow, for the quadratic $f(\weights) = \big(\weight_{1}^{2} + 5\,\weight_{2}^{2}\big)/2$ with initialization $\weights^{(0)} = (2, 1.8)^{\top}$. Gray ellipses are level sets of $f$; the solid curve is the exact gradient flow trajectory. For the small step size $\lrate = 0.02$, the GD iterates (dashed, circular marks) follow the trajectory closely. For the large step size $\lrate = 0.3$, the iterates (dotted, square marks) oscillate across the narrow direction of the level sets. Data generated by pythondemos/gd.py
Returning to the fixed-point iteration $\weights^{(\iteridx+1)} = \gdstep{\lrate}(\weights^{(\iteridx)})$, its convergence is governed by the properties of the GD step operator $\gdstep{\lrate}$. Assume $f$ is convex and its gradient is $L$-Lipschitz continuous, i.e., \[\norm{\nabla f(\weights) - \nabla f(\weights')} \le L\,\norm{\weights - \weights'} \quad \text{for all } \weights, \weights' \in \reals^{\nrfeatures} \text{.}\] For $0 < \lrate \le 1/L$, the operator $\gdstep{\lrate}$ is then a non-expansive operator with respect to the Euclidean norm $\norm{\cdot}$: it does not increase distances between any two points $\weights, \weights'$, \[\norm{\gdstep{\lrate}(\weights) - \gdstep{\lrate}(\weights')} \le \norm{\weights - \weights'} \text{.}\] Non-expansiveness alone does not guarantee a unique fixed point (Bauschke and Combettes, 2011, Ch. 4).

Assume, moreover, that $f$ is $\mu$-strongly convex, i.e., the function $f(\weights) - (\mu/2) \norm{\weights}^{2}$ is still convex, so the curvature of $f$ is at least $\mu > 0$ in every direction. Then $\gdstep{\lrate}$ is a contractive operator with respect to the same norm, \[ \norm{\gdstep{\lrate}(\weights) - \gdstep{\lrate}(\weights')} \le (1 - \mu\lrate)\,\norm{\weights - \weights'} \text{.} \] In this case, Banach's fixed-point theorem gives a unique fixed point $\widehat{\weights}$ (the minimizer of $f$) to which GD converges at a geometric rate (Boyd and Vandenberghe, 2004; Nesterov, 2004). For linear regression, these properties are explicit: the gradient of the average squared error loss is an affine function of $\weights$, and the contraction factor of $\gdstep{\lrate}$ is governed by the eigenvalues of the matrix $\featuremtx^{\top}\featuremtx$. Here, $\featuremtx$ denotes the feature matrix, whose rows are the feature vectors of the data points in the training set (see linear regression).

How fast GD converges depends on the curvature of $f$, as quantified by the constants $L$ and $\mu$ above. Let $\widehat{\weights}$ be a minimizer and $f^{\star} = f(\widehat{\weights})$. For convex $f$ with $L$-Lipschitz gradient and the constant step size $\lrate = 1/L$ (Beck, 2017, Ch. 10; Bubeck, 2015, Th. 3.3), \[ f\big(\weights^{(\nriter)}\big) - f^{\star} \le \frac{L\,\norm{\weights^{(0)} - \widehat{\weights}}^{2}}{2\,\nriter} \text{,} \] so the suboptimality after $\nriter$ steps falls in proportion to $1/\nriter$: halving the suboptimality requires doubling the number of iterations. If $f$ is in addition $\mu$-strongly convex, the bound improves to the geometric rate \[ f\big(\weights^{(\nriter)}\big) - f^{\star} \le \left(1 - \tfrac{\mu}{L}\right)^{\nriter} \big(f(\weights^{(0)}) - f^{\star}\big) \text{,} \] consistent with the contractive operator factor $1 - \mu\lrate$ above (Boyd and Vandenberghe, 2004, Sect. 9.3; Bubeck, 2015, Th. 3.10). A geometric rate means that the suboptimality shrinks by at least the constant factor $1 - \mu/L$ in every single iteration. Thus, halving the suboptimality now costs a fixed number of iterations, however small the current suboptimality already is. Momentum methods, discussed below, sharpen both bounds.

In two common settings that motivate variants of GD, the assumptions behind these guarantees fail or the gradient becomes too costly. First, when $f$ is non-smooth, its gradient may fail to exist and GD is replaced by subgradient descent, which steps along a subgradient in place of the gradient. A concrete case is the least absolute shrinkage and selection operator (Lasso) objective, whose penalty term $\regparam \normgeneric{\weights}{1}$ is non-smooth. Second, in empirical risk minimization (ERM)-based methods, $f$ is an average of $\samplesize$ loss functions, one for each data point, so evaluating the full gradient sums $\samplesize$ gradients and its cost grows in proportion to the training set size $\samplesize$. GD is thus replaced by stochastic gradient descent (SGD), which uses a cheap gradient estimate from a random subset of the training set at each step.

Momentum methods provide another generalization of plain GD: each update combines gradients from several past steps rather than the current one alone. The name stems from a physical analogy: the iterates trace a particle whose momentum accumulates the force exerted by the negative gradient of the objective function. One prototypical example of a momentum method is Polyak's heavy-ball method. It adds a fraction $\beta \in [0, 1)$ of the previous increment, \[ \weights^{(\iteridx+1)} = \weights^{(\iteridx)} - \lrate \nabla f(\weights^{(\iteridx)}) + \beta\big(\weights^{(\iteridx)} - \weights^{(\iteridx-1)}\big) \text{, for } \iteridx=1,\ldots. \] For a strongly convex quadratic $f$, this iteration converges faster than plain GD (Polyak, 1987). Fig. 3 compares plain GD and heavy-ball momentum on a strongly convex quadratic function.

Figure 3 of the entry gd
Figure 3: Suboptimality $f(\weights^{(\iteridx)}) - f^{\star}$ of plain GD (solid, circular marks) and heavy-ball momentum (dashed, square marks) on a strongly convex quadratic, shown on a logarithmic scale. Both sequences decay geometrically, which appears as a straight line on this scale. The momentum method shrinks the suboptimality by a smaller factor per iteration and therefore reaches any prescribed accuracy in fewer iterations. Data generated by pythondemos/gd.py
A related momentum algorithm is Nesterov's accelerated variant of GD, which improves the $1/\nriter$ bound above for convex $f$ with $L$-Lipschitz gradient to \[ f\big(\weights^{(\nriter)}\big) - f^{\star} \le \frac{2\,L\,\norm{\weights^{(0)} - \widehat{\weights}}^{2}} {(\nriter+1)^{2}} \text{.} \] In contrast to the bound for plain gradient descent (GD), which falls in proportion to $1/\nriter$, this bound falls in proportion to $1/\nriter^{2}$ (Beck and Teboulle, 2009, Th. 4.4; Bubeck, 2015, Th. 3.19). For $\mu$-strongly convex $f$, acceleration improves the contraction factor from $1 - \mu/L$ to $1 - \sqrt{\mu/L}$ (Nesterov, 2004, Sect. 2.2; Bubeck, 2015, Th. 3.18). See also: gradient step, gradient, step size, SGD, subgradient descent, subgradient, gradient flow, convex, strongly convex, minimum, differentiable, ERM, fixed point, Banach's fixed-point theorem.

References

  1. Goodfellow et al. (2016). Deep Learning. MIT Press.
  2. Boyd and Vandenberghe (2004). Convex Optimization. Cambridge Univ. Press.
  3. Helmke and Moore (1994). Optimization and Dynamical Systems. Springer.
  4. Bauschke and Combettes (2011). Convex Analysis and Monotone Operator Theory in Hilbert Spaces. Springer Science+Business Media.
  5. Nesterov (2004). Introductory Lectures on Convex Optimization: A Basic Course. Kluwer Academic.
  6. Beck (2017). First-Order Methods in Optimization. SIAM-Society for Industrial and Applied Mathematics.
  7. Bubeck (2015). Convex Optimization: Algorithms and Complexity. Found. Trends Mach. Learn..
  8. Polyak (1987). Introduction to optimization. Optimization Software, Inc., Publications Division, New York.
  9. Beck and Teboulle (2009). A fast iterative shrinkage-thresholding algorithm for linear inverse problems. SIAM J. Imaging Sci..

Cite this entry

@misc{dictml_gd,
  author = {Jung, Alexander},
  title = {gradient descent},
  howpublished = {Dictionary of Applied Machine Learning (course edition)},
  year = {2026},
  doi = {10.5281/zenodo.21569296},
  note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-08-06},
  url = {https://dictionaryofml.org/terms/gd.html}
}