Mathematical Foundations

VI.4 · Optimization

Can you explain every component of one parameter update?

Freeze the current parameters, evaluate their gradient, scale it by a negative learning rate, and add the resulting displacement. Replay the evaluated states to see exactly why the optimizer moved.

Replay every evaluated gradient descent step

Parameter space: θ₁ and θ₂

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Stop: iteration budget. Parameters outside the displayed window are retained in the table; the view never changes the path.

Loss slice: θ₂ = 0

This is a slice of the objective in parameter space, with θ₂ fixed at zero.

Current parameter vector
(2, 1)
Current objective value
4
Actual gradient components
(2, 4)
Learning rate
0.250000
Update vector
(−0.5, −1)
Next parameter vector
(1.5, 0)
New objective value
1.125000

≈ binary64 calculation · = analytic classification. Replay selects the same evaluated step in every view.

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Stop: iteration budget. Parameters outside the displayed window are retained in the table; the view never changes the path.

L=a2(θ1−c)2+2θ22L=\tfrac a2(\theta_1-c)^2+2\theta_2^2
θk+1=θk−η∇L(θk)\theta_{k+1}=\theta_k-\eta\nabla L(\theta_k)
θ1≈[21]+[−0.5−1]≈[1.50]\theta_{1}\approx \begin{bmatrix}2\\1\end{bmatrix}+\begin{bmatrix}-0.5\\-1\end{bmatrix}\approx \begin{bmatrix}1.5\\0\end{bmatrix}
Evaluated binary64 history. Replay changes the selected row, never the stored mathematics.
kθ(k)L(k)gradientηupdateθ(k+1)L(k+1)
0(2, 1)4(2, 4)0.25(−0.5, −1)(1.5, 0)1.125
1(1.5, 0)1.125(1.5, 0)0.25(−0.375, 0)(1.125, 0)0.632813
2(1.125, 0)0.632813(1.125, 0)0.25(−0.28125, 0)(0.84375, 0)0.355957
3(0.84375, 0)0.355957(0.84375, 0)0.25(−0.210938, 0)(0.632813, 0)0.200226
4(0.632813, 0)0.200226(0.632813, 0)0.25(−0.158203, 0)(0.474609, 0)0.112627
5(0.474609, 0)0.112627(0.474609, 0)0.25(−0.118652, 0)(0.355957, 0)0.063353
6(0.355957, 0)0.063353(0.355957, 0)0.25(−0.088989, 0)(0.266968, 0)0.035636
7(0.266968, 0)0.035636(0.266968, 0)0.25(−0.066742, 0)(0.200226, 0)0.020045
8(0.200226, 0)0.020045(0.200226, 0)0.25(−0.050056, 0)(0.150169, 0)0.011275
9(0.150169, 0)0.011275(0.150169, 0)0.25(−0.037542, 0)(0.112627, 0)0.006342
10(0.112627, 0)0.006342(0.112627, 0)0.25(−0.028157, 0)(0.08447, 0)0.003568
11(0.08447, 0)0.003568(0.08447, 0)0.25(−0.021118, 0)(0.063353, 0)0.002007

Evaluated iteration 0

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss.

θ1≈[21]+[−0.5−1]≈[1.50]\theta_{1}\approx \begin{bmatrix}2\\1\end{bmatrix}+\begin{bmatrix}-0.5\\-1\end{bmatrix}\approx \begin{bmatrix}1.5\\0\end{bmatrix}

from −3 to 3, up to 2 decimal places

from −3 to 3, up to 2 decimal places

from 0.25 to 4, up to 2 decimal places

from −2 to 2, up to 2 decimal places

from 0.01 to 2, up to 2 decimal places

from 1 to 40, whole numbers only

Replay one evaluated iteration at a time. Match current parameters, loss, gradient, rate, update, and next parameters with the actual displacement arrow and binary64 history.

Start with θ0=(2,1)\theta_0=(2,1), η=1/4\eta=1/4, and L=x2/2+2y2L=x^2/2+2y^2. Before advancing, predict the gradient (2,4)(2,4), the displacement (−1/2,−1)(-1/2,-1), the next point (3/2,0)(3/2,0), and the loss change 4→9/84\to9/8. The stage’s trajectory uses binary64; the hand calculation below is exact.

