Stochastic gradient descent
SGD subtracts a learning-rate-scaled sampled gradient from the current parameter.
On this page 8 sections
01Understand the idea#
Stochastic gradient descent uses a randomly selected example to estimate a training direction. Its arithmetic resembles full gradient descent, but each sampled direction can disagree with the whole dataset’s gradient. This makes individual steps noisy while reducing work per step.
SGD takes a step using a randomly selected example’s gradient. Given that sampled gradient g, the arithmetic is:
At θ=(3,−2), sampled g=(−4,2) and rate 0.25 give an update of (4,−2.5).
Starting from parameter 4 with sampled gradient 2 and rate 0.5 gives . If the next iteration supplies gradient , start from 3 and get . Carry the updated parameter forward, and use the gradient assigned to each iteration.
, sampled , . Find the SGD update.
Show answer and explanation
Subtract : .
02For successive steps, carry the new parameter forward#
For successive steps, carry the new parameter forward. Each supplied gradient belongs to its specified iteration.
The gradients can differ because the example or current parameter changed; use the value supplied for that step.
Start x=2. Step1: gradient -4, rate 0.25. Step2: gradient 2, rate 0.5. Find final x.
Show answer and explanation
First x=3; then x=2.
03A sampled direction need not reduce the full empirical objective#
A sampled direction need not reduce the full empirical objective. It can improve one example while worsening the dataset average.
For losses (w−a)²/2 and (w+a)²/2, their average is J(w)=(w²+a²)/2. At w=0, the first example has gradient −a while the full gradient is zero.
. Start w=0, sampled g=−5, rate 0.5. A report predicts lower J. Compute the new J.
Show answer and explanation
New w=2.5. J rises from 12.5 to 15.625.
04A closer look#
Uniformly sampling an example gives an unbiased estimate of the mean-loss gradient under the usual differentiability assumptions. Unbiased refers to the average over possible samples, not a promise that one sampled step reduces the full objective.
Use the supplied sampled gradient at each step; one update need not reduce the full dataset objective.
- Compute a parameter update using a supplied sampled gradient.
Sources & further reading
- [1]D2L §12.4.1, equation12.4.3 ↗D2L §12.4.1, equation12.4.3 · Article