Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Gradient descent
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Description== [[File:Gradient descent.svg|thumb|350px|Illustration of gradient descent on a series of [[level set]]s]] Gradient descent is based on the observation that if the [[multi-variable function]] <math>F(\mathbf{x})</math> is [[Defined and undefined|defined]] and [[Differentiable function|differentiable]] in a neighborhood of a point <math>\mathbf{a}</math>, then <math>F(\mathbf{x})</math> decreases ''fastest'' if one goes from <math>\mathbf{a}</math> in the direction of the negative [[gradient]] of <math>F</math> at <math>\mathbf{a}, -\nabla F(\mathbf{a})</math>. It follows that, if :<math> \mathbf{a}_{n+1} = \mathbf{a}_n-\gamma\nabla F(\mathbf{a}_n)</math> for a small enough step size or [[learning rate]] <math>\gamma \in \R_{+}</math>, then <math>F(\mathbf{a_n})\geq F(\mathbf{a_{n+1}})</math>. In other words, the term <math>\gamma\nabla F(\mathbf{a})</math> is subtracted from <math>\mathbf{a}</math> because we want to move against the gradient, toward the local minimum. With this observation in mind, one starts with a guess <math>\mathbf{x}_0</math> for a local minimum of <math>F</math>, and considers the sequence <math>\mathbf{x}_0, \mathbf{x}_1, \mathbf{x}_2, \ldots</math> such that :<math>\mathbf{x}_{n+1}=\mathbf{x}_n-\gamma_n \nabla F(\mathbf{x}_n),\ n \ge 0.</math> We have a [[Monotonic function|monotonic]] sequence :<math>F(\mathbf{x}_0)\ge F(\mathbf{x}_1)\ge F(\mathbf{x}_2)\ge \cdots,</math> so the sequence <math>(\mathbf{x}_n)</math> converges to the desired local minimum. Note that the value of the ''step size'' <math>\gamma</math> is allowed to change at every iteration. It is possible to guarantee the [[Convergent series|convergence]] to a local minimum under certain assumptions on the function <math>F</math> (for example, <math>F</math> [[Convex function|convex]] and <math>\nabla F</math> [[Lipschitz continuity|Lipschitz]]) and particular choices of <math>\gamma</math>. Those include the sequence <math>\gamma_{n} = \frac{ \left | \left (\mathbf x_{n} - \mathbf x_{n-1} \right )^T \left [\nabla F (\mathbf x_{n}) - \nabla F (\mathbf x_{n-1}) \right ] \right |}{\left \|\nabla F(\mathbf{x}_{n}) - \nabla F(\mathbf{x}_{n-1}) \right \|^2}</math> as in the [[Barzilai-Borwein method]],<ref>{{cite journal |last1=Barzilai |first1=Jonathan |last2=Borwein |first2=Jonathan M. |year=1988 |title=Two-Point Step Size Gradient Methods |journal=IMA Journal of Numerical Analysis |volume=8 |issue=1 |pages=141–148 |doi=10.1093/imanum/8.1.141}}</ref><ref>{{cite book |last=Fletcher |first=R. |title=Optimization and Control with Applications |publisher=Springer |year=2005 |isbn=0-387-24254-6 |editor-last=Qi |editor-first=L. |series=Applied Optimization |volume=96 |location=Boston |pages=235–256 |chapter=On the Barzilai–Borwein Method |editor2-last=Teo |editor2-first=K. |editor3-last=Yang |editor3-first=X.}}</ref> or a sequence <math> \gamma_n</math> satisfying the [[Wolfe conditions]] (which can be found by using [[line search]]). When the function <math>F</math> is [[Convex function|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, <math>F</math> is assumed to be defined on the plane, and that its graph has a [[Bowl (vessel)|bowl]] shape. The blue curves are the [[contour line]]s, that is, the regions on which the value of <math>F</math> 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 <math>F</math> is minimal. === An analogy for understanding gradient descent === [[File:Okanogan-Wenatchee National Forest, morning fog shrouds trees (37171636495).jpg|thumb|Fog in the mountains]] 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 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 (mathematics)|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 === Since using a step size <math>\gamma</math> that is too small would slow convergence, and a <math>\gamma</math> too large would lead to overshoot and divergence, finding a good setting of <math>\gamma</math> is an important practical problem. [[Philip Wolfe (mathematician)|Philip Wolfe]] also advocated using "clever choices of the [descent] direction" in practice.<ref>{{cite journal |last1=Wolfe |first1=Philip |title=Convergence Conditions for Ascent Methods |journal=SIAM Review |date=April 1969 |volume=11 |issue=2 |pages=226–235 |doi=10.1137/1011036 }}</ref> 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 <math> \mathbf{p}_n</math> and step size <math> \gamma_n</math> and consider the more general update: :<math> \mathbf{a}_{n+1} = \mathbf{a}_n-\gamma_n\,\mathbf{p}_n</math>. Finding good settings of <math> \mathbf{p}_n</math> and <math> \gamma_n</math> requires some thought. First of all, we would like the update direction to point downhill. Mathematically, letting <math> \theta_n</math> denote the angle between <math>-\nabla F(\mathbf{a_n})</math> and <math> \mathbf{p}_n</math>, this requires that <math> \cos \theta_n > 0.</math> To say more, we need more information about the objective function that we are optimising. Under the fairly weak assumption that <math>F</math> is continuously differentiable, we may prove that:<ref>{{cite arXiv|last1=Bernstein|first1=Jeremy|last2=Vahdat|first2=Arash|last3=Yue|first3=Yisong|last4=Liu|first4=Ming-Yu|date=2020-06-12|title=On the distance between two neural networks and the stability of learning|class=cs.LG|eprint=2002.03432}}</ref> {{NumBlk|:|<math> F(\mathbf{a}_{n+1}) \leq F(\mathbf{a}_n) - \gamma_n \|\nabla F(\mathbf{a}_n)\|_2 \|\mathbf{p}_n\|_2 \left[\cos \theta_n - \max_{t\in[0,1]} \frac{\|\nabla F(\mathbf{a}_n - t \gamma_n \mathbf{p}_n) - \nabla F(\mathbf{a}_n)\|_2}{\| \nabla F(\mathbf{a}_n) \|_2}\right]</math>|{{EquationRef|1}}}} This inequality implies that the amount by which we can be sure the function <math>F</math> 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 ({{EquationNote|1}}) could be optimized over <math> \mathbf{p}_n</math> and <math> \gamma_n</math> to choose an optimal step size and direction. The problem is that evaluating the second term in square brackets requires evaluating <math> \nabla F(\mathbf{a}_n - t \gamma_n \mathbf{p}_n)</math>, 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 <math>\mathbf{p}_n = \nabla F(\mathbf{a_n})</math>, and use [[line search]] to find a suitable step-size <math> \gamma_n</math>, 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 <math>\mathbf{p}_n </math> 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 <math> \gamma_n</math>). * Assuming that <math>F</math> is twice-differentiable, use its Hessian <math>\nabla^2 F</math> to estimate <math> \|\nabla F(\mathbf{a}_n - t \gamma_n \mathbf{p}_n) - \nabla F(\mathbf{a}_n)\|_2 \approx \| t \gamma_n \nabla^2 F(\mathbf{a}_n) \mathbf{p}_n\|.</math>Then choose <math> \mathbf{p}_n</math> and <math> \gamma_n</math> by optimising inequality ({{EquationNote|1}}). * Assuming that <math>\nabla F</math> is [[Lipschitz continuity|Lipschitz]], use its Lipschitz constant <math> L</math> to bound <math> \|\nabla F(\mathbf{a}_n - t \gamma_n \mathbf{p}_n) - \nabla F(\mathbf{a}_n)\|_2 \leq L t \gamma_n \|\mathbf{p}_n\|.</math> Then choose <math> \mathbf{p}_n</math> and <math> \gamma_n</math> by optimising inequality ({{EquationNote|1}}). * Build a custom model of <math> \max_{t\in[0,1]} \frac{\|\nabla F(\mathbf{a}_n - t \gamma_n \mathbf{p}_n) - \nabla F(\mathbf{a}_n)\|_2}{\| \nabla F(\mathbf{a}_n) \|_2}</math> for <math>F</math>. Then choose <math> \mathbf{p}_n</math> and <math> \gamma_n</math> by optimising inequality ({{EquationNote|1}}). * Under stronger assumptions on the function <math>F</math> such as [[Convex function|convexity]], more [[#Fast gradient methods|advanced techniques]] may be possible. Usually by following one of the recipes above, [[convergent series|convergence]] to a local minimum can be guaranteed. When the function <math>F</math> is [[Convex function|convex]], all local minima are also global minima, so in this case gradient descent can converge to the global solution.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)