Jump to content

Stochastic gradient descent: Difference between revisions

From Wikibase
Fix the validity equation: add the 1/|I_1| normalisation, drop the learning rate, and explain what the normalisation is and why it is needed (via update-page on MediaWiki MCP Server)
Normalise the aggregated objective by the dataset size (via update-page on MediaWiki MCP Server)
 
Line 11: Line 11:


$$
$$
f=\sum_{k \in I} f_k
f=\frac{1}{|I|}\sum_{k \in I} f_k
$$
$$



Latest revision as of 13:48, 11 November 2026

Languages: English · français · Esperanto


Stochastic gradient descent (SGD) is a variant of gradient descent that optimises computation for aggregated differentiable objective function by estimating the gradient from a random sample of the data at each iteration.

It is the standard algorithm used to train artificial neural network (ANN) models on large datasets.

Mathematical definition

Let

$$ f=\frac{1}{|I|}\sum_{k \in I} f_k $$

then

$$ \vec x_{i+1} = \vec x_i - \frac{\eta}{|I_1|}\sum_{k \in I_1 \subset I} \nabla f_k(\vec x_i), $$

where $I_1 \subset I$ is the sample examined at iteration $i$. The step uses the average sampled gradient rather than its sum, so that $\eta$ keeps the same meaning whatever the sample size.

Validity

Classic (left) v. stochastic (right) gradient descent. Classic descent is like an old and wise person taking careful small steps directly towards the goal, while stochastic descent is like a young drunkard stumbling rapidly in the general direction. · Open in a new tab

The true gradient is the average of the per-datapoint gradients,

$$ \nabla f(\vec x_i) = \frac{1}{|I|}\sum_{k \in I}\nabla f_k(\vec x_i), $$

and the stochastic estimate must therefore also be an average rather than a sum. That is what the factor $1/|I_1|$ is: the sample size, dividing the sum over the sampled datapoints by how many terms that sum contains.

Without the factor the estimate is biased, because the sample holds only $|I_1|$ of the $|I|$ terms. Each datapoint is equally likely to be drawn, $\mathbb{P}(k \in I_1)=|I_1|/|I|$, so taking the expectation over the draw of $I_1$ with $\vec x_i$ fixed,

$$ \mathbb{E}\left[\sum_{k \in I_1 \subset I}\nabla f_k(\vec x_i)\right] = \sum_{k \in I}\mathbb{P}(k \in I_1)\nabla f_k(\vec x_i) = \frac{|I_1|}{|I|}\sum_{k \in I}\nabla f_k(\vec x_i) = |I_1|\,\nabla f(\vec x_i). $$

The raw sample sum therefore overshoots the true gradient by the factor $|I_1|$. Dividing by $|I_1|$ cancels that factor exactly,

$$ \mathbb{E}\left[\frac{1}{|I_1|}\sum_{k \in I_1 \subset I}\nabla f_k(\vec x_i)\right] = \nabla f(\vec x_i), $$

so the expected value of the sample gradient equals the true gradient. Therefore, the stochastic gradient is an unbiased estimator of the true gradient, whatever the sample size.

Advantage

Training large ANNs require large datasets with millions of datapoints and thousands of iterations. Calculating the true gradient requires evaluating $f_k$ for each datapoint, which is computationally prohibitive. Stochastic gradient descent significantly reduces computation burden without sacrificing accuracy.