The Case for Differentials
Every student studying a field related to optimization should be able to work with differentials. They are simpler to apply than (partial) derivatives and strictly more expressive, especially when generalizing to matrix functions. We will motivate them in this post, following the book Matrix Differential Calculus.
In university of any engineering degree, they teach you the partial derivatives of a function. It tells you the rate of change between an input and an output of the function and uses the convention to represent them as . That works for functions with scalar input and scalar output, but does not generalize well for vector/matrix calculus. Also this convention is rather weird, as it introduces a fraction notation, while not being a real fraction (your are not allowed to move out).
Instead, differentials use a different approach. They represent how a change of the input should be transformed to arrive at the linear part of the output . Linear, because the term is only allowed to depend on once, for example for
the first differential is given as .
The function parameters may be scalar, vector or matrix, for demonstration purpose we will concentrate on scalar functions with matrix parameters, often encountered in machine learning context and denote them as .
Differentiating inverse function
For the beginning, we start with a motivational example. Letβs consider the differential of the matrix inverse function for an invertible matrix . We work with the identity and differentiate
Hence, bringing the part of equation involving to the RHS and right-multiplying , we do get
So this tells us, that increasing by , increases the output by for the linear part. We cannot hope to represent this relation with derivatives so easily, as we would have to represent the partial derivates for all input/output combinations.
Identification of Jacobian
Another way to express the relation between first-order derivatives and first-order differentials is the following identity
with the Jacobian describing the change at some coordinate . To rewrite a differential to a derivative, we need to order elements such that we can express the Jacobian in the LHS relation above.
Comparing this to the approach of many machine learning frameworks, we see the similarity to vector-Jacobian product (vJp) to transform a gradient vector in a chain of Jacobian transformations. Sometimes, respresenting the transformation as a linear map is hard, and we can represent the vJp in a more general form for differentials.
Introducing useful calculus rules
We will directly go in media res and introduce differentials of matrix calculus. Many rules are straightforward and known from derivative rules. We have that for constant , and that the differential is a linear operator
The matrix product follows from product rule
Further, one can also prove that
and hence (following from log rule)
Folowing the identification theorem, we can define the chain rules for two functions and as
resulting from and .
Going to Second Differentials
Producing more rules, we can derive Hessian from the second differential. It is straightforward defines as taking the differential, of a differential: . The third differential is again defines, as taking the differential of the second differential, and so on .
Similar to the identification of the Jacobian matrix, we can also identify the Hessian from the second differential. We formally define the Hessian through the differential of the Jacobian matrix parametrized by . Say and , then we have
We used in that .
Hence, if we arrive (after a length derivation) at some representation , then we know that the Hessian is .
Four Examples of Matrix Functions
We finish with three examples of matrix functions taken from the book. The functions take all matrices as input:
- 1.
- Let ,
then we have
We use the trace rule from previous section in
, and the product rule in . The second differentials follow from
- 2.
- Let , then
for
We again apply the product rule for k-packets in , and the known reordering in trace argument for . For
- 3.
- Let ,
then
We applied the differential of an inverse in , we have derived it in the first section.
We cannot identify the Hessian matrix from second differentials, because the vec and Kronecker operator are missing.
Conclusion
I hope you got an idea why differentials are a handy tool when working with optimization or Machine Learning. Personally I found them helpful many times when deriving some algorithm for machine learning.
We showcased only some calculus rules to highlight the advantage of differentials compared to derivatives. For actual applications take a look at Chapter 11 for inequalities and Chapter 15 for Maximum Likelihood Estimation. I recommend the whole book, there is also a condensed overview in the last chapter.