Skip to content
AI360XpertBeta
Playgrounds

Supervised Learning

Gradient Descent

The gradient measures local change; descent subtracts the learning-rate-scaled gradient and measures the actual result.

Data seed 20260825

Guided steps 1 / 7

Stage 1 of 7: The data

Selected observation 1, x -4.500000, y -8.646135. 34 observations.

  • Observation
  • Selected observation
Edit an observation

Edited coordinates round to 0.01 units; other coordinates keep their exact seeded values. Plot bounds: x ±5, y ±15.

Observations34Observations: 34

What changes when you move one observation?

Drag any observation, use its arrow keys or edit its coordinates. These are the same 34 observations used by every later calculation.

Observation

One measured input x and target y.

Check this stage

Check your understanding

A gradient measures local change. Subtract a scaled gradient, then measure the result: a finite step can lower the loss, overshoot or remain stationary.

Move a line, then move its parameters

Start by moving an observation. Drag it, focus its handle and use the arrow keys, or open Edit an observation and enter its coordinates. Each edit changes the same dataset used by the line, loss, gradient and OLS reference.

In A guess, change the starting slope and intercept. The line predicts y^=wx+b\hat y=wx+b. Its residual is y−y^y-\hat y, positive when an observation is above the line. One number compares the mean squared residual, MSE, with the mean absolute residual, MAE. A residual of magnitude 4 contributes 16 to the squared sum; four residuals of magnitude 1 contribute only 4 between them.

The loss curve holds the current intercept fixed while it varies the slope. The neighbouring contour map varies both parameters. Its circles and trails live in parameter space: a horizontal move changes the slope; a vertical move changes the intercept. They are not movements of an observation.

What does the gradient tell you?

For the regression objective,

L(w,b)=1n∑i(wxi+b−yi)2,∇L=(2n∑i(y^i−yi)xi,2n∑i(y^i−yi)).L(w,b)=\frac1n\sum_i(wx_i+b-y_i)^2, \qquad \nabla L=\left(\frac2n\sum_i(\hat y_i-y_i)x_i,\frac2n\sum_i(\hat y_i-y_i)\right).

The gradient is a vector of partial derivatives. It points locally uphill under the Euclidean norm; its negative gives a local steepest-descent direction. It doesn't tell the optimiser where the minimum is. This local meaning and its dependence on the chosen norm are formalised in Boyd and Vandenberghe's optimisation text.

In The gradient, predict how the slope will change. Switch Vectors between the direction aids and Actual update. Direction aids have a fixed illustrative length of 0.75 parameter units. The actual displacement is −η∇L-\eta\nabla L, whose length changes with both the gradient and the rate η\eta.

A local slope, not a destination

Feeling the slope beneath your feet can tell you which nearby direction descends. It cannot tell you where the whole valley ends, or whether a long stride lands on the opposite wall. The analogy describes local direction; the lab computes the finite endpoint instead of assuming it will be lower.

Check one update by hand

For observations (0,1),(1,3),(2,5)(0,1),(1,3),(2,5) and parameters (w,b)=(1,1)(w,b)=(1,1), predictions are 1,2,31,2,3. Prediction errors are 0,−1,−20,-1,-2, giving

gw=23(0−1−4)=−103,gb=23(0−1−2)=−2.g_w=\frac23(0-1-4)=-\frac{10}{3},\qquad g_b=\frac23(0-1-2)=-2.

At rate η=0.1\eta=0.1, the displacement is (1/3,0.2)(1/3,0.2), so the next parameters are (4/3,1.2)(4/3,1.2). MSE falls from 5/35/3 to approximately 0.5140740.514074. The full update is

(w,b)k+1=(w,b)k−η∇L((w,b)k).(w,b)_{k+1}=(w,b)_k-\eta\nabla L((w,b)_k).

The small hand fixture illustrates the same calculation as the larger seeded dataset. Open Under the hood for the live gradient, displacement, endpoint, endpoint loss and incoming rate for every recorded iteration.

Step, inspect and branch

Press Step in the sixth stage. The parameter trail and loss history record that exact computation. Select Full update slice to inspect f(θ+tΔ)f(\theta+t\Delta): t=0t=0 is the current state, t=1t=1 is the proposed endpoint. The diamond there corresponds to the diamond at the end of the parameter arrow. This differs from the retained fixed-intercept slice, which never carries a trajectory evaluated at changing intercepts.

Play is reader-started and bounded. Pause stops it. Replay starts again from the chosen starting parameters with the current settings. Seeking a recorded step pauses; the next update replaces its former future. A rate change pauses and preserves earlier measurements, while changing the start, objective, multiplier or observations starts a fresh history.

Run to convergence computes bounded chunks and offers Cancel. Its name is an intention, not a promise. The status distinguishes a known optimum within the stated tolerances, a small gradient without a global certificate, three material loss increases, a numerical bound and the 240-update limit. Cancellation retains completed updates. A tiny loss change alone is never called convergence.

Break the rate, then question the guarantee

