Gradient Descent

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

published · difficulty 2/5 · 12 min read

Reading map and next steps

Intuition

Build the mental picture first so the rest of the page has something to attach to.

PredictName the object in plain language, then predict what should change.Leave with one reusable mental picture before notation appears.

A model can receive one scalar complaint, the loss is high, while having thousands or millions of parameters. Which way should those parameters move?

Gradient descent is the basic answer behind most neural-network training: measure which way the loss rises, then step the other way.

Imagine standing on a landscape in fog. You cannot see the whole terrain, but you can feel the local slope under your feet. The gradient points in the steepest uphill direction. If your goal is to lower the loss, you walk against that direction.

The method is deliberately local. It does not know whether a better valley exists far away, and it can move too slowly or overshoot if the step size is wrong. But it gives a reusable training loop: compute a loss, differentiate it, update parameters, repeat.

This page assumes the gradient is already available. Backpropagation explains how computation graphs and reverse-mode autodiff produce that gradient for neural networks; gradient descent explains how an optimizer consumes it.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

InspectTrack the same object through the notation and check each symbol.Leave with the invariant the equations preserve.

Let L:Rp→RL:\mathbb{R}^p\to\mathbb{R} be a loss function and let θt∈Rp\theta_t\in\mathbb{R}^p be the current parameter vector. Under the standard Euclidean inner product, the gradient

∇θL(θt)\nabla_\theta L(\theta_t)

points in the direction of steepest local increase. Gradient descent uses the update

θt+1=θt−η∇θL(θt),\theta_{t+1} = \theta_t - \eta \nabla_\theta L(\theta_t),

where η>0\eta > 0 is the learning rate.

If LL is differentiable near θ\theta and ∇L(θ)≠0\nabla L(\theta)\neq 0, the first-order Taylor approximation says

L(θ−η∇L(θ))≈L(θ)−η∥∇L(θ)∥2.L(\theta-\eta\nabla L(\theta)) \approx L(\theta)-\eta\|\nabla L(\theta)\|^2.

That is the local reason stepping against the gradient should reduce the loss. The learning rate controls how much you trust this local approximation. If η\eta is too small, training makes slow progress. If η\eta is too large, the update can jump across a valley or even increase the loss. On a quadratic loss, this tradeoff is governed by curvature: steep directions demand smaller stable steps than flat directions.

At a stationary point, ∇L(θ)=0\nabla L(\theta)=0, so this first-order decrease argument disappears. In a nonconvex loss, such a point might be a minimum, a saddle, or a maximum.

For the quadratic used below,

L(θ)=12θTAθ,L(\theta)=\frac12\theta^{\mathsf T}A\theta,

with AA symmetric positive definite, the gradient is ∇L(θ)=Aθ\nabla L(\theta)=A\theta. In an eigen-direction of AA with curvature λi\lambda_i, the update becomes

zi,t+1=(1−ηλi)zi,t.z_{i,t+1}=(1-\eta\lambda_i)z_{i,t}.

For convergence to zero from every starting point, fixed-step descent needs ∣1−ηλi∣<1|1-\eta\lambda_i|<1 for every direction, so

0<η<2λmax⁡.0<\eta<\frac{2}{\lambda_{\max}}.

This is the convergence bound used by the code and the demo. At equality, the highest-curvature factor is −1-1: a nonzero coordinate in that direction alternates without decaying in ideal arithmetic. Above the bound its magnitude grows. Below the bound, a positive factor shrinks without changing sign, a zero factor reaches zero in one update, and a negative factor with magnitude below one alternates while shrinking.

In the demo's diagonal quadratic with curvature 2020, step size 0.10.1 and start [4.4,2.6][4.4,2.6], the recurrence gives xt=4.4(0.9)tx_t=4.4(0.9)^t and yt=2.6(−1)ty_t=2.6(-1)^t. Thus Lt=67.6+9.68(0.9)2tL_t=67.6+9.68(0.9)^{2t} decreases toward 67.667.6, not the minimum value zero. A decreasing loss alone does not establish convergence to the minimum. These are ideal-arithmetic consequences of this authored recurrence, not conclusions proved by 18 plotted updates or guarantees about nonconvex or stochastic training.

In deep learning, the exact gradient over the whole dataset is often too expensive. For a training set of nn examples, define the empirical risk

