I notice that the matrix derivative technique might be useful for the contents of the course, and fortunately I know a good tutorial introducing the technique, but unfortunately the materials are in Chineses, therefore I translate and summarize the main idea of the tutorial and hope it could be helpful.
The contents are heavily borrowed from the post by 长躯鬼侠 (ECE PhD at CMU) on Zhihu (Chinese Quora).
The relation between differential and matrix derivative¶
Consider the matrix function f(X):X→R, which maps a matrix X∈Rn×d into a real number. This is the common setting for calculus of variantions (e.g., backpropagation of neural networks, optimal control), as the loss/control objective should always be a real number to be optimized and evaluated.
Recall why we are good at calculating the usual derivative: we basically calculate the derivative based on the composition of simple rules. For the matrix case, the chain rule of derivatives could be error-prone, that’s what makes the problem complicated. But fortunately, the composition of differentials still holds. Indeed, the matrix derivative and differential are connected by the following relation
where df∈R has the same shape with f and dX,∂X∂f∈Rn×d has the same shape with X, tr donotes the trace operator. Note that since df is a scalar, tr(df)=df, thus we could add trace on both sides.
In all, to calculate the matrix derivative ∂X∂f, our plan would be:
Take the differential of f w.r.t. X, by the composition of differentials.
Add trace on both sides, and arange the terms into the key relation by trace tricks.
Directly readout the derivative from the relation between differential and matrix derivative.
Consider a system Y=σ(WX), X∈Rd×n consists of n data points, each is a d-dimensional vector, W∈Rm×d, Y∈Rm×n, σ(⋅) is some nonlinear function. Denote the label matrix as Y^∈Rm×n, then the MSE loss