| Part of a series on |
| Machine learning anddata mining |
|---|
Learning with humans |
Model diagnostics |
Stochastic gradient descent (often abbreviatedSGD) is aniterative method for optimizing anobjective function with suitablesmoothness properties (e.g.differentiable orsubdifferentiable). It can be regarded as astochastic approximation ofgradient descent optimization, since it replaces the actual gradient (calculated from the entiredata set) by an estimate thereof (calculated from a randomly selected subset of the data). Especially inhigh-dimensional optimization problems this reduces the very highcomputational burden, achieving faster iterations in exchange for a lowerconvergence rate.[1]
The basic idea behind stochastic approximation can be traced back to the Robbins–Monro algorithm of the 1950s. Today, stochastic gradient descent has become an important optimization method inmachine learning.[2]
Bothstatisticalestimation andmachine learning consider the problem ofminimizing anobjective function that has the form of a sum:where theparameter that minimizes is to beestimated. Each summand function is typically associated with the-thobservation in thedata set (used for training).
In classical statistics, sum-minimization problems arise inleast squares and inmaximum-likelihood estimation (for independent observations). The general class of estimators that arise as minimizers of sums are calledM-estimators. However, in statistics, it has been long recognized that requiring even local minimization is too restrictive for some problems of maximum-likelihood estimation.[3] Therefore, contemporary statistical theorists often considerstationary points of thelikelihood function (or zeros of its derivative, thescore function, and otherestimating equations).
The sum-minimization problem also arises forempirical risk minimization. There, is the value of theloss function at-th example, and is the empirical risk.
When used to minimize the above function, a standard (or "batch")gradient descent method would perform the following iterations:The step size is denoted by (sometimes called thelearning rate in machine learning) and here "" denotes the update of a variable in the algorithm.
In many cases, the summand functions have a simple form that enables inexpensive evaluations of the sum-function and the sum gradient. For example, in statistics,one-parameter exponential families allow economical function-evaluations and gradient-evaluations.
However, in other cases, evaluating the sum-gradient may require expensive evaluations of the gradients from all summand functions. When the training set is enormous and no simple formulas exist, evaluating the sums of gradients becomes very expensive, because evaluating the gradient requires evaluating all the summand functions' gradients. To economize on the computational cost at every iteration, stochastic gradient descentsamples a subset of summand functions at every step. This is very effective in the case of large-scale machine learning problems.[4]

