Dictionary of Applied Machine Learning: 114 machine-learning terms, each with a definition, a figure, citations and a Python demo · All terms · Demos · Start here

gradient descent (GD)

Updated on 2026-11-02

Readiness 100/100

▶ Run the Python demo Open in Colab Typeset PDF LaTeX source Markdown Cite this entry

See also gradient stochastic gradient descent convex

Gradient descent (GD) is an iterative algorithm for minimizing a differentiable function $f: \mathbb{R}^{d} \rightarrow \mathbb{R}$. Each iteration updates the current estimate by a step along the negative gradient, scaled by a step size $\eta$. 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.

Figure produced by the Python demo of the entry gradient descent (GD)
Figure written by the entry's Python demo gd.py, which recomputes what the entry states: the script block by block · open in Colab

Definition

When training a deep net for image recognition, the average loss incurred by the network on a training set of labeled images is a function $f({\mathbf w})$ of the vector ${\mathbf w} \in \mathbb{R}^{d}$ of its model parameters, and training means minimizing that function. Many machine learning (ML) applications amount to such an optimization problem: an objective function $f: \mathbb{R}^{d} \rightarrow \mathbb{R}$ measures the quality of the model parameters ${\mathbf w}$, which are the optimization variable. Minimizing $f$ on the training set is a proxy: the goal is a small loss on data points outside it (see generalization).

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

GD uses this local linear approximation to improve the current choice of the model parameters iteratively. Starting from an initialization ${\mathbf w}^{(0)}$, it generates a sequence of estimates ${\mathbf w}^{(0)}, {\mathbf w}^{(1)}, {\mathbf w}^{(2)}, \ldots$ that ideally converge to a minimum of $f$. At each iteration $t$, GD refines the current estimate ${\mathbf w}^{(t)}$ by stepping in the direction of steepest descent of the local linear approximation to $f$ at ${\mathbf w}^{(t)}$. This direction is the negative gradient $\nabla f({\mathbf w}^{(t)})$, giving the update \begin{equation} \label{equ_def_GD_step_dict} {\mathbf w}^{(t+1)} = {\mathbf w}^{(t)} - \eta \nabla f({\mathbf w}^{(t)}) \text{,} \end{equation} where $\eta > 0$ is a step size; the update is a gradient step with step size $\eta$. For a sufficiently small $\eta$, each step decreases the function value, $f({\mathbf w}^{(t+1)}) \le f({\mathbf w}^{(t)})$, with strict decrease whenever $\nabla f({\mathbf w}^{(t)}) \neq \mathbf{0}$ (Boyd and Vandenberghe, 2004, Sect. 9.3). GD and its variants are the standard solvers for model training in deep learning (Goodfellow et al., 2016). Fig. 1 illustrates a single GD step. Algorithm 1 states the method in full.

Algorithm 1 of the entry gd
Algorithm 1: Gradient descent
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 $\eta$, held fixed across iterations, a single step is described by the GD step operator $\mathcal{F}^{(\eta)}({\mathbf w}) = {\mathbf w} - \eta \nabla f({\mathbf w})$, so GD is the fixed-point iteration ${\mathbf w}^{(t+1)} = \mathcal{F}^{(\eta)}({\mathbf w}^{(t)})$. Its fixed points, where $\mathcal{F}^{(\eta)}({\mathbf w}) = {\mathbf w}$, are exactly the stationary points $\nabla f({\mathbf w}) = \mathbf{0}$. For convex $f$, these are the minima according to the zero-gradient condition (Boyd and Vandenberghe, 2004, Sect. 4.2.3).

