Skip to main content

Curvature of a loss

Derive the Hessians of the mean squared error and of the logistic log loss, see why both are never negative, take the Newton step that lands on the least-squares answer in one move, and find the largest eigenvalue from Hessian-vector products: the curvature that caps the learning rate.
M05.5.4L2 Intermediate25 min
In review (what this means)

The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.

Before this lesson: M05.5.3 Minimum, maximum or saddle: the second-derivative test M05.2 Partial derivatives and the gradient M03.2 Diagonalization and matrix powers

What you will be able to do
  • Derive the Hessian (2/n) XᵀX of the mean squared error and the Hessian (1/n) XᵀSX of the mean log loss, and show that both are positive semidefinite.
  • Derive the Newton step -H⁻¹∇L as the minimiser of the Taylor model, and show that it solves least squares in one step from any start.
  • Compute a Hessian-vector product from two gradients and find the largest eigenvalue with the power method.
  • Explain why gradient descent on a quadratic is stable exactly when the learning rate is below 2/λ_max.

The question

Train the line \({\hat y = wx + b}\) on the four running points by gradient descent. How large can the learning rate be before the steps blow up instead of settling? And is there a step that lands on the best line \({(1.4, 0.5)}\) in one move, from anywhere? Both answers are written in the loss’s Hessian. The same number, its largest eigenvalue, is the sharpness that deep-learning practice watches during training.

From the last lesson

1. State the verdict for each sign pattern of the eigenvalues of \(\mat{H}\) at a critical point.

Show answer

All positive: a strict local minimum. All negative: a strict local maximum. Both signs: a saddle. Some zero and the rest of one sign: the test is silent.

2. Why is the running loss’s critical point \({(1.4, 0.5)}\) a minimum?

Show answer

Its Hessian \({[[15, 5], [5, 2]]}\) has \({f_{xx} = 15 > 0}\) and determinant 5 \({> 0}\), so both eigenvalues are positive.

Intuition

The running loss is a valley. Across the valley the walls are steep; along the floor the ground is almost level. The Hessian’s two eigen-directions point across and along, and its two eigenvalues say how sharply the loss curves each way.

A contour map of the running loss L of w and b, with w from minus 0.1 to 3.1 and b from minus 2.2 to 3.2: long, thin, tilted reddish purple ellipses round a black star at (1.4, 0.5). A long pale orange line along the ellipses is labelled lambda about 0.30 and a short one across them is labelled lambda about 16.70. Beside the map: the Hessian of the loss, H equals 2 over n X transpose X equals rows 15, 5 and 5, 2; across the valley the curvature is 16.70, along it only 0.30; ratio about 56, the same everywhere, because a quadratic loss has a constant Hessian.
M05.5.4-F1

The running loss is steep across its valley and nearly flat along it: curvatures 16.70 and 0.30.

A ratio of about 56 between the two curvatures has consequences. A step size that is safe across the valley crawls along it; a step size that moves briskly along it overshoots across. Newton’s method avoids the dilemma by dividing each direction by its own curvature.

Build it up

Step 1. One example at a time. The loss is the mean of the squared residuals \({(w x_i + b - y_i)^2}\). Write \({\tilde{\vect{x}}_i = (x_i, 1)}\) for example \(i\)’s row of the design matrix, so that its prediction is \({\tilde{\vect{x}}_i\T \vect{w}}\) with \({\vect{w} = (w, b)}\). Example \(i\)’s share of the loss, \({\tfrac1n (\tilde{\vect{x}}_i\T \vect{w} - y_i)^2}\), has gradient \({\tfrac2n (\tilde{\vect{x}}_i\T \vect{w} - y_i)\, \tilde{\vect{x}}_i}\) and Hessian \({\tfrac2n \tilde{\vect{x}}_i \tilde{\vect{x}}_i\T}\).

Step 2. That Hessian is a trough. The matrix \({\tilde{\vect{x}}_i \tilde{\vect{x}}_i\T}\) has rank one. Along any \(\vect{v}\) with \({\tilde{\vect{x}}_i\T \vect{v} = 0}\), a change of weights that leaves example \(i\)’s prediction unchanged, its curvature is zero.

