[Math] derivative with respect to a diagonal matrix

derivativeslinear algebramatricesmatrix-calculusmultivariable-calculus

Had check some previous questions regarding the derivatives of diagonal matrices, but haven't found a form like this.

If $K=Wdiag(s)W^T$, in which $W$ is an m-by-n matrix, and $diag(s)$ represents an n-by-n diagonal matrix of which diagonal is represented by the vector $s$. I'm interested in the derivative of the log-determinant of K, ($\frac{\partial{ln}|K|}{\partial{s}}$), but I get stuck at solving this part: $\frac{\partial{K}}{\partial{s}}$

Best Answer

We have, with $S = \operatorname{Diag}(s)$:

$$ \begin{align} K &= W S W^T\\ dK &= W dS W^T \end{align} $$

Finding the differential and gradient of your expression, knowing that $K$ is symmetric:

$$ \eqalign{ f &= \log \det(K) \\ &= \operatorname{tr}(\log(K)) \\ df &= K^{-T} : dK \\ &= K^{-1} : W dS W^T\\ &= W^T K^{-1} W : dS\\ &= \operatorname{diag}(W^T K^{-1} W) : ds } $$

Thus we can identify:

\begin{equation} \frac{\partial f}{\partial s} = \operatorname{diag}(W^T K^{-1} W) \end{equation}


The colon used here denotes the Frobenius inner product:

$$ A:B = \operatorname{tr}(A^TB)$$

with the following properties derived from the underlying trace function

$$\eqalign{A:BC &= B^TA:C\cr &= AC^T:B\cr &= A^T:(BC)^T\cr &= BC:A \cr } $$