Contents

Matrices and Derivatives: Kronecker in the Realm of Matrices

Written on January 21, 2019

NOTE: This post is automatically translated from Farsi using GPT 5.5

It was said that when we regard derivatives with respect to matrices as derivatives with respect to their vectorized forms (the same vec operator), we no longer need to wrestle with tensors and covectors and contravectors. At the same time, we need to bring the Kronecker product from that world into this one. In tensor computations, the Kronecker product creates a tensor whose dimensions equal the sum of the dimensions of its input tensors. For example, the Kronecker product of two vectors is a matrix. But in the world of matrices, the Kronecker product has a simpler form.

If we have two matrices A and B, their Kronecker product is defined as follows:

AB=[A11BA12BA1mBA21BA22BA2mBAn1BAn2BAnmB]

For example:

[3456][1001]=[3040030450600506]

This product has beautiful properties, and in the context of differentiation with respect to matrices, the following property is one of the most important:

vec(AXB)=(BTA)vec(X)

For an example of using this relation, suppose we want to differentiate AXB with respect to X:

AXBX=vec(AXB)vec(X)=(BTA)vec(X)vec(X)=(BTA)

Chain derivatives and the derivative of a product of functions

In the world of scalars, there were all sorts of relationships for derivatives that got the job done. These relationships also hold in similar forms in the world of matrices. One of those relationships was the scalar product and sum rule, which I mentioned in the previous post.

It is not a bad idea to see why that relation holds:

(αA+βB)Xij=vec(αA+βB)ivec(X)j=αvec(A)ivec(X)j+βvec(B)ivec(X)j=αvec(A)ivec(X)j+βvec(B)ivec(X)j=αvec(A)vec(X)ij+βvec(B)vec(X)ij

In the same way, one can see that the chain derivative of functions can be computed as follows:

f(g(X))Xij=kvec(f(g(X)))ivec(g(X))kvec(g(X))kvec(X)j=(f(g(X))g(X)g(X)X)ij

And more generally:

h(f(X),g(X))Xij=k(vec(h(f(X),g(X)))ivec(f(X))kvec(f(X))kvec(X)j+vec(h(f(X),g(X)))ivec(g(X))kvec(g(X))kvec(X)j)=(h(f(X),g(X))f(X)f(X)X+h(f(X),g(X))g(X)g(X)X)ij

Apparently, those who defined the rule of matrix multiplication as multiplying the row of the first by the column of the second laid the right foundation! Everything fits together.

But what are the relations for the product of two functions?

f(X)g(X)X=?

If you are tired of examining the derivative element by element, you have every right to be; I am tired too. So we ask Professor Kronecker for help in finding this one. First, we consider the function h(X,Y)=XY. The derivative of this function with respect to X and Y can be computed using the Kronecker relation as follows:

vec(XYI)=(IX)vec(Y)XYY=(IX)vec(IXY)=(YTI)vec(X)XYX=(YTI)

With this, the derivative of h(f(X),g(X))=f(X)g(X) becomes:

f(X)g(X)X=(If(X))g(X)X+(g(X)TI)f(X)X

The fact that I wrote the identity matrices corresponding to f and g with the same symbol should not make you assume that they both have the same dimensions. The matrix I that is Kronecker-multiplied by f(x) has dimensions equal to g(X), and vice versa.

There is one small point to talk about, and then we have closed the file on this post. We talked about the vec operator, but we did not say anything about the effect of transpose on this operator. For example, when we want to compute the derivative of AT with respect to A:

ATA=vec(AT)vec(A)

What does vec(AT) become? Does it have a relation with vec(A)? Well, it is obvious that I have asked a nonsensical question and that they do have a relation, but what relation?

For example, let us look at a 3 by 3 matrix:

vec([123456789])=[147258369]vec([123456789]T)=[123456789]

The relation between these two matrices can be written like this:

[100000000000100000000000100010000000000010000000000010001000000000001000000000001][123456789]=[147258369]

Matrices consisting of one 1 in each row are permutation matrices. Their job is to place the rows of the vector (or matrix) they are multiplied by in another order. In matrix algebra, we call the permutation matrix that turns vec(A) into vec(AT) the matrix T. But what remained was the derivative of the Kronecker product. Let us skip how to compute this one. Just know that the derivative of the Kronecker product has a result like the following:

ABA=(InTqmIp)(Imnvec(B))

This time I wrote the dimensions of the identity matrices and T, because if we do not write them, the probability of everything getting mixed up with everything else becomes high and the stew ends up in the yogurt. The expression above assumes that A has dimensions m×n and B has dimensions p×q.

Well, we have closed the file on Kronecker too. In the next post, we will deal with functions such as the inverse and determinant of a matrix, so that in the final post, we can solve a few sample problems using the tools we have discussed.