Gradient descent step size
Quick answer
Gradient descent iteratively changes parameters in the direction opposite the gradient. The learning rate (step size) controls how far each update moves. In a scalar problem, w_next = w - η J′(w). A positive learning rate can still be too large; the behavior depends on the curvature and the objective.
Follow a quadratic update
Use J(w) = (w - 3)². Its derivative is 2(w - 3). With w = 7 and η = 0.25, the derivative is 8 and the new value is 5. Subtracting 2 moves toward 3. The error e = w - 3 changes by the factor 1 - 2η each step. For this particular quadratic, convergence from any finite starting value in exact arithmetic occurs for 0 < η < 1. At η = 0.5 the minimizer is reached in one update; η = 1 gives constant-amplitude oscillation; η > 1 grows the error unless already at the optimum.
for rate in [0.25, 0.75, 1.0, 1.25]: w = 7.0 trace = [w] for _ in range(3): w -= rate * 2 * (w - 3) trace.append(w) print(rate, trace)Expected output (local Python 3.13.5):
0.25 [7.0, 5.0, 4.0, 3.5]0.75 [7.0, 1.0, 4.0, 2.5]1.0 [7.0, -1.0, 7.0, -1.0]1.25 [7.0, -3.0, 12.0, -10.5]The first two rates converge, the third oscillates without improving, and the last diverges. The bound is specific to this objective, not a universal learning-rate rule.
Full batch, stochastic and mini-batch gradients
For mean squared error, each observation contributes 2(w-y). Full-batch gradient descent averages all contributions before updating; stochastic gradient descent (SGD) uses one randomly sampled observation per step; mini-batch descent uses a subset. Uniform sampling gives an unbiased estimate of the full gradient at a fixed w, but a single estimate can be noisy. In this deterministic illustration the batches are chosen explicitly, not randomly. An epoch normally means a pass through the training set; the number of updates per epoch depends on batch size and handling of the final batch.
ys = [2, 4, 6, 8]w = 0.0for batch in [ys, [ys[0]], ys[:2]]: g = sum(2*(w-y) for y in batch)/len(batch) print(g, w - 0.1*g)Expected output (local Python 3.13.5):
-10.0 1.0-4.0 0.4-6.0 0.6000000000000001All updates start at the same parameter. The last printed decimal illustrates floating-point representation, not a different mathematical value.
Common mistakes
Do not accidentally add the gradient when minimizing. Avoid updating w inside a loop that is supposed to accumulate one full-batch gradient. A loss summed over the batch has a different gradient scale than a mean. Small batches can have noisy loss curves; lower training loss after every step is not required for SGD.
Practice and next steps
Predict the third update from w=7 at η=0.5. Compare one mini-batch gradient from [6,8] with the full gradient at w=0. Next, examine when a stationary point is a minimum.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Gradient descent step size — knowledge check
Apply optimization reasoning to synthetic examples.
At w=7, target=3 and η=.25, what is the next parameter?
Which rate reaches the minimum in one step for J=(w-3)^2?
At η=1 for this quadratic, what happens away from the optimum?
What is a full-batch gradient?
Why may a mini-batch loss rise temporarily?