Intuition: downhill direction plus a chosen distance

The gradient points toward the steepest local increase per unit Euclidean distance. Negating it gives a locally downhill direction. The learning rate scales that vector into a displacement, and adding the displacement produces a new parameter choice.

One step is not an instruction to move directly to the minimum. It uses information at the current point, and the shape can change along the way. Even a downhill direction can cross a valley and end at a higher loss if the distance is too large. The next step must evaluate the gradient again at the new point rather than reuse an earlier one.

Definition: the update recurrence

For a differentiable objective, gradient descent with positive learning rate η\eta uses

gk=∇L(θk),Δθk=−ηgk,θk+1=θk+Δθk.g_k=\nabla L(\theta_k),\qquad \Delta\theta_k=-\eta g_k,\qquad \theta_{k+1}=\theta_k+\Delta\theta_k.

The gradient, update vector, and next parameter vector are distinct. gkg_k contains sensitivity; Δθk\Delta\theta_k contains a signed movement; θk+1\theta_{k+1} is an absolute point. With a fixed objective and fixed rate, the recurrence is deterministic. A stopping policy decides when the finite computation ends, which is separate from the mathematical definition of an iteration.

The recurring model is L=a(x−c)2/2+2y2L=a(x-c)^2/2+2y^2, with default a=1,c=0a=1,c=0, gradient (a(x−c),4y)(a(x-c),4y), and Hessian diag⁡(a,4)\operatorname{diag}(a,4). This chapter uses full objective gradients; stochastic estimates and momentum are later algorithms with additional state or assumptions.

Mechanics: account for every quantity in the inspector

For the selected iteration, read current θk\theta_k, current loss, actual gradient, learning rate, update vector, next θ\theta, and next loss. The update arrow must start at θk\theta_k and end at θk+1\theta_{k+1}, so its coordinate difference is exactly the stored displacement. The table retains the evaluated binary64 history, including points outside the drawing window.

Next, previous, and direct selection choose stored iteration states. They do not numerically undo a step or recompute a new path. Reset restores the canonical quadratic, start (2,1)(2,1), rate 1/41/4, and iteration budget. Editing the start, rate, or objective produces a different run; changing the replay cursor only selects an already evaluated step.

Every derivative for a step is evaluated at the same current vector before either coordinate changes. Computing the x update, then using that newly changed x to evaluate the y update would generally be a different algorithm. This separable quadratic can conceal such an error, so keep the simultaneous vector rule explicit.

Derivation: why the negative gradient, and why it can overshoot

For a unit direction uu, differentiability gives the first-order rate

DuL(θ)=g⋅u≥−∥g∥,D_uL(\theta)=g\cdot u\geq-\norm{g},

by Cauchy–Schwarz. For g≠0g\ne0, equality holds at u=−g/∥g∥u=-g/\norm{g}: the negative-gradient direction is steepest decrease under the Euclidean distance convention. Choosing displacement −ηg-\eta g gives step length η∥g∥\eta\norm{g} and linear predicted change −η∥g∥2-\eta\norm{g}^2. At g=0g=0, the update is the well-defined zero vector; no normalization is needed.

The quadratic’s exact expansion includes curvature:

L(θ−ηg)−L(θ)=−η∥g∥2+η22gTHg.L(\theta-\eta g)-L(\theta) =-\eta\norm{g}^2+\frac{\eta^2}{2}g^{\mathsf T}Hg.

The first term is negative for a nonzero gradient, but the second term can dominate for a large rate. For the default Hessian diag⁡(1,4)\operatorname{diag}(1,4),

gTHg≤4∥g∥2,L(θ−ηg)−L(θ)≤−η(1−2η)∥g∥2.g^{\mathsf T}Hg\leq4\norm{g}^2, \qquad L(\theta-\eta g)-L(\theta) \leq-\eta(1-2\eta)\norm{g}^2.

