Gradient Descent and Sampling Strategies

Chapter 3, Numerical Optimization for Learning

Learning objectives

  • Write the gradient descent step for least squares and follow it by hand for its first steps
  • Read the learning rate's three behaviours (creeping in, swinging across, diverging) from the curvature of the loss, and say why the limit is 2/lambda_max
  • Explain why a direction thousands of times flatter than the steepest barely moves, and why standardizing a feature fixes it
  • Say what converging proves: the descent finds the minimum of the loss it is given, not the physics behind the data

A Step at a Time

Gradient descent fits a model by walking down its loss a step at a time, each step against the gradient and as long as the learning rate says. How long a step may be is set by the loss's curvature: below half a limit, 2/Ξ»max⁑2/\lambda_{\max}, the error creeps in from one side; between half the limit and the limit it overshoots and swings back while converging; past the limit it diverges. On the line from density to porosity in Ogbon-1's sandstone, standardized density at a quarter of the limit reaches least squares' slope, βˆ’0.520 v/v per g/cc, in 100 epochs. On density in g/cc the loss is 9055 times flatter in one direction than in the other, and at 0.95 of its limit the descent ends 100 epochs at +0.073 v/v per g/cc, the wrong sign.

Learning Rate And CurvatureInteractive figure, enable JavaScript to interact.

The Data and the Fit

The figure fits one line, porosity Ο•^=b+w ρb\hat\phi = b + w\,\rho_b, to the 616 samples of sandstone in Ogbon-1, the Petrophysics book's well, as the book's own learning set holds it: porosity is the generator's truth and density is what the book's own tool model records, a running mean over a foot and a half of rock with a stated noise. The set is synthetic, and that is why every number below can be checked. Least squares, by the normal equations, gives an intercept of 1.411 v/v, a slope of βˆ’0.520 v/v per g/cc and an RMSE of 0.0149 v/v, an R2R^2 of 0.836. The figure takes the three sands together because the main sand alone spans only 0.250 to 0.270 v/v of porosity, too little against the tool's noise to show a line: its least squares slope is βˆ’0.024 v/v per g/cc.

The Step

The loss is the mean squared error, J(𝜽)=1nβˆ₯Aπœ½βˆ’π“βˆ₯2J(\boldsymbol\theta) = \tfrac{1}{n}\lVert A\boldsymbol\theta - \boldsymbol\phi\rVert^2, with 𝜽=(b,w)\boldsymbol\theta = (b, w) and AA the density and a column of ones. Its gradient is 2nA⊀(Aπœ½βˆ’π“)\tfrac{2}{n}A^{\top}(A\boldsymbol\theta - \boldsymbol\phi), and a step is

𝜽k+1=𝜽kβˆ’Ξ·β€‰2nA⊀(A𝜽kβˆ’π“)\boldsymbol\theta_{k+1} = \boldsymbol\theta_k - \eta\,\tfrac{2}{n}A^{\top}(A\boldsymbol\theta_k - \boldsymbol\phi)

with Ξ·\eta the learning rate. One full pass over the samples is an epoch; here every epoch is one step, on all 616 samples at once. The descent starts from zero, where the line predicts no porosity at all and the RMSE is 0.2349 v/v.

Curvature Sets the Rate

The loss is a bowl, and its curvature is its Hessian, H=2nA⊀AH = \tfrac{2}{n}A^{\top}A, the same everywhere. Along an eigenvector of HH with eigenvalue Ξ»\lambda a step multiplies the error by 1βˆ’Ξ·Ξ»1 - \eta\lambda. The descent converges only when every such factor lies between βˆ’1 and 1, which is

0<η<2/λmax⁑0 < \eta < 2/\lambda_{\max}

The figure gives the rate as a share rr of that limit, so along the steepest direction each step keeps ∣1βˆ’2r∣|1 - 2r| of the error. Standardized, density has mean 0 and standard deviation 1, and the bowl is as curved in every direction: both eigenvalues are 2.000, and the limit is a rate of 1.000.

Three Behaviours

At a quarter of the limit each step keeps 0.50 of the error and never overshoots: the RMSE goes 0.2349, 0.1182, 0.0605 and 0.0329 v/v in the first three epochs. At half the limit the first step lands on the answer, 0.0149 v/v. At three quarters each step goes past the answer and the next comes back, and the path swings across it; each step still keeps 0.50 of the error, so the RMSE is the same as at a quarter. At the limit each step swings across and keeps all of the error, and the run neither converges nor diverges. Past it the swings grow: at 1.05 of the limit each step multiplies the error by 1.10, and the run is stopped at epoch 25, where its RMSE passes ten times its start.

A Flat Direction

In g/cc the two eigenvalues are 12.301 and 0.00136: the bowl is 9055 times more curved across its valley than along it, because every density sits near 2.27 g/cc and the intercept and the slope can trade against each other along the valley's floor. The limit, a rate of 0.163, is set by the steep direction, and along the flat one each step at 0.95 of the limit keeps 0.99979 of the error: about 4765 epochs for each factor of ee it takes off. After 100 epochs the descent has reached the valley's floor and barely moved along it, and its slope is +0.073 v/v per g/cc. No rate fixes this, since a larger one diverges across the valley. Standardizing does: it makes both curvatures equal, and that is why Section 4.1 fits its models on standardized logs.

What Converging Means

Converged, the descent sits at least squares' answer, βˆ’0.520 v/v per g/cc, and not at the physics' line. A sandstone of grain density 2.65 g/cc full of a fluid of 1.00 g/cc has Ο•=(2.65βˆ’Οb)/(2.65βˆ’1.00)\phi = (2.65 - \rho_b)/(2.65 - 1.00), a slope of βˆ’0.606 v/v per g/cc. The tool's noise in density flattens the line least squares finds, and the descent can only find the minimum of the loss it is given. The rate decides whether it gets there and how soon; what is there is the data's.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.