Assume that $X\in\mathbb{R}^{n\times n}\geq 0$, $Y\in\mathbb{R}^{n\times k}\geq 0$ and $Z\in\mathbb{R}^{k\times n}\geq 0$. Let us define the function $f(Y,Z)$ as follows: $$f(Y,Z)=\Vert X-YZ\Vert_W^2:=\mathrm{trace}\left((X-YZ)^T(W\circ(X-YZ))\right),$$ where $\circ$ is the Hadamard product and $W\in\mathbb{R}^{n\times n}\geq 0$ is symmetric.
It can be seen that \begin{align*} f(Y,Z)&=\mathrm{trace}\left((X^T-Z^TY^T)(W\circ(X-YZ))\right)\\ &=\mathrm{trace}(X^T(W\circ X))-\mathrm{trace}(X^T(W\circ (YZ)))-\mathrm{trace}(Z^TY^T(W\circ X)) +\mathrm{trace}(Z^TY^T(W\circ (YZ))). \end{align*} Now, according to the fact that $\mathrm{trace}(AB)=\mathrm{trace}(BA)$, and $\mathrm{trace}(A^T(B\circ C)=trace((A\circ B)^TC)$, it follows that $$f(Y,Z)=\mathrm{trace}(X^T(W\circ X))-2\mathrm{trace}(Z^TY^T(W\circ X)) +\mathrm{trace}(Z^TY^T(W\circ (YZ))).$$
I have a question about the derivative of $f$ with respect to $Y$ or $Z$. To this end, we have $$\frac{\partial \mathrm{trace}(Z^TY^T(W\circ X))}{\partial Y}=(W\circ X)Z^T,\quad and\quad \frac{\partial \mathrm{trace}(Z^TY^T(W\circ X))}{\partial Z}=Y^T(W\circ X).$$
What can it be said about the following items? $$\frac{\partial \mathrm{trace}(Z^TY^T(W\circ (YZ)))}{\partial Y},\quad and\quad\frac{\partial \mathrm{trace}(Z^TY^T(W\circ (YZ)))}{\partial Z}.$$
I would be appreciate if someone can help me.
If we define $\phi=\mathrm{trace}(Z^TY^T(W\circ (YZ)))$ and $A=YZ$, it can be observed that $$\phi=\mathrm{trace}(Z^TY^T(W\circ (YZ)))=\mathrm{trace}(A^T(W\circ A)).$$ For more convenience, let's define $\mathrm{trace}(C^TD)=C:D$. Hence, \begin{align*} \phi=W\circ A:A, \end{align*} and we can conclude that \begin{align*} d\phi&=2W\circ A:dA\\ &=2W\circ (YZ):d(YZ)\\ &=2W\circ (YZ):(dY\,\,Z+Y\,\,dZ)\\ &=2(W\circ (YZ))Z^T:dY+2Y^T(W\circ (UV)):dZ. \end{align*} As a consequence, we get \begin{align*} &\frac{\partial\phi}{\partial Y}=2(W\circ (YZ))Z^T,\\ &\frac{\partial\phi}{\partial Z}=2Y^T(W\circ (UV)). \end{align*}