Motivation
Least squares turns fitting data into an optimization problem. Solving the normal equations gives an exact description of the answer, while gradient descent approaches that answer through repeated updates. The two viewpoints should agree: the equations identify the destination, and the iteration explains how the current error changes on the way there.
A quadratic objective is particularly useful for understanding this process. Its gradient depends affinely on the parameters, its curvature is constant, and its eigenvectors separate the update into independent scalar recurrences. Consequently, we can calculate precisely when a step size gives convergence, when the iterates oscillate, and when they move farther from the minimum. These conclusions also explain why changing the scale of a loss changes a suitable learning rate, even though the fitted model stays the same.
Throughout this section, parameter vectors are columns, and the gradient is a column of partial derivatives. The Euclidean geometry behind the word “steepest” is the same inner-product geometry used in projections and PCA. We will use the spectral decomposition of a real symmetric matrix rather than introduce another algorithm for finding eigenvectors.
Definitions
Definition
Quadratic objective and gradient
For a parameter vector , consider
Here is a real matrix, , and is a scalar. Its gradient and Hessian are
The matrix is positive definite when for every nonzero . In that case all its eigenvalues are positive. Write and .
The symmetry assumption makes the derivative especially transparent. Expanding produces two equal cross terms, so the part linear in is . The remaining part is . The factor in the objective cancels the factor that differentiation of a square would otherwise introduce.
Definition
Gradient descent with a constant step size
Choose an initial parameter and a positive scalar step size . Gradient descent generates
The gradient is evaluated at the current iterate. Every coordinate in uses that same current vector .
To understand the direction, let . Among unit vectors , the directional derivative has smallest value , attained at when . This follows from Cauchy–Schwarz. Gradient descent uses itself, so its direction is steepest descent and its displacement length is . A direction and a displacement length are different choices: a useful direction does not make an arbitrarily long step useful.
Theorem/Proposition
Theorem
The minimum and its exact objective gap
Suppose is symmetric positive definite. Then has the unique global minimizer
For ,
The constant changes objective values but has no effect on the minimizer or the updates. The vector determines the centre of the quadratic, while determines the shape around that centre. In particular, finding a stationary point here solves the minimization problem because the objective gap is strictly positive away from that point.
Theorem
The exact constant-step convergence condition
Let be symmetric positive definite and set . For a fixed real step size ,
The iterates converge to for every initial vector if and only if
For such a step size, define
Then and .
The words “for every initial vector” matter. A particular initialization can have zero error in an unstable eigenvector direction, so a single successful run does not establish a step-size guarantee. The theorem controls every direction that an initial error might contain.
Proof sketch or proof idea
First expand . The terms linear in cancel because , leaving . If with orthogonal, set . Then , and the objective-gap bounds follow by replacing each eigenvalue with or . Positivity also proves uniqueness.
Subtract the stationary equation from one gradient step:
Changing to eigenvector coordinates gives
Each coordinate is a geometric sequence. It tends to zero for every starting value exactly when , equivalently . Requiring this for all eigenvalues gives the stated interval. Taking squared sums yields the error bound; weighting those squares by yields the objective-gap bound.
At , a nonzero component in a largest-eigenvalue direction multiplies by , so it alternates without shrinking. Above this boundary, its multiplier has magnitude greater than one and that component diverges. At , every iterate stays at its initial value. These cases explain both strict inequalities in the convergence condition.
Curvature, progress, and conditioning
There is also an exact one-step expression. With ,
Thus every nonstationary step strictly decreases the objective when . For , all the eigenvector multipliers lie between and : there is no sign alternation in these coordinates. When is much smaller than , however, the low-curvature direction shrinks slowly. The steepest direction restricts the allowed step size, while the flattest direction limits progress.
The ratio is the condition number of this positive-definite quadratic. Among constant steps, the smallest worst-direction contraction is obtained by balancing the two endpoint multipliers: . This gives and . This is a statement about a known quadratic spectrum. It also makes the role of feature scaling concrete: changing coordinates can change the relative curvatures faced by the iteration.
The contraction factor describes repeated progress, rather than just a successful first update. If , an error component that dominates the estimate initially may still require many updates to become small. After ten updates the bound contains , whereas the corresponding objective-gap bound contains . An apparently rapid decrease in the loss can therefore coexist with a more gradual improvement in the parameters. The two quantities measure different features of the same run, and the theorem states their relationship explicitly.
This distinction is especially visible in a narrow quadratic valley. Moving away from its steep walls can remove much of the initial loss quickly. Once that component is small, the remaining error lies mostly along the flatter direction. Progress then looks slower even though the same constant recurrence has governed every step. The apparent change of speed comes from changing proportions of the error components, rather than a change in the algorithm.
Worked examples
Worked example
1. A scalar step can shrink, alternate, or diverge
Let . Its derivative is , so , , and the step-size interval is . Starting with , choose . The error multiplier is , giving
The corresponding losses are , , , and . Error halves at each step, while loss is divided by four because it is quadratic in error.
With , the multiplier is : the iterates alternate between and , and the loss stays at . With , the multiplier is : the first three iterates are , , and , with losses , , and . All three runs use the negative gradient; their different behaviour comes from the step length.
Worked example
2. Two eigenvector directions progress at different rates
Consider
Here , , and the coordinate axes are already eigenvector directions. For , the two error multipliers are and . Starting at therefore gives
The second coordinate reaches its optimal value in one step. The first continues to approach geometrically. The losses are , , and . The smallest worst-direction contraction instead uses , giving multipliers and . Sign alternation can therefore coexist with convergence and even improve the worst-direction contraction.
The following Python code computes both gradient coordinates before updating either parameter. Reading its successive states beside the exact calculation makes the coordinate recurrence visible.
u, v = 3.0, 1.0
eta = 0.25
for k in range(4):
loss = 0.5 * ((u - 1.0) ** 2 + 4.0 * (v + 1.0) ** 2)
print(f"{k}: ({u:.6f}, {v:.6f}) f={loss:.6f}")
grad_u, grad_v = u - 1.0, 4.0 * (v + 1.0)
u, v = u - eta * grad_u, v - eta * grad_v
Its output is
0: (3.000000, 1.000000) f=10.000000
1: (2.500000, -1.000000) f=1.125000
2: (2.125000, -1.000000) f=0.632812
3: (1.843750, -1.000000) f=0.355957
Worked example
3. Gradient descent reaches the same regression fit
For three observations, take
The first parameter is an intercept and the second is a slope. Expansion gives and , hence . The columns of are independent, so is positive definite and .
With and , the gradient is , giving . The residual vector is , so . Another step gives and . At the optimum, the residual is and . The intercept error disappears immediately; the slope error is multiplied by on every step. A positive minimum loss expresses the remaining fitting residual, rather than failure of the optimization.
For a general design matrix , the same normalization gives
Full column rank is exactly the condition making positive definite: is positive for nonzero precisely when the null space is zero. The largest curvature is , linking the learning rate to singular values. No matrix inverse is needed to perform a step: form a prediction, subtract the target, multiply the residual by , and divide by .
The indices in this calculation have distinct roles. The prediction and residual have one entry for each observation, whereas the gradient has one entry for each parameter. Multiplication by converts observation errors into parameter directions by accumulating each feature's contribution. For an intercept column of ones, its gradient entry is the mean residual. For another feature column, it is the mean product of that feature with the residual. This explains how the normal-equation orthogonality condition appears inside an iterative algorithm: a zero gradient says that every feature column is orthogonal to the current residual.
Consequently, the residual vector itself need not tend to zero. At a least-squares solution it can retain a component orthogonal to the column space of . Gradient descent cannot remove that component by changing the coefficients, because every available prediction remains in the same column space. What tends to zero is the gradient, or the part of the residual that still points toward an available improvement. This is the geometric reason to distinguish a small optimization error from a small data-fitting error.
The two products and also provide a direct implementation without first constructing . For a dense matrix, each product uses work proportional to the number of entries of . The quadratic matrix remains useful for analysis even when the implementation applies those products separately. This separates the mathematical object that proves convergence from the operations that actually produce an update.
Loss normalization and stopping
Replacing by for preserves its minimizer, but multiplies its gradient and Hessian by . To reproduce the same iterates, divide the step size by . In the regression example, the unnormalized residual sum of squares is . Its largest curvature is , so its interval is ; a step of reproduces the mean-loss step of .
A useful stopping quantity is . Since , a known lower curvature bound gives . A small update by itself has a different meaning: it may simply reflect an extremely small chosen . Report the loss normalization and the stopping quantity together when comparing numerical runs.
Common mistakes
Common mistake
Confusing a gradient direction with a guaranteed decrease
The negative gradient gives a local descent direction at a nonstationary point. A finite step also depends on curvature. For a quadratic, the factor determines whether each error component shrinks. Checking its magnitude explains both convergence with alternating signs and divergence after an excessively long step.
Common mistake
Changing the loss while retaining the same learning rate
The losses and have the same minimizers, but their gradients differ by . Write the objective first, differentiate that objective, and adjust when a multiplicative normalization changes.
Summary
The stationary equation locates the unique minimum of a positive-definite quadratic. Subtracting that equation from the update gives an exact linear recurrence for the error. In eigenvector coordinates, each error component is multiplied by ; all components shrink precisely when . Least-squares regression fits this framework when the design matrix has independent columns, with curvature determined by its squared singular values and by the chosen loss normalization.
Exercises
Checkpoint
1. Find the minimum, the full constant-step convergence interval, and the first step when , , , and .
Compute the gradient at the initial vector before updating either coordinate.
Checkpoint
2. For and , compute the next two iterates for and for . Which run converges?
Express the update using the error .
Checkpoint
3. In the regression example, replace by the residual sum of squares . Which step reproduces for , and what is the convergence interval for ?
Track both the gradient scaling and the largest Hessian eigenvalue.
Checkpoint
4. Let with and . Find the iterates and all minimizers. Why does the uniqueness theorem not apply?
Identify what the gradient does in the second coordinate.
Solutions
Solution · 1. Solve the stationary equation and apply the two multipliers
The minimum is . Since , the interval is . At , the gradient is , so . The multipliers are and .
Solution · 2. Separate boundary oscillation from shrinking oscillation
The derivative is , and the error multiplier is . For it is , giving , and continued alternation. For it is , giving , and convergence to . The convergence interval is , so only the second run lies inside it.
Solution · 3. Scale the learning rate inversely with the objective
Because , choose to reproduce the same update. The largest Hessian eigenvalue becomes , giving for convergence from every initial vector.
Solution · 4. A flat direction preserves its initial coordinate
The gradient is . The first step gives , and every later iterate stays there. All vectors with minimize the objective. Its Hessian is positive semidefinite but not positive definite; the flat second direction prevents uniqueness.
Continue with least squares and residuals, SVD and principal components, or the course reading list.