Gradient descent is a method for unconstrained mathematical optimization. It is a first-order iterative algorithm for finding a local minimum of 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 local maximum of 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.
A simple extension of gradient descent, stochastic gradient descent, serves as the most basic algorithm used for training most deep networks today.
F(x)
a
F(x)
a
F
a,-\nablaF(a)
an+1=an-\gamma\nablaF(an)
\gamma\in\R+
F(an)\geq |
F(an+1) |
\gamma\nablaF(a)
a
x0
F
x0,x1,x2,\ldots
xn+1=xn-\gamman\nablaF(xn), n\ge0.
We have a monotonic sequence
F(x0)\geF(x1)\geF(x2)\ge … ,
so, hopefully, the sequence
(xn)
\gamma
It is possible to guarantee the convergence to a local minimum under certain assumptions on the function
F
F
\nablaF
\gamma
\gamman=
\left|\left(xn-xn-1\right)T\left[\nablaF(xn)-\nablaF(xn-1)\right]\right| | |
\left\|\nablaF(xn)-\nablaF(xn-1)\right\|2 |
as in the Barzilai-Borwein method,[6] [7] or a sequence
\gamman
F
This process is illustrated in the adjacent picture. Here,
F
F
F
The basic intuition behind gradient descent can be illustrated by a hypothetical scenario. Persons 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 persons happen to have at the 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 wanted 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 not to go off track.
In this analogy, the persons 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.
Since using a step size
\gamma
\gamma
\gamma
To reason about this mathematically, consider a direction
pn
\gamman
an+1=an-\gammanpn
pn
\gamman
\thetan
-\nabla
F(an) |
pn
\cos\thetan>0.
F
F
In principle inequality could be optimized over
pn
\gamman
\nablaF(an-t\gammanpn)
pn=\nabla
F(an) |
\gamman
pn
\gamman
F
\nabla2F
\|\nablaF(an-t\gammanpn)-\nablaF(an)\|2 ≈ \|t\gamman\nabla2F(an)pn\|.
pn
\gamman
\nablaF
L
\|\nablaF(an-t\gammanpn)-\nablaF(an)\|2\leqLt\gamman\|pn\|.
pn
\gamman
maxt\in[0,1]
\|\nablaF(an-t\gammanpn)-\nablaF(an)\|2 | |
\|\nablaF(an)\|2 |
F
pn
\gamman
F
Usually by following one of the recipes above, convergence to a local minimum can be guaranteed. When the function
F
Gradient descent can be used to solve a system of linear equations
Ax-b=0
reformulated as a quadratic minimization problem.If the system matrix
A
F(x)=xTAx-2xTb,
so that
\nablaF(x)=2(Ax-b).
For a general real matrix
A
F(x)=\left\|Ax-b\right\|2.
In traditional linear least squares for real
A
b
\nablaF(x)=2AT(Ax-b).
The line search minimization, finding the locally optimal step size
\gamma
\gamma
For example, for real symmetric and positive-definite matrix
A
\begin{align} &repeatintheloop:\\ & r:=b-Ax\\ & \gamma:={rTr
To avoid multiplying by
A
x:=x+\gammar
r:=r-\gammaAr
\begin{align} &r:=b-Ax\\ &repeatintheloop:\\ & \gamma:={rTr
\kappa(A)
A
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
\begin{cases} 3x1-\cos(x2x3)-\tfrac{3}{2}=0
2+2x | |
\\ 4x | |
2-1 |
=0\\ \exp(-x1x2)+20x3+\tfrac{10\pi-3}{3}=0 \end{cases}
Let us introduce the associated function
G(x)=\begin{bmatrix} 3x1-\cos(x2x3)-\tfrac{3}{2}
2+2x | |
\\ 4x | |
2-1 |
\\ \exp(-x1x2)+20x3+\tfrac{10\pi-3}{3}\\ \end{bmatrix},
where
x=\begin{bmatrix} x1\\ x2\\ x3\\ \end{bmatrix}.
One might now define the objective function
\begin{align}F(x)&=
1 | |
2 |
GT(x)G(x)\\&=
1 | |
2 |
\left[\left(3x1-\cos(x2x
|
\right)2+
2+2x | |
\left(4x | |
2-1 |
\right)2+\right.\\ &{} \left.\left(\exp(-x1x2)+20x3+
10\pi-3 | |
3 |
\right)2\right],\end{align}
which we will attempt to minimize. As an initial guess, let us use
x(0)=0=\begin{bmatrix} 0\\ 0\\ 0\ \end{bmatrix}.
We know that
x(1)=0-\gamma0\nablaF(0)=0-\gamma0
T | |
J | |
G(0) |
G(0),
JG
JG(x)=\begin{bmatrix} 3&\sin(x2x3)x3&\sin(x2x3)x2\\ 8x1&-1250x2+2&0\\ -x2\exp{(-x1x2)}&-x1\exp(-x1x2)&20\\ \end{bmatrix}.
We calculate:
JG(0)=\begin{bmatrix} 3&0&0\\ 0&2&0\\ 0&0&20 \end{bmatrix}, G(0)=\begin{bmatrix} -2.5\\ -1\\ 10.472 \end{bmatrix}.
Thus
x(1)=0-\gamma0\begin{bmatrix} -7.5\\ -2\\ 209.44 \end{bmatrix},
and
F(0)=0.5\left((-2.5)2+(-1)2+(10.472)2\right)=58.456.
Now, a suitable
\gamma0
F\left(x(1)\right)\leF\left(x(0)\right)=F(0).
This can be done with any of a variety of line search algorithms. One might also simply guess
\gamma0=0.001,
x(1)=\begin{bmatrix} 0.0075\\ 0.002\\ -0.20944\\ \end{bmatrix}.
Evaluating the objective function at this value, yields
F\left(x(1)\right)=0.5\left((-2.48)2+(-1.00)2+(6.28)2\right)=23.306.
The decrease from
F(0)=58.456
F\left(x(1)\right)=23.306
is a sizable decrease in the objective function. Further steps would reduce its value further until an approximate solution to the system was found.
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.[13]
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 combined with a line search, finding the locally optimal step size
\gamma
\gamma
\gamma
Methods based on Newton's method and inversion of the Hessian using conjugate gradient techniques can be better alternatives.[16] [17] 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
\gamma.
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.
x'(t)=-\nablaf(x(t))
x'(t)=u(t)
u(t)
u(t)=-\nablaf(x(t))
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.
Yurii Nesterov has proposed[19] 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
F
\nablaF
F
k
l{O}\left({k-2
For constrained or non-smooth problems, Nesterov's FGM is called the fast proximal gradient method (FPGM), an acceleration of the proximal gradient method.
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, or to mass movement in Newtonian dynamics through a viscous medium in a conservative force field.[24] 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.
This technique is used in stochastic gradient descent and as an extension to the backpropagation algorithms used to train artificial neural networks.[25] [26] In the direction of updating, stochastic gradient descent adds a stochastic property. The weights can be used to calculate the derivatives.
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).[27]
Gradient descent is a special case of mirror descent using the squared Euclidean distance as the given Bregman divergence.[28]
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.[29] 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.