Gradient descent and the step size
The question
Which step size gets you to the target first in a long, narrow valley?
Run the same start with different step sizes and compare the paths.
- 1 SeeRace step sizes down a valley.
- 2 TryPredict the next loss.
- 3 ProveBuild the convergence proof.
- 4 ApplyCompute rates, iterates, and losses.
Before you start · 3 quick checks on coordinate slopes, diagonal matrices, and repeated multiplication
Two ideas before you start
2 ideasRead the slope where you are
A curved slice with a short tangent at the selected point.
The dashed line gives the slope at the selected point. In a valley with two coordinates, collect one such slope for each coordinate.
Exact definition
For a differentiable function \(f(x,y)\), the gradient \(\nabla f(x,y)=(f_x,f_y)\) is the vector of partial derivatives at \((x,y)\). The partial with respect to \(x\) holds \(y\) fixed, and the partial with respect to \(y\) holds \(x\) fixed. Each is a slope measured along one axis.
Scale a displacement
Two segments from the same point in the same direction, with one length scaled by a positive factor.
The dashed segment starts at the same point as the solid one. Its length changes with the scale, and it points along the same ray.
Exact definition
Write \(z_k\) for the input vector after \(k\) updates. A gradient descent update with a positive step size, also called a learning rate, \(\eta\), is
\[z_{k+1}=z_k-\eta\nabla f(z_k).\]The gradient is recomputed at each point. The scale \(\eta\) multiplies the whole gradient vector, so the distance moved is \(\eta\|\nabla f(z_k)\|\) in Euclidean coordinates. A fixed step size means a fixed multiplier.
Fine print on the valley model
Here the loss is the function to minimize. The first examples use an unconstrained quadratic with no mixed term or linear term. Its axes point across and along a bowl centered at the origin. The loss at the origin is the minimum. A contour joins points with the same loss.
Work in equally scaled Euclidean coordinates. Each update uses the full gradient and the same positive step size. The ball in the illustration gives a starting location. In the model, movement is calculated from the current coordinates with no velocity carried over from the last step.
Race step sizes down the valley
- Pick a step size and run it from the marked start.
- Compare the update count. A run scores when it first enters the target contour or lands on it.
- Scrub the update slider to inspect the run. Try each rate to see the comparison.
All recorded updates
How the score and map work
Count updates from the square, including the update that meets the loss cutoff. Runs that miss the cutoff within the budget get no count in the ranking. That includes runs still making progress when the budget ends.
The map uses equal scales for both axes and fits the entire recorded path. Its scale can change between runs. Compare coordinates or losses to compare sizes across runs. The path is made of a line segment between consecutive iterates. The algorithm uses the endpoints of those segments when it evaluates the loss.
Compare the loss at two endpoints
- Make a prediction on a different bowl.
- Then choose a step size to test each goal.
Follow the two coordinates
Which fixed rates reach the minimum?
Let \(a\) and \(b\) be real numbers with \(0\lt a\lt b\). Minimize
\[f(x,y)=\tfrac12(ax^2+by^2)\]over the whole plane in Euclidean coordinates. Start at \((x_0,y_0)\) with both coordinates nonzero. Use the exact gradient at each step and a fixed \(\eta\gt0\). The iterates converge to the unique minimizer \((0,0)\) exactly when
\[0\lt\eta\lt 2/b.\]At \(\eta=2/b\) the steep coordinate alternates with constant magnitude. Above that rate its magnitude grows without bound. The coefficient \(b\) is the larger eigenvalue of the Hessian, the matrix of second derivatives.
Pick the true statement at each step. A wrong choice leaves the current line open so you can inspect the feedback and try again.
Balance the slowest direction
For this bowl, call the larger of the two multiplier magnitudes \(\rho\). It measures the largest fraction of the Euclidean length of an error vector that could remain after one update. To balance the magnitudes, set the positive shallow multiplier equal to the negative of the steep multiplier. That gives
\[\eta_*={2\over a+b}.\]Below \(\eta_*\), the shallow multiplier \(1-\eta a\) is positive and larger than its value at balance. Above \(\eta_*\), the steep magnitude \(\eta b-1\) is larger than its value at balance. So \(\eta_*\) minimizes \(\rho\). A fixed starting point and a finite loss target can give a different best count, as can a restricted menu of rates.
Rotate the bowl
For a real symmetric positive definite matrix \(H\), the quadratic \(\tfrac12 z^THz\) has perpendicular eigenvector axes. In those axes the Hessian is diagonal, with strictly positive eigenvalues \(\lambda_i\). Each coordinate is multiplied by \(1-\eta\lambda_i\). The bound \(2/\lambda_{\max}\) gives the open upper limit for convergence from every start. To see failure at or above the bound, choose a start with a nonzero component in a largest-eigenvalue direction.
If an initial coordinate is zero in an eigenvector direction, it stays zero there. At the minimizer all coordinates remain zero for every fixed step size. These cases explain the nonzero-start condition in the theorem.
Compute the step, then check its effect
Enter a number to check your result. Each problem has hints and a worked solution. A requested endpoint can be excluded from the interval it bounds.
Further reading
- S. Boyd and L. Vandenberghe, Convex Optimization, gradient descent.
- J. Nocedal and S. J. Wright, Numerical Optimization, line search methods.