Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Calculating Partial Derivatives

Hello! Welcome to the first lesson in our new module on Multivariate Calculus for Machine Learning.

Introduction

In our last module, we explored how linear algebra, through concepts like eigendecomposition and SVD, allows us to understand and manipulate data matrices. We concluded by seeing how SVD can find the best low-rank approximation of a matrix, a key tool in dimensionality reduction and compression.

Now, we pivot from the linear world of matrices to the continuous world of multivariable functions. This module is the mathematical engine behind training almost all modern machine learning models. The central idea is optimization: finding the set of model parameters that minimizes a cost or error function. To do that, we first need to understand how the function's value changes as we adjust its parameters.

Today, we address the first learning outcome of this module: to compute partial derivatives of multivariable functions. A partial derivative is the natural extension of the single-variable derivative you are familiar with. It measures the instantaneous rate of change of a function with respect to one of its variables, while holding all other variables constant. This is the fundamental building block for the optimization algorithms we will study later.

From Single to Multiple Variables

Recall that for a function of one variable, , the derivative or gives us the slope of the tangent line to the function's graph at point . It tells us how sensitive is to a small change in .

But what about a function of multiple variables, like ? This function's graph is no longer a curve, but a surface in 3D space. At any point on this surface, there isn't just one "slope"—we could move in the x-direction, the y-direction, or any combination.

To get a handle on this, let's first build our intuition for what these functions and their graphs look like.

Lec 8: Level curves; partial derivatives; tangent plane | MIT 18.02 Multivariable Calculus, Fall 07

This video from MIT OpenCourseWare will introduce the concept of functions of several variables and how we can start to think about them.

Please watch the segment from 00:30 to 05:49. The goal is to understand the transition from f(x) to f(x, y) and see some examples.

As the video discusses, visualizing these functions is key. We have two primary methods:

  1. Graphs: We can plot as a surface in 3D space. The height of the surface above the xy-plane at point represents the function's value.
  2. Contour Plots (Level Curves): We can draw curves in the 2D xy-plane that connect all points where the function has a constant value, like a topographical map showing lines of constant elevation.

The core idea of partial differentiation is to simplify the problem by considering only one direction of change at a time—specifically, change along the coordinate axes.

The Partial Derivative: Definition and Geometric Meaning

To find the rate of change of in the x-direction, we can simply hold constant at some value . The function effectively becomes a single-variable function of , . The derivative of this "partial function" is what we call the partial derivative of with respect to .

Notation:
The partial derivative of with respect to is denoted by:

The curly 'd' symbol (, called "del" or "partial") is crucial. It signifies that is a function of multiple variables and we are only differentiating with respect to one of them, holding the others constant.

Formal Definition:
Just like the ordinary derivative, the partial derivative is defined with a limit. The partial derivative of with respect to at a point is:

Similarly, the partial derivative with respect to is:

Notice that in the definition for , the coordinate remains unchanged, and vice-versa.

Geometric Interpretation:
Geometrically, holding constant at is equivalent to slicing the 3D surface with a vertical plane at . The intersection of the plane and the surface is a curve. The partial derivative at is simply the slope of the tangent line to that specific curve at that point.

Visual and Mathematical Definition of Partial Derivatives
This image illustrates the geometric meaning of the partial derivative. Slicing the surface with the plane y=b creates a curve (shown in red). The partial derivative ∂f/∂x at a point on this slice is the slope of the tangent line to that curve.

To see this concept in motion, the following video provides an excellent visualization.

Lec 8: Level curves; partial derivatives; tangent plane | MIT 18.02 Multivariable Calculus, Fall 07

This clip from the same MIT lecture series explains the formal definition and geometric interpretation of partial derivatives with helpful animations.

Watch from 38:25 to 44:19. Focus on how fixing one variable corresponds to taking a slice of the function's graph, and how the partial derivative represents the slope along that slice.

The Mechanics of Computation

While the limit definition is fundamental for theory, in practice we almost never use it for computation. The rule is much simpler.

To compute a partial derivative, treat all other variables as constants and apply the standard rules of single-variable differentiation.

For example, to compute of :

  1. We are differentiating with respect to .
  2. Therefore, we treat as a constant. The term is just a constant multiplier.
  3. The derivative of with respect to is .
  4. So, .

Now, let's compute of the same function, :

  1. We are differentiating with respect to .
  2. We treat as a constant. The term is a constant multiplier.
  3. The derivative of with respect to is .
  4. So, .

The following resource provides a clear walkthrough of this process.

Chapter 13: Partial Derivatives

This document from MIT OpenCourseWare provides a concise and rigorous explanation of partial derivatives, including several illustrative examples.

Please read Section 13.2, 'Partial Derivatives' (pages 549-551). Pay close attention to the examples, particularly how y is treated as a constant when finding fx, and vice-versa. Notice how standard rules like the chain rule are applied in Example 3.

The rules you know from single-variable calculus, like the product rule, quotient rule, and chain rule, all apply directly when computing partial derivatives.

Oxford Calculus: Partial Differentiation Explained with Examples

For a more complex example that shows how the product and chain rules are applied in partial differentiation, please watch this segment.

Watch from 12:35 to 17:32. Observe carefully how the product rule is used for the x-derivative, and how the chain rule is applied to both the sine and exponential terms. This demonstrates that no new differentiation 'rules' are needed, only the principle of holding other variables constant.

Test your understanding!

Let . Compute the partial derivatives and .

Hint: You will need to use the chain rule. Remember that .

Show answer

To compute , we treat as a constant.

For the first term, we use the chain rule. The derivative of the exponent with respect to is .

To compute , we treat as a constant. The term is now a constant, so its derivative is 0.

For the first term, we use the chain rule again. The derivative of the exponent with respect to is .

Conclusion

In this lesson, we have taken the first crucial step into multivariate calculus for machine learning. We have extended the concept of a derivative to functions of multiple variables by defining the partial derivative.

Key Takeaways:

  • A multivariable function can be visualized as a surface or through its level curves.
  • The partial derivative measures the instantaneous rate of change of the function as only the variable changes.
  • Geometrically, it represents the slope of the tangent line to the curve formed by slicing the function's graph with a plane that holds all other variables constant.
  • Computationally, we find by treating all other variables as constants and applying the familiar rules of single-variable differentiation.

Preview of the Next Lesson:
We have learned to measure the rate of change along each coordinate axis individually. But what if we want to know the direction of the steepest ascent on our function's surface? In the next lesson, we will combine all the partial derivatives of a function into a single vector called the gradient. This vector, , points in the direction of the greatest rate of increase of the function and is the cornerstone of gradient-based optimization methods that train machine learning models.

Can't find a good explanation? Sign up and we'll make it for you

Sign up