Derivative of trace of matrix

2.8k Views Asked by At

I'm new to matrix calculus and I have a problem with my assignment. Following is a function of trace of matrices: $$ f = \mathrm{tr}[\mathbf{X} \mathbf{X^T}] - \mathrm{tr}[\mathbf{X} \mathbf{H^T} \mathbf{W}^T] - \mathrm{tr}[\mathbf{W} \mathbf{H} \mathbf{X}^T] + \mathrm{tr}[\mathbf{W} \mathbf{H} \mathbf{H}^T \mathbf{W}^T]. $$

And I have to prove that: $$ \frac {\partial \mathrm{tr}[ (\mathbf{X}-\mathbf{W}\mathbf{H}) (\mathbf{X}-\mathbf{W}\mathbf{H})^T ] } {\partial W} = -2 \mathbf{X} \mathbf{H}^T + 2 \mathbf{W} \mathbf{H} \mathbf{H}^T. $$

In the second equation, the numerator is f in the fist equation. Can you help me solve this? Thank you.

2

There are 2 best solutions below

3
On BEST ANSWER

$f(W)=\mathrm{Constant}-2\mathrm{tr}(XH^TW^T)+\mathrm{tr}(WHH^TW^T)$.

The derivative is $$ \begin{align*} Df_W:Z\rightarrow &-2\mathrm{tr}(XH^TZ^T)+\mathrm{tr}(ZHH^TW^T)+\mathrm{tr}(WHH^TZ^T)\\ &=-2\mathrm{tr}(XH^TZ^T)+2\mathrm{tr}(ZHH^TW^T)\\ &=-2\langle XH^T,Z\rangle+2\langle WHH^T,Z\rangle. \end{align*}$$

Thus the gradient is $\nabla(f)(W)=-2XH^T+2WHH^T$.

1
On

Here is my solution. Sorry for posting the image but I don't know how to type formulas on this text box. My solution uses denominator notation as described here

Most of formulas mentioned in the solution also from Wiki, please have a look if you are confused.enter image description here