In stochastic (or "on-line") gradient descent, the true gradient of is approximated by a gradient at a single sample:As the algorithm sweeps through the training set, it performs the above update for each training sample. Several passes can be made over the training set until the algorithm converges. If this is done, the data can be shuffled for each pass to prevent cycles. Typical implementations may use anadaptive learning rate so that the algorithm converges.[5]
In pseudocode, stochastic gradient descent can be presented as :
A compromise between computing the true gradient and the gradient at a single sample is to compute the gradient against more than one training sample (called a "mini-batch") at each step. This can perform significantly better than "true" stochastic gradient descent described, because the code can make use ofvectorization libraries rather than computing each step separately as was first shown in[6] where it was called "the bunch-mode back-propagation algorithm". It may also result in smoother convergence, as the gradient computed at each step is averaged over more training samples.
The convergence of stochastic gradient descent has been analyzed using the theories ofconvex minimization and ofstochastic approximation. Briefly, when thelearning rates decrease with an appropriate rate,and subject to relatively mild assumptions, stochastic gradient descent convergesalmost surely to a global minimum when the objective function isconvex orpseudoconvex, and otherwise converges almost surely to a local minimum.[2][7]This is in fact a consequence of theRobbins–Siegmund theorem.[8]
Suppose we want to fit a straight line to a training set with observations and corresponding estimated responses usingleast squares. The objective function to be minimized isThe last line in the above pseudocode for this specific problem will become:Note that in each iteration or update step, the gradient is only evaluated at a single. This is the key difference between stochastic gradient descent and batched gradient descent.
In general, given a linear regression problem, stochastic gradient descent behaves differently when (underparameterized) and (overparameterized). In the overparameterized case, stochastic gradient descent converges to. That is, SGD converges to the interpolation solution with minimum distance from the starting. This is true even when the learning rate remains constant. In the underparameterized case, SGD does not converge if learning rate remains constant.[9]
In 1951,Herbert Robbins andSutton Monro introduced the earliest stochastic approximation methods, preceding stochastic gradient descent.[10] Building on this work one year later,Jack Kiefer andJacob Wolfowitz publishedan optimization algorithm very close to stochastic gradient descent, usingcentral differences as an approximation of the gradient.[11] Later in the 1950s,Frank Rosenblatt used SGD to optimize hisperceptron model, demonstrating the first applicability of stochastic gradient descent to neural networks.[12]
Backpropagation was first described in 1986, with stochastic gradient descent being used to efficiently optimize parameters across neural networks with multiplehidden layers. Soon after, another improvement was developed: mini-batch gradient descent, where small batches of data are substituted for single samples. In 1997, the practical performance benefits from vectorization achievable with such small batches were first explored,[13] paving the way for efficient optimization in machine learning. As of 2023, this mini-batch approach remains the norm for training neural networks, balancing the benefits of stochastic gradient descent withgradient descent.[14]
By the 1980s,momentum had already been introduced, and was added to SGD optimization techniques in 1986.[15] However, these optimization techniques assumed constanthyperparameters, i.e. a fixed learning rate and momentum parameter. In the 2010s, adaptive approaches to applying SGD with a per-parameter learning rate were introduced with AdaGrad (for "Adaptive Gradient") in 2011[16] and RMSprop (for "Root Mean Square Propagation") in 2012.[17] In 2014, Adam (for "Adaptive Moment Estimation") was published, applying the adaptive approaches of RMSprop to momentum; many improvements and branches of Adam were then developed such as Adadelta, Adagrad, AdamW, and Adamax.[18][19]
Within machine learning, approaches to optimization in 2023 are dominated by Adam-derived optimizers. TensorFlow and PyTorch, by far the most popular machine learning libraries,[20] as of 2023 largely only include Adam-derived optimizers, as well as predecessors to Adam such as RMSprop and classic SGD. PyTorch also partially supportslimited-memory BFGS, a line-search method, but only for single-device setups without parameter groups.[19][21]
Stochastic gradient descent is a popular algorithm for training a wide range of models inmachine learning, including (linear)support vector machines,logistic regression (see, e.g.,Vowpal Wabbit) andgraphical models.[22] When combined with thebackpropagation algorithm, it is thede facto standard algorithm for trainingartificial neural networks.[23] Its use has been also reported in theGeophysics community, specifically to applications of Full Waveform Inversion (FWI).[24]
Stochastic gradient descent competes with theL-BFGS algorithm,[citation needed] which is also widely used. Stochastic gradient descent has been used since at least 1960 for traininglinear regression models, originally under the nameADALINE.[25]
Another stochastic gradient descent algorithm is theleast mean squares (LMS) adaptive filter.
Many improvements on the basic stochastic gradient descent algorithm have been proposed and used. In particular, in machine learning, the need to set alearning rate (step size) has been recognized as problematic. Setting this parameter too high can cause the algorithm to diverge; setting it too low makes it slow to converge.[26] A conceptually simple extension of stochastic gradient descent makes the learning rate a decreasing functionηt of the iteration numbert, giving alearning rate schedule, so that the first iterations cause large changes in the parameters, while the later ones do only fine-tuning. Such schedules have been known since the work of MacQueen onk-means clustering.[27] Practical guidance on choosing the step size in several variants of SGD is given by Spall.[28]