Thus 0<η<1/20<\eta<1/2 guarantees a strict loss decrease whenever the gradient is nonzero for this particular quadratic. The largest curvature matters. Detailed convergence behavior belongs to VI.5; a small learning rate is not a universal guarantee for an arbitrary objective or invalid domain.

Worked example: the complete canonical step

Substitute the current parameters before moving them:

θ0=(2,1),L0=222+2(1)2=4,g0=(2,4).\theta_0=(2,1),\qquad L_0=\frac{2^2}{2}+2(1)^2=4,\qquad g_0=(2,4).

Scale both components and add the displacement:

Δθ0=−14(2,4)=(−12,−1),θ1=(2,1)+(−12,−1)=(32,0).\Delta\theta_0=-\frac14(2,4)=\left(-\frac12,-1\right), \qquad \theta_1=(2,1)+\left(-\frac12,-1\right)=\left(\frac32,0\right).

The new loss is L1=(3/2)2/2=9/8L_1=(3/2)^2/2=9/8. As an independent check, ∥g0∥2=20\norm{g_0}^2=20 and g0THg0=68g_0^{\mathsf T}Hg_0=68. The exact loss change is −20/4+68/32=−23/8-20/4+68/32=-23/8, agreeing with 9/8−49/8-4.

Worked example: Replay every evaluated gradient descent step

Parameter space: θ₁ and θ₂

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Stop: iteration budget. Parameters outside the displayed window are retained in the table; the view never changes the path.

Loss slice: θ₂ = 0

This is a slice of the objective in parameter space, with θ₂ fixed at zero.

Current parameter vector
(2, 1)
Current objective value
4
Actual gradient components
(2, 4)
Learning rate
0.250000
Update vector
(−0.5, −1)
Next parameter vector
(1.5, 0)
New objective value
1.125000

≈ binary64 calculation · = analytic classification. Replay selects the same evaluated step in every view.

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss. Stop: iteration budget. Parameters outside the displayed window are retained in the table; the view never changes the path.

L=a2(θ1−c)2+2θ22L=\tfrac a2(\theta_1-c)^2+2\theta_2^2
θk+1=θk−η∇L(θk)\theta_{k+1}=\theta_k-\eta\nabla L(\theta_k)
θ1≈[21]+[−0.5−1]≈[1.50]\theta_{1}\approx \begin{bmatrix}2\\1\end{bmatrix}+\begin{bmatrix}-0.5\\-1\end{bmatrix}\approx \begin{bmatrix}1.5\\0\end{bmatrix}
Evaluated binary64 history. Replay changes the selected row, never the stored mathematics.
kθ(k)L(k)gradientηupdateθ(k+1)L(k+1)
0(2, 1)4(2, 4)0.25(−0.5, −1)(1.5, 0)1.125
1(1.5, 0)1.125(1.5, 0)0.25(−0.375, 0)(1.125, 0)0.632813
2(1.125, 0)0.632813(1.125, 0)0.25(−0.28125, 0)(0.84375, 0)0.355957
3(0.84375, 0)0.355957(0.84375, 0)0.25(−0.210938, 0)(0.632813, 0)0.200226
4(0.632813, 0)0.200226(0.632813, 0)0.25(−0.158203, 0)(0.474609, 0)0.112627
5(0.474609, 0)0.112627(0.474609, 0)0.25(−0.118652, 0)(0.355957, 0)0.063353
6(0.355957, 0)0.063353(0.355957, 0)0.25(−0.088989, 0)(0.266968, 0)0.035636
7(0.266968, 0)0.035636(0.266968, 0)0.25(−0.066742, 0)(0.200226, 0)0.020045
8(0.200226, 0)0.020045(0.200226, 0)0.25(−0.050056, 0)(0.150169, 0)0.011275
9(0.150169, 0)0.011275(0.150169, 0)0.25(−0.037542, 0)(0.112627, 0)0.006342
10(0.112627, 0)0.006342(0.112627, 0)0.25(−0.028157, 0)(0.08447, 0)0.003568
11(0.08447, 0)0.003568(0.08447, 0)0.25(−0.021118, 0)(0.063353, 0)0.002007

