Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 29

Partial Derivatives: The Constant Rule

Recommended resources

Introduction

In our last lesson, we developed a powerful mental model: visualizing a machine learning model's loss function as a vast, high-dimensional landscape. We identified the key geographical features of this terrain—minima, maxima, and saddle points—and understood that the goal of training is to find the lowest possible valley.

Now that we have a map of the terrain, we need a compass. If we're standing at a point on this landscape (a specific set of model parameters), how do we know which way is downhill? The slope is different in every direction. The first step to building our compass is to figure out the slope in the most basic directions: those aligned with our coordinate axes.

This lesson will equip you with the fundamental tool for this: the partial derivative. You will learn how to compute the partial derivative of a multivariable function. This is the mathematical equivalent of measuring the slope of the landscape if you only walk parallel to one of the parameter axes, holding all others fixed. This skill is the first building block for the gradient, the vector that will ultimately guide our descent to the minimum.


The Geometry of Partial Derivatives: Freeze and Slice

Imagine you're standing on the side of a hill—our loss landscape. The steepness depends on which way you're facing. If you face directly along the contour line, the slope is zero. If you face straight downhill, the slope is at its maximum.

A partial derivative simplifies this by asking a more constrained question: "What is the slope if I only move in the x-direction, without changing my y-coordinate at all?"

Geometrically, this is equivalent to taking a giant knife and slicing our 3D landscape with a plane that is parallel to the x-z plane. The intersection of this plane and our surface creates a simple 2D curve. The partial derivative with respect to x, at that specific slice, is just the ordinary slope of that curve.

The following video provides an excellent visual walkthrough of this "slicing" concept.

What are derivatives in 3D? Intro to Partial Derivatives

This video from Dr. Trefor Bazett masterfully visualizes how a partial derivative isolates a single dimension of change on a 3D surface.

Please watch the first part of the video, up to the 7-minute mark. Focus on these key ideas: Slicing the surface: See how fixing one variable (e.g., y = y_naught) turns the 3D surface into a 2D curve. Defining partial derivatives: Understand how the notation \frac{\partial f}{\partial x} and \frac{\partial f}{\partial y} is defined as the ordinary derivative of these 2D sliced curves. The limit definition: Observe how the formal limit definition for a partial derivative naturally arises from the single-variable definition, by only allowing one variable to change (e.g., x_0+h) while keeping the other fixed (y_0).

This "slice and measure" approach is the core intuition. The image below perfectly summarizes the concept. On the left, we see the 3D surface being sliced by a plane where y is fixed at b. This isolates a 2D curve. The partial derivative is the slope of the tangent to that curve. The formula on the right is the formal limit definition you just saw in the video, which mathematically captures this idea.

A partial derivative, \(\frac{\partial f}{\partial x}\), measures the instantaneous rate of change of the function `f` as only the `x` variable changes. This is visualized as the slope of a curve formed by slicing the function's surface with a plane of constant `y`.

The Computation: How to "Freeze and Differentiate"

The geometric intuition of "slicing" translates into a simple computational rule: to find the partial derivative with respect to one variable, you treat all other variables as if they were constants.

Since you're comfortable with basic single-variable differentiation from your physics studies, this is the only new concept you need. Let's walk through the mechanics.

Calculating Partial Derivatives

This article provides a clear, step-by-step guide to the computational procedure with excellent examples.

Read the article from the beginning, focusing on the two main examples. First, understand the three-step process. Work through the first example, f(x,y)=x^2+y^3+4. Notice how when differentiating with respect to x, the y^3 term is treated like the constant 4 and its derivative becomes zero. Pay close attention to the second example, g(w,b)=w^2b+5w−2b+7. This is crucial. When differentiating with respect to w, b acts as a constant coefficient. The derivative of w^2b is 2wb, just like the derivative of 5w^2 would be 10w. The variables w and b are analogous to weights and biases in a model, so this form is very common in machine learning.

Let's recap the key rule from that second example, as it's the most important pattern for machine learning.

Given the function :

  • To find : Treat b as a constant. The derivative of is . So, .
  • To find : Treat w as a constant, meaning w^2 is also a constant. The derivative of (with respect to b) is 1. So, .

This technique of "freezing" all but one variable is the fundamental mechanical skill for the rest of this module.


Notation and Formalism

To tie everything together, let's briefly look at the standard notation and formal definition, which reinforces what we've learned.

Introduction to partial derivatives (article) - Khan Academy

This Khan Academy article provides a great summary of the concepts, notation, and formal definitions.

Please read the following sections: Read "How does this work for multivariable functions?" to understand why the special symbol \partial (pronounced "del" or "partial") is used instead of the d from single-variable calculus. Review the computational example for f(x,y)=x^2y^3. This reinforces the "treat y as constant" rule. Finally, read the section "A more formal definition". Notice that the limit formulas for \frac{\partial f}{\partial x} and \frac{\partial f}{\partial y} are identical to the single-variable derivative definition, except for which input variable gets the small nudge h.

The two main notations for the partial derivative of a function with respect to are:

  • Leibniz's notation:
  • Subscript notation:

Both are common in machine learning literature, and they mean exactly the same thing.


Conclusion

In this lesson, you've acquired the core skill for analyzing multivariable functions. You now understand not just the geometric meaning of a partial derivative, but also the mechanical procedure for computing it.

Key Takeaways:

  • A partial derivative measures the rate of change of a multivariable function along a direction parallel to one of the coordinate axes.
  • Geometrically, it's the slope of a 2D curve created by slicing the function's surface with a plane.
  • Computationally, you find it by treating all other variables as constants and applying the familiar rules of single-variable differentiation.
  • The partial derivative tells you the "sensitivity" of the loss function to a single model parameter .

We have successfully calculated the slopes in the cardinal directions (north-south, east-west) of our loss landscape. However, the steepest path downhill is rarely aligned perfectly with one of these axes. In our next lesson, we will learn how to combine all the partial derivatives into a single vector called the gradient. This vector, , will finally give us our true compass, pointing in the exact direction of steepest ascent at any point on the landscape.

As this image previews, the partial derivatives with respect to each variable, \(\frac{\partial f}{\partial x_1}\) and \(\frac{\partial f}{\partial x_2}\), are vectors that point along the axes. The gradient, \(\nabla_x f\), is their vector sum and points in the direction of steepest ascent on the surface.