Skip to main content
L2.7

Derivatives Just in Time

About 24 min

Goal

By the end of this lesson, you can interpret a derivative as local sensitivity, predict its sign from a simple curve, and compare a numerical finite-difference estimate with an exact derivative.

A derivative answers a small-change question​

You do not need to begin with a page of calculus symbols.

Start with this question:

If I nudge the input a tiny amount to the right, does the output rise or fall, and how quickly?

That local rate of change is the derivative.

Read derivative sign from a bowl-shaped function​

Consider:

f(w) = (w - 3)²

The function is smallest at w = 3.

At w = 1, moving right toward 3 makes the function smaller. The derivative is negative.

At w = 5, moving right moves farther away from 3 and makes the function larger. The derivative is positive.

At w = 3, a tiny movement in either direction increases the function symmetrically, so the derivative is zero.

The exact derivative is:

f'(w) = 2(w - 3)

Now the formula matches the geometry you already reasoned about.

Estimate the derivative numerically​

A centered finite difference uses a small step h:

(f(w+h) - f(w-h)) / (2h)

This compares nearby values on both sides of the point.

If h is reasonably small, the estimate should be close to the exact derivative for this smooth function.

If h is huge, you are averaging behavior across a wide region rather than measuring a truly local slope.

Extremely tiny h can also create floating-point precision problems in real numerical code. Gradient checking therefore uses a sensible small scale rather than “as small as possible.”

Compare exact and numerical slopes in the Lab​

  1. Click Run unchanged. Both derivatives print -4.0 (numeric derivative: -4.0 and exact derivative: -4.0), and absolute error is a tiny number around 1e-11, so the two methods agree.
  2. Before editing, predict the sign of the slope at w = 5, to the right of the minimum at w = 3.
  3. Change only w = 1.0 to w = 5.0 and click Run. Both derivatives become 4.0: the slope is now positive, so gradient descent would move w back down toward 3. The checks still pass because the numerical and exact values still agree; only the example point changed.
  4. Press Reset, change only w = 1.0 to w = 3.0, predict, and run. Both derivatives are 0.0 at the bottom of the curve.
  5. Press Reset, then change only step = 1e-5 to step = 1.0. Predict whether a much larger step makes the estimate worse, then run. It still prints -4.0, now with absolute error: 0.0: for a quadratic loss the central difference is exact for any step. On curvier functions a large step does add error, which is why the default step stays small.
  6. Press Reset afterward.

Loading lab…

How derivative sign connects to gradient descent​

Gradient descent subtracts the derivative or gradient.

  • negative derivative → subtracting it moves the parameter upward;
  • positive derivative → subtracting it moves the parameter downward;
  • near-zero derivative → the local update becomes small.

For this bowl-shaped function, those movements point toward the minimum at 3.

Debugging derivative code​

When a derivative estimate looks wrong, check:

  1. the function you are differentiating;
  2. the evaluation point;
  3. the step size;
  4. subtraction order;
  5. whether you are comparing the same scalar objective.

Reversing f(w+h) - f(w-h) flips the estimated sign, which can reverse a training update.

Read a derivative as a local sensitivity​

Suppose a small change in w from 2.00 to 2.01 changes loss from 4.00 to about 4.06.

A rough local sensitivity is:

change in loss / change in w
≈ 0.06 / 0.01
≈ 6

That does not mean increasing w by 1 will always increase loss by exactly 6. A derivative describes the slope near the current point.

This local nature is why gradient descent takes repeated steps and recomputes gradients after parameters move.

Explain more simply

Imagine walking on a hill in thick fog. You cannot see the whole hill. You can only feel the ground right under your feet.

The derivative is that feeling.

  • Its sign tells you uphill or downhill. Positive means a step to the right goes up.
  • Its size tells you how steep it is. A derivative of 6 means a tiny step to the right raises you about 6 times the length of that step.

A few steps later, the ground may be flatter or steeper. That is why you check again after every step. Gradient descent does the same: step, feel the slope again, step again.

Sign and magnitude answer different questions​

  • positive derivative: increasing the variable locally raises the output;
  • negative derivative: increasing the variable locally lowers the output;
  • large magnitude: the output is locally sensitive to that variable;
  • near zero: small local movement has little first-order effect.

Do not interpret a zero derivative as “this parameter can never matter.” Nonlinear networks can have regions where a local slope is zero even though the parameter affects behavior elsewhere.

Quick Check

1. What does derivative sign describe locally?
2. What should the derivative be near the minimum of `(w-3)^2` at `w=3`?
3. Why use a small finite-difference step?

0 of 3 questions answered.

Key Takeaways

  • A derivative measures local sensitivity.
  • Its sign tells whether the function locally rises or falls as the input increases.
  • Finite differences provide an independent numerical gradient check.
  • Derivative signs explain gradient-descent update direction.

Next Lesson

Next, you will use these local sensitivities to ask how a change in an earlier parameter reaches the final loss—the central question behind backpropagation.

References

Lesson actions

Completion is stored locally on this device.

View progress