Evaluated iteration 0

Iteration 0: at θ ≈ (2, 1), L ≈ 4 and gradient ≈ (2, 4). Rate η ≈ 0.25 gives update ≈ (−0.5, −1). Adding that update gives θ next ≈ (1.5, 0) and L next ≈ 1.125. The step follows the negative gradient; a finite step can still increase loss.

θ1≈[21]+[−0.5−1]≈[1.50]\theta_{1}\approx \begin{bmatrix}2\\1\end{bmatrix}+\begin{bmatrix}-0.5\\-1\end{bmatrix}\approx \begin{bmatrix}1.5\\0\end{bmatrix}

Replay the canonical binary64 step beside its exact hand calculation: gradient (2,4), update (−1/2,−1), next point (3/2,0), and losses 4 → 9/8.

For the second step, recompute g1=(3/2,0)g_1=(3/2,0). The new displacement is (−3/8,0)(-3/8,0), so θ2=(9/8,0)\theta_2=(9/8,0) and L2=81/128L_2=81/128. These are exact rational values; their dyadic denominators also make these first binary64 evaluations exactly representable.

More generally the component recurrence is

xk+1−c=(1−ηa)(xk−c),yk+1=(1−4η)yk.x_{k+1}-c=(1-\eta a)(x_k-c),\qquad y_{k+1}=(1-4\eta)y_k.

For the default canonical run, y becomes zero after the first step, while xk=2(3/4)kx_k=2(3/4)^k. In exact arithmetic x tends to zero but remains positive at every finite k. A plotted line reaching the origin after rounding does not change that statement.

Executable reference code

The standard-library program records exact step dictionaries containing the current vector, loss, gradient, rate, displacement, next vector, and next loss. Its literal assertions verify the first two canonical steps, then independently compare repeated updates with the closed-form recurrence. A zero-gradient point has a zero displacement, and a larger-rate example verifies a real loss increase.

The NumPy version evolves several starting points simultaneously using matrix multiplication. Time steps remain sequential because each depends on the previous one; the batch axis is vectorized. A separate broadcasted closed form cross-checks the entire bounded path within absolute tolerance 10−1410^{-14}. These numerical trajectories are binary64 approximations even when the first dyadic values happen to be exact.

code/python/optimization_descent.py
"""Exact quadratic descent frames, independently checked against a closed form."""
from fractions import Fraction as F


def loss(theta, a=1, c=0):
    x, y = theta
    return F(a)*(x-F(c))**2/2 + 2*y*y


def step(theta, eta, a=1, c=0):
    x, y = map(F, theta)
    eta, a, c = F(eta), F(a), F(c)
    if eta <= 0:
        raise ValueError("The descent learning rate must be positive")
    gradient = (a*(x-c), 4*y)
    update = tuple(-eta*g for g in gradient)
    next_theta = (x+update[0], y+update[1])
    return {
        "theta": (x, y), "loss": loss((x, y), a, c),
        "gradient": gradient, "eta": eta, "update": update,
        "next_theta": next_theta, "next_loss": loss(next_theta, a, c),
    }


def trajectory(theta, eta, iterations, a=1, c=0):
    if type(iterations) is not int or not 0 <= iterations <= 1000:
        raise ValueError("Require an integer iteration count in [0,1000]")
    theta, eta = tuple(map(F, theta)), F(eta)
    if eta <= 0:
        raise ValueError("The descent learning rate must be positive")
    frames = []
    for _ in range(iterations):
        frame = step(theta, eta, a, c)
        frames.append(frame)
        theta = frame["next_theta"]
    return frames