The convergence of the fixed-point iteration ${\mathbf w}^{(t+1)} = \mathcal{F}^{(\eta)}({\mathbf w}^{(t)})$ is governed by the properties of the GD step operator $\mathcal{F}^{(\eta)}$. Assume $f$ is convex and its gradient is $L$-Lipschitz continuous, i.e., \[\Vert {\nabla f({\mathbf w}) - \nabla f({\mathbf w}')} \Vert \le L\,\Vert {{\mathbf w} - {\mathbf w}'} \Vert \quad \text{for all } {\mathbf w}, {\mathbf w}' \in \mathbb{R}^{d} \text{.}\] For $0 < \eta \le 1/L$, the operator $\mathcal{F}^{(\eta)}$ is then a non-expansive operator with respect to the Euclidean norm $\Vert {\cdot} \Vert$: it does not increase distances between any two points ${\mathbf w}, {\mathbf w}'$, \[\Vert {\mathcal{F}^{(\eta)}({\mathbf w}) - \mathcal{F}^{(\eta)}({\mathbf w}')} \Vert \le \Vert {{\mathbf w} - {\mathbf w}'} \Vert \text{.}\] Non-expansiveness alone does not guarantee a unique fixed point (Bauschke and Combettes, 2011, Ch. 4).

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

P-rateHow fast GD converges depends on the curvature of $f$, as quantified by the constants $L$ and $\mu$ above. Let $\widehat{{\mathbf w}}$ be a minimizer and $f^{\star} = f(\widehat{{\mathbf w}})$. For convex $f$ with $L$-Lipschitz gradient and the constant step size $\eta = 1/L$ (Beck, 2017, Ch. 10; Bubeck, 2015, Thm. 3.3), \[ f\big({\mathbf w}^{(T)}\big) - f^{\star} \le \frac{L\,\Vert {{\mathbf w}^{(0)} - \widehat{{\mathbf w}}} \Vert^{2}}{2\,T} \text{,} \] so the suboptimality after $T$ steps falls in proportion to $1/T$: 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({\mathbf w}^{(T)}\big) - f^{\star} \le \left(1 - \tfrac{\mu}{L}\right)^{T} \big(f({\mathbf w}^{(0)}) - f^{\star}\big) \text{,} \] consistent with the contractive operator factor $1 - \mu\eta$ above (Boyd and Vandenberghe, 2004, Sect. 9.3; Bubeck, 2015, Thm. 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, improve both bounds.

The iteration also has a continuous-time counterpart. Consider shrinking the step size $\eta$ in the GD step \(\eqref{equ_def_GD_step_dict}\) toward zero. For $\eta \to 0$, the iterate ${\mathbf w}^{(t)}$ converges to ${\mathbf w}(t \eta)$, the value at time $t \eta$ of the continuous-time trajectory ${\mathbf w}(\tau)$ that satisfies the ordinary differential equation $\dot{{\mathbf w}}(\tau) = -\nabla f({\mathbf w}(\tau))$, known as gradient flow. In particular, GD is the explicit Euler discretization of this gradient flow with step $\eta$ (Helmke and Moore, 1994). Replacing the time derivative $\dot{{\mathbf w}}(\tau)$ by the difference quotient $\big({\mathbf w}^{(t+1)} - {\mathbf w}^{(t)}\big)/\eta$ 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 discrete iteration, 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 $\alpha \left\lVert {\mathbf w} \right\rVert_{1}$ is non-smooth. Second, in empirical risk minimization (ERM)-based methods, $f$ is an average of $m$ loss functions, one for each data point, so evaluating the full gradient sums $m$ gradients and its cost grows in proportion to the training set size $m$. GD is thus replaced by stochastic gradient descent (SGD), which uses a gradient estimate from a random subset of the training set at each step.

P-momentumMomentum 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, \[ {\mathbf w}^{(t+1)} = {\mathbf w}^{(t)} - \eta \nabla f({\mathbf w}^{(t)}) + \beta\big({\mathbf w}^{(t)} - {\mathbf w}^{(t-1)}\big) \text{, for } t=1,\ldots. \] For a strongly convex quadratic $f$, this iteration converges faster than plain GD (Polyak, 1987). Fig. 3 compares plain GD with the heavy-ball method 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/T$ bound above for convex $f$ with $L$-Lipschitz gradient to \[ f\big({\mathbf w}^{(T)}\big) - f^{\star} \le \frac{2\,L\,\Vert {{\mathbf w}^{(0)} - \widehat{{\mathbf w}}} \Vert^{2}} {(T+1)^{2}} \text{.} \] In contrast to the bound for plain gradient descent (GD), which falls in proportion to $1/T$, this bound falls in proportion to $1/T^{2}$ (Beck and Teboulle, 2009, Thm. 4.4; Bubeck, 2015, Thm. 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, Thm. 3.18).

See also: gradient, step size, stochastic gradient descent, subgradient descent, subgradient, gradient flow, convex, strongly convex, fixed point.

References

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

Cite this entry

@misc{dictml_gd,
  author = {Jung, Alexander},
  editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {gradient descent (GD)},
  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-11-04},
  url = {https://dictionaryofml.org/terms/gd.html}
}