Where We Are
Chapter 018 gave us the derivative.
For a one-variable function
the derivative tells us the local rate of change:
That is enough when there is only one dial.
But real machine-learning models have many dials.
Even the tiny house-price model
already has three parameters:
Its loss is not a curve.
It is a function of several variables:
Now the phrase “the slope” becomes incomplete.
Slope in which direction?
Change ?
Change ?
Change ?
Change all three together?
To learn what each parameter is doing, we need to isolate them.
That is exactly what a partial derivative does.
1. The Problem: One Surface, Many Possible Slopes
Start with a simple two-variable function:
Its graph is a bowl.
z
↑
/ \
/ \
/ \
/ \
-------------------→ x,y plane
Stand at the point
Ask:
How steep is the surface here?
That question is incomplete.
Walk in the x-direction and you experience one slope.
Walk in the y-direction and you experience another.
Walk diagonally and you experience something else.
With one variable there were only two local directions: left and right.
With two variables there are infinitely many directions around you.
With a billion parameters, the space is impossible to visualize—but the same issue remains.
2. A Tempting Wrong Idea: Move Everything Together
Suppose we try to imitate the one-variable derivative by nudging both inputs:
This measures something real.
It tells us how changes when we move along the diagonal direction
But it does not tell us what x is doing separately from y.
At one point, x may be pushing the function upward while y pushes it downward.
Those effects could cancel.
A Tempting Wrong Idea
“Just nudge every parameter by the same small amount and read one slope.”
That measures one chosen direction through parameter space. It cannot tell us which parameter caused what, and a zero result does not imply every individual direction is flat.
We need one measurement per dial.
3. The Discovery: Freeze Everything Except One Variable
Take
To understand how changes with x, freeze y.
Suppose
Then the two-variable function becomes a one-variable curve:
Now ordinary calculus works.
Differentiate with respect to x:
Because the original function has multiple inputs, we write this as
The symbol reminds us:
other variables exist, but they are being held fixed.
Likewise, freeze x and vary y:
These are partial derivatives.
4. What the Symbol Means
Compare:
and
| Symbol | Typical context | Meaning |
|---|---|---|
| one-variable function | local change in as x changes | |
| multi-variable function | local change in as x changes while other inputs stay fixed |
The curly is not a mysterious new kind of arithmetic.
It is a context marker.
“There are other variables here. I am deliberately moving only x.”
5. Tiny Numerical Example
Let
We want the partial derivative with respect to x.
Treat y as a constant.
Differentiate term by term:
because y behaves like a fixed number,
and
Therefore
Now with respect to y:
So
At
we get
Interpretation:
- nudging x upward changes locally at about 7 output units per x-unit,
- nudging y upward changes locally at about 8 output units per y-unit.
One point. Two different sensitivities.
6. Partial Derivatives Are Slices Through a Surface
A two-variable function creates a surface.
To take
freeze y.
That cuts the surface with a vertical plane parallel to the x-axis.
The intersection is a curve.
Then take the ordinary slope of that curve.
To take
freeze x and slice the other way.
So a partial derivative is not an abstract trick.
It is the slope of a cross-section of the surface.
7. The Axis-Direction Interpretation
Chapter 006 taught us about basis vectors.
In 2D:
Changing x while holding y fixed means moving along
Changing y while holding x fixed means moving along
So partial derivatives are local rates of change along the coordinate axes.
In n dimensions:
measures change along basis direction
Linear algebra has returned inside calculus.
8. Definition From the One-Variable Derivative
For
the partial derivative with respect to is
Read it slowly:
- start at the current input vector,
- move only in coordinate direction j,
- measure output change,
- divide by the tiny step,
- shrink the step toward zero.
This is exactly the derivative from Chapter 018, restricted to one coordinate direction.
9. Return to the House Model
Model:
For one house, squared loss:
The loss depends on three parameters:
A partial derivative answers questions like:
If I change only the room weight, how does loss change?
If I change only the area weight, how does loss change?
If I change only the bias, how does loss change?
That is precisely the information training needs.
10. A Fully Worked ML Example
Take one training example:
Use a simplified model
Let current parameters be
Prediction:
Error:
Loss:
Now ask how the loss reacts to each dial.
We can reason numerically first.
Increase slightly.
Because r=2, prediction rises twice as fast as .
Increase slightly.
Because a=3, prediction rises three times as fast as .
Increase b slightly.
Prediction rises one-for-one.
Since prediction is currently too low, all three increases reduce loss—but with different sensitivities.
This is why one scalar “slope” cannot train all parameters correctly.
11. Partial Derivatives Through Composition Preview
The loss is not directly written as a simple polynomial in every parameter unless we substitute everything.
Instead we have stages:
Changing changes prediction.
Prediction changes error.
Error changes loss.
So to compute
we will need to combine local rates of change across stages.
That is the chain rule—Chapter 021.
For now, the key point is that partial derivatives define which input variable’s influence we are tracking.
12. Partial Derivative Rules
Once other variables are treated as constants, ordinary derivative rules apply.
Let
With respect to x:
Why does disappear?
Because y is frozen, so is constant with respect to x.
With respect to y:
Now x is frozen instead.
Same expression. Different variable being allowed to move.
13. What “Hold Constant” Really Means
Suppose
At
with respect to x:
That means:
if y remains exactly 10 and x changes a tiny amount, output changes about 10 times that amount.
With respect to y:
Meaning:
if x remains exactly 3 and y changes a tiny amount, output changes about 3 times that amount.
A partial derivative describes a controlled experiment.
Move one cause. Freeze the others.
14. Finite-Difference Check
We can estimate a partial derivative numerically.
For
at
analytically:
Use a small
Then estimate:
It should be very close to 7.
This is called a finite-difference gradient check when applied across many parameters.
It becomes a powerful debugging tool for backpropagation.
15. Why Not Use an Extremely Tiny h?
It seems that smaller h should always be better.
But computers use finite-precision floating-point numbers.
If h is too tiny, subtracting
can lose meaningful digits because the two numbers are nearly identical.
This is catastrophic cancellation.
So numerical derivative checks balance two errors:
- h too large → approximation error,
- h too small → floating-point error.
A value around
is often a reasonable starting point for double precision, depending on the problem.
16. Partial Derivatives Are Not Yet the Whole Direction Story
Suppose at one point:
We know slopes along x and y axes.
But what is the slope if we move diagonally?
For example, along direction
Partial derivatives alone look like separate facts.
We need to organize them into one object that can answer any direction question.
That object will be the gradient in Chapter 020.
17. Mixed Partial Derivatives
We can differentiate a partial derivative again.
For
first:
Then differentiate that with respect to y:
Reverse order:
then
They match here.
For sufficiently smooth functions, mixed partials are equal under standard regularity conditions.
Later this structure forms the Hessian matrix.
18. Shape Check
If
then each partial derivative at a point is a scalar:
∂f/∂x1 → scalar
∂f/∂x2 → scalar
∂f/∂x3 → scalar
Three inputs create three coordinate sensitivities.
If a neural network has one million scalar parameters, the loss has one million partial derivatives.
We clearly need a compact way to organize them.
19. Code From Scratch
def f(x, y):
return x*x + 3*x*y + y*y
def partial_x(f, x, y, h=1e-6):
return (f(x + h, y) - f(x, y)) / h
def partial_y(f, x, y, h=1e-6):
return (f(x, y + h) - f(x, y)) / h
print(partial_x(f, 2.0, 1.0)) # near 7
print(partial_y(f, 2.0, 1.0)) # near 8
Notice the implementation mirrors the definition exactly.
For partial_x, y never moves.
For partial_y, x never moves.
20. Break It: Move More Than One Variable
If you compute
(f(x+h, y+h) - f(x,y)) / h
you are not estimating either partial derivative.
You are measuring change along a diagonal direction.
That can be useful, but it is a different quantity.
This is a common conceptual mistake in multivariable calculus.
21. Break It: Forget Which Variable Is Constant
Take
A learner may say:
derivative with respect to x is x.
But that confuses the variables.
With respect to x, y is the fixed multiplier:
With respect to y:
Always ask:
Which dial am I moving?
Everything else becomes constant for this measurement.
22. Break It: Confuse Parameter Derivative With Input Derivative
A model
has different derivatives depending on what we differentiate with respect to.
With respect to input x:
With respect to weight w:
With respect to bias b:
Same formula. Different question. Different answer.
This distinction is central to backpropagation.
23. 🎯 Machine-Learning Connection — Parameter Sensitivity
A partial derivative such as
means:
if only parameter changes slightly, how sensitive is the loss to that change?
If it is strongly positive, increasing raises loss quickly.
If strongly negative, increasing lowers loss quickly.
If near zero, loss is locally insensitive to that parameter.
Training needs all these sensitivities.
24. 🎯 Machine-Learning Connection — Input Sensitivity
We can also differentiate output with respect to inputs:
This can reveal how sensitive a prediction is to a feature.
In image models, derivatives with respect to pixels are related to saliency methods and adversarial perturbations.
In optimization, derivatives with respect to parameters guide learning.
The mathematics is the same; the interpretation changes with the variable.
25. History Lens — Extending Calculus Beyond One Variable
Once calculus proved useful for curves, surfaces and physical systems demanded a broader language.
Quantities in mechanics, geometry and later thermodynamics depend on many variables at once.
Partial differentiation emerged as the natural way to isolate one variable’s local influence while keeping others fixed.
Modern machine learning pushes this idea to extraordinary scale: a loss may depend on billions of parameters, yet conceptually each partial derivative still asks the same simple question:
What happens if I nudge this one dial?
26. Distinctions That Matter
| Pair | Difference |
|---|---|
| ordinary derivative vs partial derivative | one input variable vs one variable among many |
| partial derivative vs directional derivative | coordinate-axis direction vs arbitrary direction |
| parameter derivative vs input derivative | sensitivity to learned dial vs sensitivity to data |
| analytical derivative vs finite difference | symbolic/exact formula vs numerical approximation |
| first partial vs mixed second partial | first-order sensitivity vs how one sensitivity changes with another variable |
27. What We Discovered
- Multi-variable functions do not have one scalar slope.
- A partial derivative changes one variable while freezing all others.
- signals that other independent variables exist.
- Partial derivatives are slopes of axis-aligned slices through a surface.
- They are directional rates along coordinate basis vectors.
- Ordinary derivative rules apply once other variables are treated as constants.
- Finite differences can numerically verify partial derivatives.
- Too-small finite-difference steps can suffer floating-point cancellation.
- Different differentiation variables produce different meanings and formulas.
- Partial derivatives give one sensitivity per parameter.
- We still need one object that organizes all these sensitivities and predicts change in arbitrary directions.
28. Mathematics We Built
For a multivariable function
the j-th partial derivative is
For
we found
At :
29. One-Minute Explanation
A partial derivative is what you use when a function has many inputs but you want to measure the local effect of just one. Freeze every other input, nudge the chosen one, and compute the ordinary derivative of that one-variable slice. For a loss function with millions of parameters, there is one partial derivative per parameter. Each tells how sensitive the loss is to that dial. The next problem is that a million separate numbers are awkward; we need to organize them into one geometric object. That object is the gradient.
30. Mastery Check
- Why is “the slope of a surface” incomplete?
- What does “hold other variables constant” actually mean?
- Why does differ conceptually from ?
- Compute both partial derivatives of .
- What is the axis-slice interpretation of a partial derivative?
- How do basis vectors appear in the formal definition?
- Why is moving x and y together not a partial derivative?
- Why can finite-difference checks fail when h is too tiny?
- For , compute derivatives with respect to x, w and b and explain why they differ.
- What information does provide during training?
- Why are partial derivatives still not enough to answer “which arbitrary direction rises fastest?”
🔭 Bridge to Chapter 020
At one point we may have
A billion-parameter model has a billion such sensitivities.
Listing them separately is not enough.
We want one object that:
- stores all partial derivatives,
- predicts change in any direction,
- points toward steepest increase.
What vector contains the complete first-order local change information of a scalar function?
That question forces the gradient.