Two contour maps over w from minus 0.1 to 3.1 and b from minus 2.2 to 3.2. Left, titled One example: a trough: straight, parallel reddish purple contour lines of the first example's share of the loss, one quarter of (w plus b minus 2) squared, with a thicker line along w plus b equals 2 and a double-headed arrow along the lines labelled flat along (1, minus 1); notes read Hessian 2 over 4 times rows 1, 1 and 1, 1, eigenvalues 1 and 0. Right, titled Four examples: a bowl: closed tilted ellipses of the running loss round a black star at (1.4, 0.5), with the four examples' zero lines drawn faint and dashed; notes read Hessian rows 15, 5 and 5, 2, eigenvalues 16.70 and 0.30.
M05.5.4-F2

One example’s squared error curves only across its own line of perfect fit. Four examples with different inputs curve in every direction: their troughs add up to a bowl.

Step 3. Add the examples. Summing over the four examples,

\[ \mat{H} = \frac{2}{n} \sum_{i=1}^{n} \tilde{\vect{x}}_i \tilde{\vect{x}}_i\T = \frac{2}{n} \mat{X}\T \mat{X} . \]

For the running points \({\mat{X}\T\mat{X} = \begin{bmatrix} 30 & 10 \\ 10 & 4 \end{bmatrix}}\), so \({\mat{H} = \begin{bmatrix} 15 & 5 \\ 5 & 2 \end{bmatrix}}\), the matrix of M05.5.1.

Step 4. Never negative. For any direction \(\vect{v}\),

\[ \begin{aligned} \vect{v}\T \mat{H} \vect{v} &= \frac{2}{n}\, (\mat{X}\vect{v})\T (\mat{X}\vect{v}) \\ &= \frac{2}{n} \norm{\mat{X}\vect{v}}^2 \ge 0 . \end{aligned} \]

The curvature along \(\vect{v}\) is \({2/n}\) times the squared change of all the predictions. It is zero only if moving along \(\vect{v}\) changes no prediction, which needs dependent columns in \(\mat{X}\). So the mean squared error is a bowl or a trough, never a saddle: it is convex (M08.2).

The formal statement

The mean squared error. With \({L(\vect{w}) = \tfrac1n \norm{\mat{X}\vect{w} - \vect{y}}^2}\), the gradient of M05.2.3 is \({\nabla L(\vect{w}) = \tfrac2n \mat{X}\T (\mat{X}\vect{w} - \vect{y})}\). It is affine in \(\vect{w}\): \({\nabla L(\vect{w} + \vect{h}) = \nabla L(\vect{w}) + \tfrac2n \mat{X}\T\mat{X}\, \vect{h}}\), so its Jacobian, the Hessian, is the constant \({\tfrac2n \mat{X}\T\mat{X}}\).

The mean log loss. For logistic regression \({p_i = \sigma(\tilde{\vect{x}}_i\T \vect{w})}\) and

\[ \begin{aligned} L(\vect{w}) &= -\frac1n \sum_{i=1}^{n} \big( y_i \ln p_i \\ &\qquad + (1 - y_i) \ln(1 - p_i) \big) , \end{aligned} \]