Lemp(θ)=1n∑i=1nℓ(fθ(xi),yi).L_{\mathrm{emp}}(\theta)=\frac1n\sum_{i=1}^n \ell(f_\theta(x_i),y_i).

For a mini-batch BtB_t, we instead compute

gt=∇θ(1∣Bt∣∑i∈Btℓ(fθ(xi),yi)).g_t = \nabla_\theta\left(\frac{1}{|B_t|}\sum_{i\in B_t}\ell(f_\theta(x_i),y_i)\right).

With uniform sampling, gtg_t estimates ∇Lemp(θt)\nabla L_{\mathrm{emp}}(\theta_t). That turns gradient descent into stochastic gradient descent. The update is the same shape, but the direction is noisy:

θt+1=θt−ηgt.\theta_{t+1} = \theta_t - \eta g_t.
Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Code

Keep the implementation aligned with the notation so the algorithm is legible.

TraceMatch variables to symbols before reading the implementation.Leave with a runnable witness for the math.
import numpy as np

# Minimize L(theta) = 0.5 * theta^T A theta.
# The second coordinate has much higher curvature.
# Shapes: A is (2, 2), theta is (2,), grad(theta) is (2,).
A = np.diag([1.0, 20.0])
theta = np.array([5.0, 5.0])
lr = 0.08

def loss(theta):
    return 0.5 * theta @ A @ theta

def grad(theta):
    return A @ theta

for step in range(20):
    theta = theta - lr * grad(theta)
    if step in [0, 1, 2, 5, 19]:
        print(step + 1, "theta=", np.round(theta, 3), "loss=", round(loss(theta), 3))

For this quadratic, λmax⁡=20\lambda_{\max}=20, so convergence from every starting point needs 0<η<2/λmax⁡=0.10<\eta<2/\lambda_{\max}=0.1. Try lr = 0.005, 0.08, and 0.12 to see slow movement, stable zig-zagging, and instability. Then try lr = 0.1: this code starts at [5,5], not the demo's [4.4,2.6], so its non-decaying second coordinate has amplitude 55, not 2.62.6. Inspect coordinates as well as loss; the code's 20 updates and the demo's 18 are finite illustrations of the recurrence.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

ManipulateChange one control and predict the visible response before reveal.Leave with the observed invariant or a repaired model.

Live Concept Demo

Explore Gradient Descent

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 2/5undergraduatecode-aligned
Demo inquiry checkpoint

Manipulate one control and predict the visible change.

01Choose lensTrace a quantity
02ObserveDemo state pending
03GroundName the equation, invariant, or control that explains it.
04CarryNext: SGD & Momentum: The Workhorses of Optimization

Choose what to inspect in Gradient Descent. This shared fallback is an observation guide, not evidence of learning.

Loading interactive demo...

Use the learning-rate slider on the stretched quadratic bowl. The contours show the loss and the brown arrow shows the first local step. Predict Crawl, Contract, Non-decaying oscillation or Diverge before revealing the full path. Crawl uses the existing small-rate heuristic (eta below 22% of the convergence bound); it is still contraction, not a separate asymptotic outcome. At a crawl setting, Contract therefore also matches, and the feedback names Crawl as the finer class.

The original presets keep curvature 2020: step size 0.080.08 contracts with alternating signs, while 0.120.12 amplifies the steep coordinate. Use the neutral eta=0.10, curvature=20 preset to inspect the exact convergence boundary. After reveal, pause or scrub the existing 18 updates and compare both current coordinates with loss. A finite trace that stays inside the plot need not converge; above-bound growth may not leave the plot within those 18 updates. Clipping affects only the drawing, not the simulated coordinates or loss.

Compare the accepted learning rate with the symbolic bound 2/λmax⁡2/\lambda_{\max}, not a rounded decimal display. Changing the rate, curvature, preset or prediction hides the old verdict and stops playback. Within the same quadratic, try 0.045, 0.05 and 0.095 at curvature 2020 to distinguish sign-preserving contraction, a steep coordinate that reaches zero, and alternating contraction. These observations illustrate the ideal recurrence; they do not establish learning or real-network behavior.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

4/4 sections ready

Concept: Gradient Descent

