Hexa Scholar

Gradient descent and the step size

A gold ball rests on the sloping side of a wooden trough.
A ball on the side of a trough marks a starting point above the floor.

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. 1 SeeRace step sizes down a valley.
  2. 2 TryPredict the next loss.
  3. 3 ProveBuild the convergence proof.
  4. 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 ideas

Read 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.

1 See

Race step sizes down the valley

Ellipses mark equal loss. The innermost ellipse bounds the target. The square marks the start.

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.

2 Try

Compare the loss at two endpoints

3 Prove

Which fixed rates reach the minimum?

Convergence on a quadratic bowl

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.

4 Apply

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.

Key point Work in the principal directions of a quadratic when they are available. Compute the multiplier, track the signed error, then square the error to get each contribution to the loss. See convex optimization for the distinct question of when a local minimum is global.
Level Undergraduate Prerequisites Gradients and quadratic forms Time ~25 min

Further reading