whose gradient (M05.2.3) has entries \({\pd{L}{w_j} = \tfrac1n \sum_i (p_i - y_i)\, x_{ij}}\). Only \(p_i\) depends on the weights, and by \({\sigma' = \sigma(1 - \sigma)}\) (M04.3.3) \({\pd{p_i}{w_k} = p_i(1 - p_i)\, x_{ik}}\). So

\[ \frac{\partial^2 L}{\partial w_k\, \partial w_j} = \frac1n \sum_{i=1}^{n} p_i(1 - p_i)\, x_{ij}\, x_{ik} , \]

which is the matrix

\[ \begin{aligned} \mat{H} &= \frac1n \mat{X}\T \mat{S} \mat{X}, \\ \mat{S} &= \operatorname{diag}\big(p_i(1 - p_i)\big) . \end{aligned} \]

The weights \({p_i(1 - p_i)}\) lie between 0 and \({\tfrac14}\), so \({\vect{v}\T \mat{H}\vect{v} = \tfrac1n \sum_i p_i(1 - p_i)(\tilde{\vect{x}}_i\T \vect{v})^2 \ge 0}\): positive semidefinite again, but now it changes with \(\vect{w}\). The labels \(y_i\) do not appear in it at all.

The Newton step. Minimise the Taylor model \({q(\vect{h}) = L + \nabla L\T \vect{h} + \tfrac12 \vect{h}\T \mat{H}\vect{h}}\) over \(\vect{h}\). Its gradient in \(\vect{h}\) is \({\nabla L + \mat{H}\vect{h}}\); setting it to zero,

\[ \vect{h}_{\text{Newton}} = -\mat{H}^{-1} \nabla L , \]

the unique minimiser when \(\mat{H}\) is positive definite. When \(L\) is itself quadratic the model is exact, so the Newton step lands on the minimum. Methods built on it are M08.5.

Curvature without the matrix. A model with a million weights has a Hessian with \({10^{12}}\) entries. But the gradient’s linear approximation gives a Hessian-vector product from two gradients,

\[ \mat{H}\vect{v} \approx \frac{\nabla L(\vect{w} + \epsilon\vect{v}) - \nabla L(\vect{w} - \epsilon\vect{v})}{2\epsilon} , \]

exact for a quadratic. Feed it to the power method of M03.2.4, \({\vect{v} \leftarrow \mat{H}\vect{v} / \norm{\mat{H}\vect{v}}}\), and \({\vect{v}\T \mat{H}\vect{v}}\) converges to the largest eigenvalue \({\lambda_{\max}}\), provided the start is not perpendicular to its eigenvector. (The power method finds the eigenvalue of largest size; for these losses no eigenvalue is negative, so that is \({\lambda_{\max}}\).)

Left, titled Two gradients: a contour map of the running loss with two orange points, w plus epsilon v at (0.6, 1.5) and w minus epsilon v at (0.6, 0.5), joined by a dashed orange line, each with a green gradient arrow; a note gives the gradients (minus 12, minus 4) and (minus 7, minus 2) and their difference (5, 2) equals 2 epsilon H v. Right, titled Error of v transpose H v against 16.70: on a log scale an orange line falls from 14.7 at step 0 through 0.045 at step 1 to about 10 to the minus 8 at step 3.
M05.5.4-F5

Left: two gradients a step \(\epsilon\) either side give \({\mat{H}\vect{v}}\) without forming \(\mat{H}\). Right: the power method built on such products finds the sharpness 16.70 in a few steps.

Why \({\lambda_{\max}}\) caps the learning rate. On a quadratic loss \({\nabla L(\vect{w}) = \mat{H}(\vect{w} - \vect{w}^*)}\), so a gradient step \({\vect{w}_{t+1} = \vect{w}_t - \eta \nabla L(\vect{w}_t)}\) moves the error \({\vect{e}_t = \vect{w}_t - \vect{w}^*}\) as

\[ \vect{e}_{t+1} = (\mat{I} - \eta \mat{H})\, \vect{e}_t . \]

Along eigenvector \(\vect{q}_i\) the error is multiplied by \({1 - \eta\lambda_i}\) at every step. It shrinks in every direction exactly when \({\abs{1 - \eta \lambda_i} < 1}\) for all \(i\), that is when \({0 < \eta < 2/\lambda_{\max}}\) (M03.8.4). For the running loss \({2/16.70 \approx 0.1198}\).

Frontier note: the edge of stability

Cohen and co-authors (ICLR 2021) measured the sharpness \({\lambda_{\max}}\) of the training loss while training neural networks by full-batch gradient descent with step size \(\eta\). Their finding, in the words of their abstract: the sharpness “hovers just above” \({2/\eta}\). Training does not stay in the region where the quadratic analysis above promises stability: the loss behaves non-monotonically over short timescales, yet keeps decreasing over long ones. Measuring the sharpness of a large network is itself a job for Hessian-vector products, since the matrix is far too big to form.

Worked example

One Newton step from the origin on the running loss.

Gradient. At the origin only the constants of \({(15w + 5b - 23.5,\; 5w + 2b - 8)}\) remain: \({\nabla L(0, 0) = (-23.5, -8)}\).

Inverse Hessian. \({\det \mat{H} = 15 \times 2 - 5 \times 5 = 5}\), so swapping the diagonal and negating the off-diagonal gives

\[ \mat{H}^{-1} = \frac15 \begin{bmatrix} 2 & -5 \\ -5 & 15 \end{bmatrix} . \]

Product. Row by row,

\[ \begin{aligned} \text{row 1:}\;\; &\tfrac15 \big( 2(-23.5) - 5(-8) \big) \\ &\quad = \tfrac15 (-7) = -1.4 , \\ \text{row 2:}\;\; &\tfrac15 \big( -5(-23.5) + 15(-8) \big) \\ &\quad = \tfrac15 (-2.5) = -0.5 , \end{aligned} \]

so \({\mat{H}^{-1}\nabla L = (-1.4, -0.5)}\).

Step. \({-\mat{H}^{-1}\nabla L = (1.4, 0.5)}\), so the new point is \({(0, 0) + (1.4, 0.5) = (1.4, 0.5)}\): the least-squares line, in one step. From \({(2.5, -1.5)}\), where \({\nabla L = (6.5, 1.5)}\), the same calculation gives the step \({(-1.1, 2)}\), and again \({(2.5 - 1.1,\; -1.5 + 2) = (1.4, 0.5)}\).

A contour map of the running loss with three orange starting points, (0, 0), (2.5, minus 1.5) and (0.3, 2.6). From each a thick green arrow, the Newton step, runs straight to the black star at (1.4, 0.5). From each a short dashed sky-blue arrow shows the steepest-descent direction minus gradient L; from the origin it nearly agrees with the Newton step, from the other two it points well away from the star. Beside the map the arithmetic from the origin: gradient (minus 23.5, minus 8), H inverse equals one fifth of rows 2, minus 5 and minus 5, 15, H inverse times gradient equals (minus 1.4, minus 0.5), step (1.4, 0.5).
M05.5.4-F3

Every Newton step lands on the minimum, because the loss equals its own quadratic model. The steepest-descent directions miss it, by far from two of the three starts.

Compare gradient descent. With \({\eta = 0.1}\) the first step from the origin is \({-0.1\,(-23.5, -8) = (2.35, 0.8)}\), which overshoots in \(w\); reaching the minimum takes many steps, because along the valley the error shrinks only by the factor \({1 - 0.1 \times 0.299 \approx 0.97}\) per step.

Code

The Hessian of the mean squared error from the design matrix, its eigenvalues and the largest stable learning rate:

import numpy as np

x = np.array([1.0, 2.0, 3.0, 4.0])
y = np.array([2.0, 3.0, 5.0, 6.0])
X = np.column_stack([x, np.ones(4)])
n = len(x)

def grad_mse(w):
    return 2 / n * X.T @ (X @ w - y)

H = 2 / n * X.T @ X
lam = np.linalg.eigvalsh(H)
print(H)
print("eigenvalues", lam.round(4), " condition number", round(lam[1] / lam[0], 1),
      " 2/lambda_max", round(2 / lam[1], 4))
[[15.  5.]
 [ 5.  2.]]
eigenvalues [ 0.2994 16.7006]  condition number 55.8  2/lambda_max 0.1198

Newton steps from three starts, and a Hessian-vector product fed to the power method. The product uses only the gradient function.

starts = [np.array([0.0, 0.0]), np.array([2.5, -1.5]), np.array([0.3, 2.6])]
landed = [w - np.linalg.solve(H, grad_mse(w)) for w in starts]
print("Newton lands at", [p.round(6).tolist() for p in landed])

def hvp(w, v, eps=1e-3):
    return (grad_mse(w + eps * v) - grad_mse(w - eps * v)) / (2 * eps)

v = np.array([0.0, 1.0])
for k in range(20):
    hv = hvp(np.zeros(2), v)
    v = hv / np.linalg.norm(hv)
sharpness = v @ hvp(np.zeros(2), v)
print("power method:", round(sharpness, 4), " eigvalsh:", round(lam[1], 4))
Newton lands at [[1.4, 0.5], [1.4, 0.5], [1.4, 0.5]]
power method: 16.7006  eigvalsh: 16.7006

Gradient descent just below and just above \({2/\lambda_{\max}}\), from the start of the pitfall figure:

def descend(eta, steps, w=(0.3, 2.2)):
    w = np.array(w, dtype=float)
    for _ in range(steps):
        w = w - eta * grad_mse(w)
    return np.linalg.norm(w - [1.4, 0.5])

for eta in (0.10, 0.11, 0.13):
    print(f"eta = {eta}: distance after 12 steps {descend(eta, 12):.3f}, after 200 steps {descend(eta, 200):.2e}")
eta = 0.1: distance after 12 steps 1.364, after 200 steps 4.50e-03
eta = 0.11: distance after 12 steps 1.315, after 200 steps 2.42e-03
eta = 0.13: distance after 12 steps 3.506, after 200 steps 2.58e+13

Finally the log loss, with invented labels \({y = (0, 0, 1, 1)}\) on the same inputs: the formula \({\tfrac1n \mat{X}\T\mat{S}\mat{X}}\) against central differences of the gradient.

labels = np.array([0.0, 0.0, 1.0, 1.0])
sigmoid = lambda z: 1 / (1 + np.exp(-z))

def grad_log(w):
    return X.T @ (sigmoid(X @ w) - labels) / n

def hess_log(w):
    p = sigmoid(X @ w)
    return X.T @ np.diag(p * (1 - p)) @ X / n

for w in (np.zeros(2), np.array([1.0, -2.5])):
    fd = np.column_stack([(grad_log(w + e) - grad_log(w - e)) / 2e-5 for e in 1e-5 * np.eye(2)])
    print(w, hess_log(w).round(4).tolist(), " eigenvalues", np.linalg.eigvalsh(hess_log(w)).round(4),
          " largest gap to differences", f"{np.abs(fd - hess_log(w)).max():.0e}")
[0. 0.] [[1.875, 0.625], [0.625, 0.25]]  eigenvalues [0.0374 2.0876]  largest gap to differences 2e-10
[ 1.  -2.5] [[1.3976, 0.4802], [0.4802, 0.1921]]  eigenvalues [0.0242 1.5655]  largest gap to differences 2e-11

At \({\vect{w} = \vect{0}}\) every \({p_i = \tfrac12}\), so \({\mat{S} = \tfrac14 \mat{I}}\) and the log loss’s Hessian is \({\tfrac1{16}\mat{X}\T\mat{X}}\), which is \({[[1.875, 0.625], [0.625, 0.25]]}\): one eighth of the mean squared error’s.

Explore

The curvature viewer in lesson M05.5.2 shows curvature at any point. On the running bowl the eigenvalues 2 and 4 never change as you drag the point; on Rosenbrock they change everywhere, which is why one Newton step is not enough there.

Pitfalls

Two contour maps of the running loss, each with a gradient-descent path of 12 green steps starting from a ringed point at (0.3, 2.2). Left, marked with a cross and titled eta equals 0.13, above 2 over lambda max: the path zigzags back and forth across the valley in ever longer strokes, reaching from w equals minus 2 to w equals 3.6; the note reads distance to the minimum 2.02 at the start, 3.51 after 12 steps. Right, marked with a tick and titled eta equals 0.10, below 2 over lambda max: the path drops into the valley floor in short strokes and creeps towards the star; the note reads 2.02 at the start, 1.36 after 12 steps.
M05.5.4-F4

Wrong beside right. Just above \({2/\lambda_{\max} \approx 0.12}\) the steps across the valley grow at every step; just below it they die away.

“A learning rate is fine as long as it is small compared with the gradient.”

What matters is the learning rate times the curvature. Across the running loss’s valley each step multiplies the error by \({1 - 16.70\,\eta}\): for \({\eta = 0.13}\) that is about \(-1.17\), so the error flips sign and grows by 17 per cent every step. The safe range is set by the sharpest direction, \({\eta < 2/\lambda_{\max}}\), whatever the size of the gradient.

“Just below \({2/\lambda_{\max}}\) is the best learning rate.”

It keeps the steep direction stable, but along the flat direction the error then shrinks only by \({1 - 0.1198 \times 0.299 \approx 0.964}\) per step. With a condition number of about 56, one fixed learning rate cannot suit both directions; that is the cost of ill-conditioning (M03.8.4), and the reason for Newton-like and adaptive methods (M08.4, M08.5).

“The Newton step always goes downhill.”

Only when \(\mat{H}\) is positive definite. On the saddle \({x^2 - y^2}\) the Newton step from any point jumps to the critical point at the origin, because the model’s only flat point is there. From \({(0.5, 1)}\), where \({f = -0.75}\), it lands at the origin, where \({f = 0}\): uphill. Practical methods check the curvature first (M08.5).

Check yourself

Recall

1. What is the Hessian of the mean squared error \({\tfrac1n \norm{\mat{X}\vect{w} - \vect{y}}^2}\), and its value for the running points?

Show answer

\({\tfrac2n \mat{X}\T\mat{X}}\), the same at every \(\vect{w}\); for the running points \({[[15, 5], [5, 2]]}\).

2. Why is that Hessian never negative in any direction?

Show answer

\({\vect{v}\T \mat{H}\vect{v} = \tfrac2n \norm{\mat{X}\vect{v}}^2 \ge 0}\): the curvature along \(\vect{v}\) is the squared change of the predictions.

3. What is the Hessian of the mean log loss of logistic regression?

Show answer

\({\tfrac1n \mat{X}\T\mat{S}\mat{X}}\) with \({\mat{S} = \operatorname{diag}(p_i(1 - p_i))}\). It depends on the weights through the \(p_i\) but not on the labels.

4. What is the Newton step, and why does one step solve least squares?

Show answer

\({-\mat{H}^{-1}\nabla L}\), the minimiser of the quadratic Taylor model. The mean squared error is quadratic, so it equals its model and the model’s minimiser is the true minimiser.

5. For which learning rates does gradient descent on a quadratic loss converge, and what is the limit for the running loss?

Show answer

For \({0 < \eta < 2/\lambda_{\max}}\). For the running loss \({2/16.70 \approx 0.12}\).

Exercises

1. ★ A line is fitted by mean squared error to three points with inputs \({x = 0, 1, 2}\). Find the Hessian of the loss in \({(w, b)}\) and the largest stable learning rate.

Show solution

\({\mat{X}\T\mat{X} = \begin{bmatrix} \sum x_i^2 & \sum x_i \\ \sum x_i & n \end{bmatrix} = \begin{bmatrix} 5 & 3 \\ 3 & 3 \end{bmatrix}}\), so \({\mat{H} = \tfrac23 \mat{X}\T\mat{X} = \begin{bmatrix} 10/3 & 2 \\ 2 & 2 \end{bmatrix}}\), whatever the targets. Its trace is \({16/3}\) and determinant \({20/3 - 4 = 8/3}\), so

\[ \begin{aligned} \lambda &= \frac{16 \pm \sqrt{160}}{6} \\ &\approx 4.775 \text{ or } 0.558 , \end{aligned} \]

and the largest stable learning rate is \({2/4.775 \approx 0.419}\).

2. ★★ Take one Newton step on the running loss from \({(2.5, -1.5)}\) by hand.

Show solution

The gradient \({(15w + 5b - 23.5,\; 5w + 2b - 8)}\) at \({(2.5, -1.5)}\) has first entry \(37.5 - 7.5 - 23.5 = 6.5\) and second entry \(12.5 - 3 - 8 = 1.5\).

With \({\mat{H}^{-1} = \tfrac15 [[2, -5], [-5, 15]]}\) the first entry of \({\mat{H}^{-1}\nabla L}\) is \({\tfrac15 (13 - 7.5)} = 1.1\) and the second is \({\tfrac15 (-32.5 + 22.5)} = -2\).

The new point is \({(2.5 - 1.1,\; -1.5 + 2) = (1.4, 0.5)}\).

3. ★★★ Show that for every \(\vect{w}\) and \(\vect{v}\) the log loss’s curvature is at most one eighth of the mean squared error’s on the same inputs, and that the bound is reached at \({\vect{w} = \vect{0}}\). What is the log loss’s largest curvature for the running inputs?

Show solution

For the log loss \({\vect{v}\T\mat{H}\vect{v} = \tfrac1n \sum_i p_i(1 - p_i)(\tilde{\vect{x}}_i\T\vect{v})^2}\). Since \({p(1 - p) \le \tfrac14}\) for every \(p\) (the parabola peaks at \({p = \tfrac12}\)),

\[ \begin{aligned} \vect{v}\T\mat{H}\vect{v} &\le \frac{1}{4n} \norm{\mat{X}\vect{v}}^2 \\ &= \frac18 \cdot \frac2n \norm{\mat{X}\vect{v}}^2 , \end{aligned} \]

and the right side is one eighth of the mean squared error’s curvature. At \({\vect{w} = \vect{0}}\) every \({p_i = \tfrac12}\), so equality holds for every \(\vect{v}\). The largest curvature is then \({16.70 / 8 \approx 2.09}\), and no point has a larger one.

Summary card

A loss’s Hessian sets its shape, its Newton step and its learning rate.

The anchor figure again: the running loss's long tilted ellipses with the eigen-directions marked lambda about 16.70 across and lambda about 0.30 along the valley.
M05.5.4-F1

Steep across, flat along.

  • Least squares. \({\mat{H} = \tfrac2n \mat{X}\T\mat{X}}\), constant and positive semidefinite.
  • Log loss. \({\mat{H} = \tfrac1n \mat{X}\T\mat{S}\mat{X}}\), \({\mat{S} = \operatorname{diag}(p_i(1 - p_i))}\).
  • Newton. \({\vect{h} = -\mat{H}^{-1}\nabla L}\): one step for a quadratic.
  • Sharpness. \({\lambda_{\max}}\) by power iteration on \({\mat{H}\vect{v}}\); stable if \({\eta < 2/\lambda_{\max}}\).

Sources and next steps

Sources. Each was opened and checked against this lesson on 15 November 2026.

  • Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong, Mathematics for Machine Learning, Section 9.2.1, the remark after equation (9.12c): the Hessian of the least-squares objective is \({\mat{X}\T\mat{X}}\) (their objective has a different constant factor), positive definite when \(\mat{X}\) has full column rank, so the stationary point is a global minimum.
  • Andrew Ng and Tengyu Ma, CS229 Lecture Notes, Stanford, Section 2.4: Newton’s method \({\theta := \theta - \mat{H}^{-1}\nabla_\theta \ell(\theta)}\) with the Hessian of second partial derivatives, applied to logistic regression.
  • Alan Edelman and Steven G. Johnson, Matrix Calculus for Machine Learning and Beyond, Section 12.4.1 (minimising the quadratic model is the Newton step \({-\mat{H}^{-1}\nabla f}\)) and Section 12.4.2 (Hessian-vector products without forming \(\mat{H}\)).
  • Jeremy Cohen, Simran Kaur, Yuanzhi Li, J. Zico Kolter and Ameet Talwalkar, Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability, ICLR 2021: the abstract’s finding that the largest Hessian eigenvalue of the training loss hovers just above \({2/\eta}\).
  • NumPy reference, numpy.linalg.eigvalsh.

Next. Module M05.6, Multiple integrals and change of variables, turns from derivatives to integrals over regions of the plane. Curvature returns in course M08: step sizes in M08.3 and Newton and quasi-Newton methods in M08.5.

This lesson unlocks

M05.6 Multiple integrals and change of variables M08.3 Gradient descent and step sizes (planned) M08.5 Newton and quasi-Newton methods (planned)

Your progress is saved in this browser only. No account, no tracking.
Back to top