What is the smallest example that makes Gradient Descent click without losing the math?

BeforeDerivativesNow4/4 sections readyTryManipulate one control and predict the visible change.NextSGD & Momentum: The Workhorses of Optimization
Object contextOptimization
ConceptLearner lens

Gradient Descent

What is the smallest example that makes Gradient Descent click without losing the math?

Mode questionCan I say the mechanism back in one sentence before I reveal anything?

Start with the prediction checkpoint, then compare the reveal to the mental model.

Take this move

Study modes

Keep the object fixed; change the lens.

Route back through the notebook

Carry the same object through intuition, math, code, and demo.

4/4 sections ready
Carry inDerivatives

Bring the mental model from Derivatives; this page will reuse it instead of restarting from zero.

Work hereGradient Descent

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

Carry outSGD & Momentum: The Workhorses of Optimization

The next edge should feel earned: use the demo prediction here before following SGD & Momentum: The Workhorses of Optimization.

After The First Pass

Turn the concept into an inspected object.

The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.
ConceptGradient DescentOptimization

Mechanism Storyboard

See the idea move before the page explains it

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

Demo notes open01 / Intuition
Editorial mathematical illustration of gradient descent steps moving through contour lines toward a minimum.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Gradient Descent should make visible.

Visual Inquiry

Make the image answer a mathematical question

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

4/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Gradient Descent easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

Object - ConceptGradient DescentQuestion

What is the smallest example that makes Gradient Descent click without losing the math?

concept:optimization/gradient-descent
Boundary

sources: boyd-2004-convex-optimization, goodfellow-2016-deep-learning

Check

Open the closest source note before trusting the local explanation.

Evidence

2 selected-object sources shown first; 2 references total.

Next move

Audit the claim boundary, then ask from the same selected object.

selected object source · book · 2004Convex OptimizationBoyd and Vandenberghe
Located CF editorial boundary

Grounds descent methods, gradients, step sizes, and convex-optimization intuition.

Used here as

Boyd and Vandenberghe ground descent methods, gradients, and step-size reasoning in convex optimization; Goodfellow et al. frame neural-network training as optimizing parameters of a cost...

Caveat

This checks the local first-order update mechanism, not a guarantee of global convergence for nonconvex neural-network losses.

Open source
selected object source · book · 2016Deep LearningGoodfellow, Bengio, and Courville
Located CF editorial boundary

Grounds gradient-based learning as the optimization language used by neural networks.

Used here as

Boyd and Vandenberghe ground descent methods, gradients, and step-size reasoning in convex optimization; Goodfellow et al. frame neural-network training as optimizing parameters of a cost...

Caveat

This checks the local first-order update mechanism, not a guarantee of global convergence for nonconvex neural-network losses.

Open source

Claim Review

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

Object - ConceptGradient DescentQuestion

What is the smallest example that makes Gradient Descent click without losing the math?

concept:optimization/gradient-descent
Boundary

sources: boyd-2004-convex-optimization, goodfellow-2016-deep-learning

Check

Treat every claim as provisional until source support and a local witness agree.

Evidence

1 structured claim check on this concept.

Next move

Run the prediction or practice transfer before asking for a grounded review.

1 CF editorial source-scope review recorded

Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 2 references and 3 local witnesses are available for inspection.

Gradient descent uses the gradient as the direction of steepest local increase and updates parameters in the negative-gradient direction, with the learning rate controlling how far to trust the local approximation.
Used here as

Boyd and Vandenberghe ground descent methods, gradients, and step-size reasoning in convex optimization; Goodfellow et al. frame neural-network training as optimizing parameters of a cost function with gradi...

Local witness
Equation 1
∇θL(θt)\nabla_\theta L(\theta_t)
Equation 2
θt+1=θt−η∇θL(θt),\theta_{t+1} = \theta_t - \eta \nabla_\theta L(\theta_t),
Caveat

This checks the local first-order update mechanism, not a guarantee of global convergence for nonconvex neural-network losses.

Review stateCF editorial source-scope reviewClaim metadata: source checkedPublisher-side editorial review only; not independent replication. Check caveats and exact source scope.