As mentioned earlier, classical stochastic gradient descent is generally sensitive tolearning rateη. Fast convergence requires large learning rates but this may induce numerical instability. The problem can be largely solved[29] by consideringimplicit updates whereby the stochastic gradient is evaluated at the next iterate rather than the current one:
This equation is implicit since appears on both sides of the equation. It is a stochastic form of theproximal gradient method since the updatecan also be written as:
As an example, consider least squares with features and observations. We wish to solve:where indicates the inner product.Note that could have "1" as the first element to include an intercept. Classical stochastic gradient descent proceeds as follows:
where is uniformly sampled between 1 and. Although theoretical convergence of this procedure happens under relatively mild assumptions, in practice the procedure can be quite unstable. In particular, when is misspecified so that has large absolute eigenvalues with high probability, the procedure may diverge numerically within a few iterations. In contrast,implicit stochastic gradient descent (shortened as ISGD) can be solved in closed-form as:
This procedure will remain numerically stable virtually for all as thelearning rate is now normalized. Such comparison between classical and implicit stochastic gradient descent in the least squares problem is very similar to the comparison betweenleast mean squares (LMS) andnormalized least mean squares filter (NLMS).
Even though a closed-form solution for ISGD is only possible in least squares, the procedure can be efficiently implemented in a wide range of models. Specifically, suppose that depends on only through a linear combination with features, so that we can write, where may depend on as well but not on except through. Least squares obeys this rule, and so doeslogistic regression, and mostgeneralized linear models. For instance, in least squares,, and in logistic regression, where is thelogistic function. InPoisson regression,, and so on.
In such settings, ISGD is simply implemented as follows. Let, where is scalar.Then, ISGD is equivalent to:
The scaling factor can be found through thebisection method since in most regular models, such as the aforementioned generalized linear models, function is decreasing, and thus the search bounds for are.
Further proposals include themomentum method or theheavy ball method, which in ML context appeared inRumelhart,Hinton andWilliams' paper on backpropagation learning[30] and borrowed the idea from Soviet mathematician Boris Polyak's 1964 article on solving functional equations.[31] Stochastic gradient descent with momentum remembers the updateΔw at each iteration, and determines the next update as alinear combination of the gradient and the previous update:[32][33]that leads to:
where theparameter which minimizes is to beestimated, is a step size (sometimes called thelearning rate in machine learning) and is an exponentialdecay factor between 0 and 1 that determines the relative contribution of the current gradient and earlier gradients to the weight change.
The name momentum stems from an analogy tomomentum in physics: the weight vector, thought of as a particle traveling through parameter space,[30] incurs acceleration from the gradient of the loss ("force"). Unlike in classical stochastic gradient descent, it tends to keep traveling in the same direction, preventing oscillations. Momentum has been used successfully by computer scientists in the training ofartificial neural networks for several decades.[34]Themomentum method is closely related tounderdamped Langevin dynamics, and may be combined withsimulated annealing.[35]
In mid-1980s the method was modified byYurii Nesterov to use the gradient predicted at the next point, and the resulting so-calledNesterov Accelerated Gradient was sometimes used in ML in the 2010s.[36]
Averaged stochastic gradient descent, invented independently by Ruppert and Polyak in the late 1980s, is ordinary stochastic gradient descent that records an average of its parameter vector over time. That is, the update is the same as for ordinary stochastic gradient descent, but the algorithm also keeps track of[37]
When optimization is done, this averaged parameter vector takes the place ofw.
AdaGrad (for adaptivegradient algorithm) is a modified stochastic gradient descent algorithm with per-parameterlearning rate, first published in 2011.[38] Informally, this increases the learning rate forsparser parameters[clarification needed] and decreases the learning rate for ones that are less sparse. This strategy often improves convergence performance over standard stochastic gradient descent in settings where data is sparse and sparse parameters are more informative. Examples of such applications include natural language processing and image recognition.[38]
It still has a base learning rateη, but this is multiplied with the elements of a vector{Gj,j} which is the diagonal of theouter product matrix
where, the gradient, at iterationτ. The diagonal is given by
This vector essentially stores a historical sum of gradient squares by dimension and is updated after every iteration. The formula for an update is now[a]or, written as per-parameter updates,Each{G(i,i)} gives rise to a scaling factor for the learning rate that applies to a single parameterwi. Since the denominator in this factor, is theℓ2 norm of previous derivatives, extreme parameter updates get dampened, while parameters that get few or small updates receive higher learning rates.[34]
While designed forconvex problems, AdaGrad has been successfully applied to non-convex optimization.[39]
RMSProp (for Root Mean Square Propagation) is a method invented in 2012 by James Martens andIlya Sutskever, at the time both PhD students in Geoffrey Hinton's group, in which thelearning rate is, like in Adagrad, adapted for each of the parameters. The idea is to divide the learning rate for a weight by a running average of the magnitudes of recent gradients for that weight.[40] Unusually, it was not published in an article but merely described in aCoursera lecture.[citation needed][41][42]
So, first the running average is calculated in terms of means square,
where, is the forgetting factor. The concept of storing the historical gradient as sum of squares is borrowed from Adagrad, but "forgetting" is introduced to solve Adagrad's diminishing learning rates in non-convex problems by gradually decreasing the influence of old data.[citation needed]
And the parameters are updated as,
RMSProp has shown good adaptation of learning rate in different applications. RMSProp can be seen as a generalization ofRprop and is capable to work with mini-batches as well opposed to only full-batches.[40]
Adam[43] (short for Adaptive Moment Estimation) is a 2014 update to theRMSProp optimizer combining it with the main feature of theMomentum method.[44] In this optimization algorithm, running averages with exponential forgetting of both the gradients and the second moments of the gradients are used. Given parameters and a loss function, where indexes the current training iteration (indexed at), Adam's parameter update is given by:
where is a small scalar (e.g.) used to prevent division by 0, and (e.g. 0.9) and (e.g. 0.999) are the forgetting factors for gradients and second moments of gradients, respectively. Squaring and square-rooting is done element-wise.
As the exponential moving averages of the gradient and the squared gradient are initialized with a vector of 0's, there would be a bias towards zero in the first training iterations. A factor is introduced to compensate this bias and get better estimates and.
The initial proof establishing the convergence of Adam was incomplete, and subsequent analysis has revealed that Adam does not converge for all convex objectives.[45][46] Despite this,Adam continues to be used due to its strong performance in practice.[47]
The popularity ofAdam inspired many variants and enhancements. Some examples include:
Even though sign-based optimization goes back to the aforementionedRprop, in 2018 researchers tried to simplify Adam by removing the magnitude of the stochastic gradient from being taken into account and only considering its sign.[56][57]
This sectionneeds expansion. You can help byadding to it.(June 2023) |
Backtracking line search is another variant of gradient descent. All of the below are sourced from the mentioned link. It is based on a condition known as the Armijo–Goldstein condition. Both methods allow learning rates to change at each iteration; however, the manner of the change is different. Backtracking line search uses function evaluations to check Armijo's condition, and in principle the loop in the algorithm for determining the learning rates can be long and unknown in advance. Adaptive SGD does not need a loop in determining learning rates. On the other hand, adaptive SGD does not guarantee the "descent property" – which Backtracking line search enjoys – which is that for all n. If the gradient of the cost function is globally Lipschitz continuous, with Lipschitz constant L, and learning rate is chosen of the order 1/L, then the standard version of SGD is a special case of backtracking line search.
A stochastic analogue of the standard (deterministic)Newton–Raphson algorithm (a "second-order" method) provides an asymptotically optimal or near-optimal form of iterative optimization in the setting of stochastic approximation[citation needed]. A method that uses direct measurements of theHessian matrices of the summands in the empirical risk function was developed by Byrd, Hansen, Nocedal, and Singer.[58] However, directly determining the required Hessian matrices for optimization may not be possible in practice. Practical and theoretically sound methods for second-order versions of SGD that do not require direct Hessian information are given by Spall and others.[59][60][61] (A less efficient method based on finite differences, instead of simultaneous perturbations, is given by Ruppert.[62]) Another approach to the approximation Hessian matrix is replacing it with the Fisher information matrix, which transforms usual gradient to natural.[63] These methods not requiring direct Hessian information are based on either values of the summands in the above empirical risk function or values of the gradients of the summands (i.e., the SGD inputs). In particular, second-order optimality is asymptotically achievable without direct calculation of the Hessian matrices of the summands in the empirical risk function. When the objective is a nonlinear least-squares loss where is the predictive model (e.g., adeep neural network)the objective's structure can be exploited to estimate 2nd order information using gradients only. The resulting methods are simple and often effective[64]
For small learning rate stochastic gradient descent can be viewed as a discretization of thegradient flow ODE
subject to additional stochastic noise. This approximation is only valid on a finite time-horizon in the following sense: assume that all the coefficients are sufficiently smooth. Let and be a sufficiently smooth test function. Then, there exists a constant such that for all
where denotes taking the expectation with respect to the random choice of indices in the stochastic gradient descent scheme.
Since this approximation does not capture the random fluctuations around the mean behavior of stochastic gradient descent solutions tostochastic differential equations (SDEs) have been proposed as limiting objects.[65] More precisely, the solution to the SDE
for where denotes theIto-integral with respect to aBrownian motion is a more precise approximation in the sense that there exists a constant such that
However this SDE only approximates the one-point motion of stochastic gradient descent. For an approximation of thestochastic flow one has to consider SDEs with infinite-dimensional noise.[66]
The RMSProp algorithm was introduced by Geoffrey Hinton in his Coursera class, where he credited its effectiveness in various applications.
{{cite journal}}:Cite journal requires|journal= (help){{cite journal}}:Cite journal requires|journal= (help){{cite book}}: CS1 maint: multiple names: authors list (link){{cite journal}}:Cite journal requires|journal= (help){{cite journal}}:Cite journal requires|journal= (help){{cite journal}}:Cite journal requires|journal= (help)