def main():
    frame = step((2, 1), F(1, 4))
    assert frame["loss"] == 4 and frame["gradient"] == (2, 4)
    assert frame["update"] == (F(-1, 2), -1)
    assert frame["next_theta"] == (F(3, 2), 0) and frame["next_loss"] == F(9, 8)
    frames = trajectory((2, 1), F(1, 4), 8)
    for k, item in enumerate(frames):
        assert item["theta"][0] == 2*F(3, 4)**k
        assert item["theta"][1] == (1 if k == 0 else 0)
        assert item["next_loss"] < item["loss"]
    assert frames[1]["next_theta"] == (F(9, 8), 0)
    assert frames[1]["next_loss"] == F(81, 128)
    assert step((0, 0), F(1, 4))["update"] == (0, 0)
    assert step((2, 1), F(3, 4))["next_loss"] == F(65, 8) > 4
    assert trajectory((2, 1), F(1, 4), 0) == []
    for eta in (0, -1):
        try:
            step((2, 1), eta)
        except ValueError:
            pass
        else:
            raise AssertionError("Nonpositive learning rate accepted")
    print("Exact first frame:", frame)
    print("Exact second next theta/loss:", frames[1]["next_theta"], frames[1]["next_loss"])
    print("A negative-gradient direction alone does not guarantee a finite-step decrease.")


if __name__ == "__main__":
    main()
code/python/optimization_descent_numpy.py
"""Binary64 simultaneous descent paths, cross-checked by the diagonal recurrence."""
import numpy as np


def trajectories(starts, eta, iterations, a=1.0, c=0.0):
    starts = np.asarray(starts, dtype=np.float64)
    if starts.ndim != 2 or starts.shape[1] != 2 or not np.all(np.isfinite(starts)):
        raise ValueError("Require finite starts of shape (n,2)")
    if not np.isfinite(eta) or eta <= 0 or not np.isfinite(a) or not np.isfinite(c):
        raise ValueError("Require finite parameters and a positive learning rate")
    if type(iterations) is not int or not 0 <= iterations <= 1000:
        raise ValueError("Require an integer iteration count in [0,1000]")
    path = np.empty((iterations+1, len(starts), 2), dtype=np.float64)
    path[0] = starts
    center, hessian = np.array([c, 0.0]), np.diag([a, 4.0])
    for k in range(iterations):
        gradient = (path[k]-center) @ hessian
        path[k+1] = path[k] - eta*gradient
        if not np.all(np.isfinite(path[k+1])):
            raise OverflowError(f"Non-finite binary64 iterate at step {k+1}")
    shifted = path-center
    losses = np.einsum("kni,ij,knj->kn", shifted, hessian, shifted)/2
    if not np.all(np.isfinite(losses)):
        raise OverflowError("Non-finite binary64 loss")
    return path, losses


def main():
    starts = np.array([[2, 1], [-2, -1], [1, 0]], dtype=np.float64)
    path, losses = trajectories(starts, 0.25, 8)
    powers = np.arange(9)[:, None, None]
    closed_form = starts[None, :, :] * np.array([0.75, 0.0])**powers
    np.testing.assert_allclose(path, closed_form, rtol=0, atol=1e-14)
    np.testing.assert_array_equal(path[1, 0], [1.5, 0])
    np.testing.assert_array_equal(losses[:3, 0], [4, 1.125, 0.6328125])
    assert np.all(np.diff(losses, axis=0) < 0)
    _, overshoot_losses = trajectories([[2, 1]], 0.75, 1)
    assert overshoot_losses[1, 0] == 8.125 > 4
    stationary, _ = trajectories([[0, 0]], 0.25, 2)
    assert np.all(stationary == 0)
    for eta in (0, -1, np.nan, np.inf):
        try:
            trajectories([[2, 1]], eta, 1)
        except ValueError:
            pass
        else:
            raise AssertionError("Invalid learning rate accepted")
    print("Binary64 trajectory approximations for the first start:", path[:, 0])
    print("Binary64 loss approximations:", losses[:, 0])
    print("Closed-form cross-check: absolute tolerance 1e-14 on this bounded run.")


if __name__ == "__main__":
    main()

Explore: predict an update before replaying it

Return to (2,1)(2,1) but change the rate to 3/43/4. The gradient remains (2,4)(2,4) because the current point is unchanged. Predict displacement (−3/2,−3)(-3/2,-3) and next point (1/2,−2)(1/2,-2). Its loss is 1/8+8=65/81/8+8=65/8, which exceeds 44. The direction is locally downhill, but the step overshoots in the high-curvature y direction.