Checked Goodfellow et al. chapters 4.3 and 8.3 plus Boyd/Vandenberghe chapter 9: Goodfellow gives directional derivative u^T grad f, says -grad is downhill, gives x' = x - eps grad f with eps as positive learning rate, and uses Taylor expansion to show curvature can make too-large steps move uphill. Boyd frames descent as direction plus step size and states Euclidean steepest descent coincides with gradient descent.

Reviewer: codex+oracle; reviewed 2026-05-06

Practice · Gradient Descent

Try the idea in your own words

Gradient descent turns local slope information into an iterative update rule for reducing a loss.

Concept · Current object

Gradient Descent

Source boundary: sources: boyd-2004-convex-optimization, goodfellow-2016-deep-learning

Object context and links

Optimization

concept:optimization/gradient-descent
Choose a task

Explain the mechanism

For Gradient Descent: What is the smallest example that makes Gradient Descent click without losing the math? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Local to this page session. Not saved after leaving or reloading.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer does not erase help history. Outside help cannot be verified here.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    This draft and any AI response do not establish mastery. Try a different case later without help; this page has not measured that learning.

    Grounded object roomClose
    Selected object routeAsk from this object; carry one invariant back.sources: boyd-2004-convex-optimization, goodfellow-2016-deep-learning
    1. ObjectConceptGradient Descent
    2. PredictBefore revealGradient Descent prediction
    3. WitnessCompare codeGradient Descent code witness 1
    4. RoomAsk groundedChecking local snapshot
    ConceptGradient DescentOptimization
    Code witness comparisonGradient Descent code witness 1A = np.diag([1.0, 20.0])Prediction before revealGradient Descent predictionManipulate one control and predict the visible change.
    Grounded room questionWhat is the smallest example that makes Gradient Descent click without losing the math?Checking local snapshot

    Research Room

    Attach the question to an exact object

    Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
    Next local actionNo local draft saved yet

    Open the draft below to save one note and next action in this browser.

    conceptOptimization

    Gradient Descent

    Anchored question

    What is the smallest example that makes Gradient Descent click without losing the math?

    Source boundaryInspect source ids: boyd-2004-convex-optimization, goodfellow-2016-deep-learningStable content-object key attached
    Role lenses for this object

    These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.

    Learner evidence requestAsk what would make "Gradient Descent" feel predictable rather than familiar.
    Assumption

    Source ids boyd-2004-convex-optimization, goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic.

    Source-checking summary

    Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.

    Proposed experiment

    Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.

    Next action

    The learner can state the mechanism in their own words

    Evidence4 checks
    PredictionChecking carried observation
    ActionReady for one action
    AILearner handoff ready
    Open source object
    01PredictionChecking browser-local route memory
    02EvidenceChecking for a carried observation
    03BoundaryInspect source ids: boyd-2004-convex-optimization, goodfellow-2016-deep-learning
    04Next moveSave one next action
    Local action draftNo local draft saved yetExpand only when ready to capture one local next action
    Local action draft

    This draft stays locally in this browser for concept:optimization/gradient-descent.

    No local draft saved.
    Evidence to inspect
    • Source ids to inspect: boyd-2004-convex-optimization, goodfellow-2016-deep-learning
    • Definition, prerequisite, and contrast concept links
    • The equation or code witness that makes the concept operational
    • One demo state that shows the invariant instead of a slogan
    What would resolve this
    • The learner can state the mechanism in their own words
    • The learner can name the prerequisite that would repair confusion
    • The learner can predict how the mechanism changes under one perturbation
    Object-attached AI handoff

    I am working in Continuous Function's research reading room. Object: concept - Gradient Descent Object key: concept:optimization/gradient-descent Context: Optimization Anchor id: concept/concept-notebook/optimization/gradient-descent Open question: What is the smallest example that makes Gradient Descent click without losing the math? Evidence to inspect: - Source ids to inspect: boyd-2004-convex-optimization, goodfellow-2016-deep-learning - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids boyd-2004-convex-optimization, goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Gradient Descent" feel predictable rather than familiar." | assumption: Source ids boyd-2004-convex-optimization, goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: boyd-2004-convex-optimization, goodfellow-2016-deep-learning" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Gradient Descent" feel predictable rather than familiar. - Assumption to keep visible: Source ids boyd-2004-convex-optimization, goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words

    concept/concept-notebook/optimization/gradient-descent concept:optimization/gradient-descent