Matrix Calculus — The Total Derivative
At the end of the previous chapter, we briefly discussed single-variable, vector-valued functions and how the derivative generalizes to them. In this chapter, we will examine how the derivative generalizes to functions with multiple variables in the domain. This is unfortunately not a trivial generalization, and the definition we provide will seem cryptic at first. However, we will soon see that the definition provides several of the conveniences we would expect from the derivative — and maybe even some additional advantages.
Definition
Recall from Chapter 1 the alternate definition of the derivative for a single variable, scalar-valued function. Let be an open subset and differentiable. The derivative of at is the unique number such that
This is equivalent to
because a function limits to zero if and only if the absolute value of the function limits to zero. This formula generalizes rather naturally to multi-variable domains by replacing the absolute values with vector norms.
We can now provide a definition for the total derivative of a function.
Let be an open subset and a sufficiently smooth, multivariable, vector-valued function. Let . If there exists a linear map (dependent on ) such that
then we say is totally differentiable at , and is the total derivative. The total derivative is usually denoted using Euler's notation:
If is totally differentiable at every point in , then we say the function is totally differentiable. Its total derivative is the function that maps points in the domain to linear maps from to . Those linear maps are usually represented by matrices of real numbers, since every linear map can also be represented as a matrix.
As the Best Linear Approximator
By defining the total derivative as a linear map, we maintain the property that it is a linear approximator of at the point . To make this precise, we can quantify the error the following way:
where is the error in the approximation. Similar to the single variable case, when we get that , and hence it limits to zero as well.
The total derivative, then, can be defined as the unique linear transformation for which the error term is minimal. Unfortunately, like in the single variable case, we will not prove uniqueness here. The consequence of this fact is that the total derivative is the best linear approximation to .
As a Differential Form
Now that we have developed some intuition for what the total derivative means, we want to discover how we can use it as a tool for computation. We mentioned in the previous chapter that every linear map can be represented as a matrix, which is much more useful for concrete computations. However, to formulate the matrix of a linear map requires us to choose bases for the domain and codomain of the transformation.
Since most applications of matrix calculus pertain to real numbers, the domain and codomain of the functions we are concerned with are in the family of vector spaces for . These vector spaces have a standard basis comprised of the set of vectors whose components are all zero, except one that equals 1. Formally, the standard basis of is the set of vectors for . Each vector has a in the 'th element and s in all other elements.
With the bases defined, we can determine the matrix of the total derivative. Consider the function from earlier, . Since , the sets of vectors , , and , , are the standard bases for the domain and codomain respectively. Let be some arbitrary point in .
We want to find a matrix that represents . Since is a linear transformation that maps points from to , consider an arbitrary point , . Then, for some . Then, using the linear approximation definition of the derivative, must satisfy
where the error is minimal. But we can represent as using the standard basis for . So we can write
using the linearity property of the total derivative. Now let us consider only the 'th coordinate of the expression above:
If we further only let the 'th variable vary and hold all other variables constant, we get
We recognize that the value satisfies the definition for the partial derivative of at the point with respect to the 'th variable in the domain. Thus, if we write out the total derivative explicitly, we would get the following matrix:
This matrix is also commonly called the Jacobian, and understanding it will be critical for nearly all aspects of differentiating matrix-like expressions.
The Gradient
For those who are familiar with vector calculus, you may recognize the total derivative in a slightly different form. Consider a differentiable, scalar-valued function of several variables, . The gradient of at the point is usually denoted and can be defined as
Intuitively, the value represents the direction and rate of fastest increase in at . The gradient is also intrinsically related to the total derivative in that the dot product of with another tangent vector is the directional derivative of at along the vector , which is exactly the total derivative applied to . That is,
One might also notice that the rows of the total derivative are comprised of the transposes of the gradients of each of the coordinate functions. That is,
This explains the algebraic connection between the total derivative and the gradient.
The Chain Rule for Total Derivatives
One of the convenient properties of the total derivative is how it interfaces with the chain rule. Recall the chain rule from elementary single-variable calculus:
Let be a differentiable function at a point and be a differentiable function at , then the composite function is differentiable at the point . Its derivative is
If we let and , we can express the chain rule through Leibniz's notation too:
Although we will not include the proof of the single variable chain rule, the essence of the proof involves studying the error in the linear approximation determined by the derivative. The full proof can be found in the Wikipedia article on the chain rule. This proof can be naturally generalized to the multivariable case, but it is a rather technical argument that requires expanding many terms. In any case, we will provide the multivariable chain rule statement in terms of total derivatives.
Let and be totally differentiable functions. The total derivative of the composite function at the point satisfies
This statement is rather elegant because, when we treat the total derivatives of and as matrices, the expression on the right hand side is simply matrix multiplication. This consequence is extremely important because it effectively means we can reason about arbitrary dependencies among the arguments of composite multivariable functions.
We are now properly equipped to dive into the world of matrix calculus. In the following chapters, we will discuss how to take the derivative of expressions involving vectors and matrices with respect to vectors and matrices. Additionally, we will explore where these structures arise in machine learning and how to reason about it all.
Sources
- Derivative — Wikipedia
- Total derivative — Wikipedia
- Chain rule — Wikipedia
- Gradient — Wikipedia
- Dummit, Richard S. and Foote, Richard M. Abstract Algebra.
- Strichartz, Robert. The Way of Analysis.