Select the saddle x2−y2x^2-y^2 at (0,0)(0,0). Its gradient is zero, so the run has no nonzero step. Compare nearby (0,h)(0,h): the loss is −h2-h^2, proving that the stopped point is not a minimum. Repeat with the peak and the flat minimum to separate algorithmic stopping from classification.

Choose the absolute-value objective at its kink, then the logarithmic objective at x=0x=0. The first has a valid loss but no classical gradient; the second has no valid loss at all. Neither permits an ordinary gradient-descent step from that state. Move the logarithmic start inside x>0x>0 before evaluating an update, and verify the new point remains inside the domain as well.

Common mistakes and counterexamples

Adding +ηg+\eta g follows the ascent direction to first order. Replacing θ\theta with −ηg-\eta g confuses a displacement with a point. Reusing the old gradient after moving fails to implement the stated recurrence. In the canonical example the y component becomes zero, so the second gradient’s y component must also be zero.

A falling loss over several steps does not certify a global optimum. The cubic can settle at its nonglobal local minimum; a saddle can stop immediately. Also keep derivatives with respect to parameters separate from derivatives with respect to data. Training updates model coefficients, while the observed input data are held fixed for this full-objective calculation.

Numerical considerations

The replay is an evaluated binary64 trajectory and is labeled with approximation signs. The exact Fraction demonstration is a separate mathematical calculation; do not use it to imply that a long browser run remains exact. With a non-dyadic rate, rounding starts immediately. With dyadic rates, eventually long products, small changes, or underflow can still affect the stored path.

A displacement smaller than the spacing of representable numbers near a coordinate can disappear when added. A repeated stored state then reports numerical stagnation, not a theorem that the real recurrence attained its limit. Large iterates or gradients can instead overflow. The NumPy reference rejects non-finite results, and the bounded explorer reports invalid domains or its stopping boundary instead of fabricating a valid endpoint.

Loss change, gradient norm, parameter scale, and iteration budget answer different diagnostic questions. This chapter exposes the update; VI.10 will examine stopping criteria in depth. Display precision must never determine whether the gradient is mathematically zero or whether an objective has a global minimum.

Engineering and ML connections

For squared-error regression, each residual contributes a parameter derivative, and the full gradient aggregates these contributions. Automatic differentiation obtains such gradients through a computational graph; the optimizer then performs the separate subtraction shown here. Differentiation computes sensitivity, while optimization uses it to choose the next parameters.

The gradient chapter supplies the directional argument, curvature supplies the finite-step correction, and convexity supplies some global guarantees. Neural-network training repeats the same vector update mechanism over many parameters, but its objective need not be convex. Coordinate units and objective scaling also affect the effective step, which motivates careful learning-rate choices rather than one universal setting.

Exercises

Write the gradient, displacement, and next point as separate quantities. Re-evaluate the gradient for a second iteration and compare actual losses after an oversized step.

calculation

Expose the entire first step

For L=x²/2+2y² at θ=(2,1) and η=1/4, give the gradient x,y components, update x,y components, next x,y coordinates, and next loss.

calculation

Recompute before the next update

After the first step, θ=(3/2,0). With η=1/4, give the new gradient x component, next x, next y, and next loss.

prediction

Check a direction with an exact finite step

Keep θ=(2,1) but use η=3/4 on L=x²/2+2y². Give the next x, next y, and next loss.

explanation

Read a zero-gradient stop honestly

Start gradient descent at the origin of L=x²−y². The gradient is (0,0), so every update is zero. What has the run established?

Choose one answer

explanation

Separate exact algebra from a binary64 trace

A binary64 implementation of the η=1/4 quadratic run eventually rounds the change in x to zero. Which interpretation is justified?

Choose one answer

Summary and checkpoints

A gradient-descent iteration evaluates the current gradient, multiplies by a negative rate, and adds the displacement to the current vector. Check that you can account for every component of (2,1)→(3/2,0)(2,1)\to(3/2,0) and the loss 4→9/84\to9/8, recompute the second gradient, and explain both overshoot and a stopped saddle. The following chapter studies how the learning rate changes the resulting trajectory.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available