Choose Make the valley diverge in Too far, then Step. This objective is w2+20b2w^2+20b^2. At (1,1)(1,1) and rate 0.10.1, the first endpoint is (0.8,−3)(0.8,-3) and loss rises from 21 to 180.64. The steep coordinate is multiplied by 1−40η=−31-40\eta=-3. The next steps amplify that alternating error. Back to working restores your complete preceding experiment and history, paused.

Try Contracting zig-zag instead. At rate 0.030.03, the steep-coordinate multiplier is −0.2-0.2: its sign alternates, but its magnitude contracts. Oscillation alone doesn't mean divergence.

For the convex quadratic objectives, each Hessian eigenmode has error multiplier 1−ηλ1-\eta\lambda. Positive-curvature modes contract for 0<η<2/λmax⁡0<\eta<2/\lambda_{\max}. Above 1/λmax⁡1/\lambda_{\max}, some can alternate. At the upper boundary the largest mode need not shrink; above it a present unstable mode grows. A start exactly at the optimum, or without a component in that mode, is an exception. Increasing the rate within the contracting interval needn't improve the convergence speed.

The regression boundaries come from the actual x coordinates. Moving y alone changes the fit and gradient, but cannot change this Hessian. Multiplying the objective by 10 multiplies gradient and curvature by 10; divide the rate by 10 to preserve the same steps. The slider zones state mode behaviour, not an invented goodness score.

A small gradient can be a saddle

Choose Start at a saddle. At the origin of w2−b2w^2-b^2, both partial derivatives are zero, so plain descent takes a zero step. Nearby b values lower the objective: this is not a minimum. Nudge the parameter handle and compare the new behaviour. The status reports a small gradient with saddle curvature, never convergence to a global optimum.

The two-minima polynomial (w2−1)2+b2+0.2w(w^2-1)^2+b^2+0.2w has unequal wells. Different starts can settle near different local minima; no global certificate is supplied. Curved valley uses the standard Rosenbrock function and analytic derivatives, (1−w)2+100(b−w2)2(1-w)^2+100(b-w^2)^2, with known minimum zero at (1,1)(1,1). Its curvature changes with position. Neither it nor the two-minima objective receives the quadratic global rate guarantee. The distinction between stationary saddles and minima is also illustrated in Dive into Deep Learning.

Contours approximate the analytic objective on a labelled 49×49 sample grid. Computed parameters are never projected into the plotting window or clipped to the slider range. Cropped arrows, boundary handles and omitted off-window trajectory segments are labelled; raw values stay in inspection. The loss plot uses a linear vertical scale that adapts to the recorded values.

Every gradient here is exact for the selected objective. Data noise belongs to the generated observations; it is not per-step stochastic gradient noise. The gradient-descent discussion in D2L provides further worked examples and explains why finite steps can overshoot.

Reset controls restores default controls and removes observation edits while retaining the stage and seed. New data changes actual generated observation noise and removes point edits. Shared links reproduce the stage, seed, edits, starting parameters and settings, opening paused at step zero. Recorded history, predictions and quiz answers stay in the session. Local progress only records exploration on this device.

Stage recap

  1. The data

    Drag any observation, use its arrow keys or edit its coordinates. These are the same 34 observations used by every later calculation.

  2. A guess

    Slope and intercept are parameters. Moving either changes every prediction; the dashed residuals join predictions to observations.

  3. One number

    MSE averages squared residuals. MAE averages their absolute values. Move a point and compare both measurements.

  4. The loss curve

    The curve holds the current intercept fixed. The contour map varies both slope and intercept. Equal-loss contours are sampled approximations to the same objective.

  5. The gradient

    The gradient points locally uphill. Its negative is a local steepest-descent direction under the Euclidean norm. The solid update arrow scales that direction by the rate; it does not point straight at the minimum.

  6. Step

    Step records one real update. Play is finite. Seek an earlier recorded step, then Step to create a new branch. Rate changes pause and retain past measurements.

  7. Too far

    Try other objectives and positive multipliers. Convex quadratics have mode-based rate boundaries. Saddles and curved nonquadratic objectives have no universal rate marker here.

Reference

Prediction and residual
ŷ = wx + b; residual = y − ŷ.
MSE
L = mean((wx + b − y)²); no half factor.
Gradient
g = (2 mean((ŷ−y)x), 2 mean(ŷ−y)); locally uphill in Euclidean coordinates.
Actual update
(w,b) ← (w,b) − ηg. Unit arrows show directions; the scaled arrow shows displacement.
Quadratic modes
Error in eigenmode λ is multiplied by 1−ηλ. Positive modes contract for 0<η<2/λmax; an absent unstable mode cannot grow.
Nonquadratic objectives
Rosenbrock and two-minima curvature varies with position. Local curvature is not a global stability guarantee.
Stopping
Known-optimum and gradient tolerances, small gradient alone, observed growth, numerical bound, cancellation and iteration budget are distinct.

Break it on purpose

On the narrow valley, start at (1, 1) with rate 0.1 and multiplier 1. The steep-coordinate error grows by a factor of −3 per step. Loss rises even though every update opposes its local gradient.