Gradient descent updates
Gradient descent repeatedly adjusts parameters in the direction opposite to their gradient. For one parameter, the update is w_next = w − η L′(w), where η (eta) is a positive learning rate. For L(w) = (w−3)², starting at w = 1 with η = 0.25 gives w_next = 1 − 0.25 × (−4) = 2. Loss drops from 4 to 1. The negative sign matters: adding the gradient would move uphill for this example.
Compare learning rates before repeating the update
The learning rate scales the update. It is chosen outside this simple optimization loop, so it is a hyperparameter rather than a learned parameter. If w has physical units, the rate must scale the derivative into the units of w; in this toy exercise we use numerical coordinates with compatible scaling. A larger rate can pass the minimum, a behavior called overshooting. Overshooting does not automatically mean divergence.
def step(w, rate): if not 0 <= rate <= 2: raise ValueError("Rate outside teaching range") return w - rate * 2 * (w - 3)
for rate in (0.25, 0.75, 1.0, 1.1): w = step(1, rate) print(rate, round(w, 2), round((w - 3) ** 2, 2))The output columns are learning rate, new parameter and new loss. Rates 0.25 and 0.75 yield parameters 2 and 4 with loss 1. Rate 1 gives 5 and loss 4, while 1.1 gives 5.4 and loss 5.76. The helper accepts rates from 0 to 2 solely to support these bounded demonstrations, not because those rates are generally safe. Zero is a no-update control.
Why this quadratic converges or diverges
Subtract 3 from the update equation to obtain w_next−3 = (1−2η)(w−3). Each step multiplies the signed distance from the optimum by 1−2η. Starting away from the optimum, a constant rate strictly between 0 and 1 makes the magnitude shrink in exact arithmetic. With η = 0.5 the quadratic reaches its minimum in one step. Rates between 0.5 and 1 alternate sides while shrinking. Rate 1 alternates without reducing the error, and rates greater than 1 grow the error magnitude. Rate 0 stalls. This exact result depends on the curvature of this specific quadratic; rescaling the loss changes the acceptable rates. For example, multiplying the loss by 10 also multiplies its derivative by 10.
Use the same gradient for every coordinate
For J(w,b) = (w+b−3)² + b², calculate both partial derivatives at the old pair before changing either coordinate. At (1,1), J = 2 and the gradient is (−2,0). With rate 0.25, the next pair is (1.5,1). The function below implements a simultaneous vector update rather than recalculating one component after the first coordinate changes.
def gradient(w, b): error = w + b - 3 return (2 * error, 2 * error + 2 * b)
def pair_step(w, b, rate): dw, db = gradient(w, b) return (w - rate * dw, b - rate * db)
w, b = pair_step(1, 1, 0.25)print(w, b)print((w + b - 3) ** 2 + b ** 2)Output: 1.5 1.0 followed by 1.25. The objective decreases from 2 to 1.25. Recalculating a partial derivative after changing w would be a different algorithm. In a dataset-based objective, full-batch descent uses all training examples for the gradient. Stochastic descent commonly uses one sampled example, and mini-batch descent uses a subset. Their estimated gradients can be noisy, so individual steps need not lower the full objective.
Monitor optimization without confusing it with success
Track a loss curve and set a maximum step count, a stopping tolerance and checks for nonfinite values in real numerical workloads. A tiny change can mean progress has stalled rather than a good solution. A nonconvex objective may have several minima, flat regions or saddle points; these quadratic calculations do not guarantee a global optimum for such objectives. Even a low training loss may reflect poor data, a misleading objective or overfitting. Evaluate performance on separate suitable observations and consider real error costs before deployment.
Practice and debugging
Starting from w = 1, calculate two updates at rate 0.25. You should obtain 2 and 2.5, with losses 1 and 0.25. At rate 0.75 the first two positions are 4 and 2.5, with the same losses. At rate 1.1 the error grows rather than shrinks. If a result differs, check the derivative sign, whether the learning rate is multiplied by the derivative, and whether the loss is recomputed from the updated parameter. Next, use the chapter project to compare trajectories and explain the limits of the toy model.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Gradient descent updates — understanding check
Apply calculus and optimization intuition to bounded synthetic examples.
For L(w) = (w − 3)², starting at w = 1 with learning rate 0.25, what is the next parameter after one gradient descent step?
For L(w) = (w − 3)² and w = 1, which constant learning rate reaches w = 3 in one gradient descent step?
For L(w) = (w − 3)² starting at w = 1 with rate 0.75, how does the signed distance w − 3 behave over successive steps?
Why are both partial derivatives evaluated before updating either parameter in simultaneous gradient descent?
What does a low training loss establish by itself?