# How to compute the derivative $f(X) = \|\mathcal{P}_\Omega(X-A)\|^2_F$?

How to compute the derivative $$f(X) = \| \mathcal{P}_\Omega(X-A)\|_F^2$$

here $$\mathcal{P}_\Omega(\cdot)$$ is a projector, $$[\mathcal{P}_\Omega(Y)]_{ij} = Y_{ij}$$ if $$(i,j)\in \Omega$$, zero otherwise.

How to compute

$$\frac{\partial f(X)}{\partial X}$$

thanks

• I think you're supposing to use $\frac{\partial }{\partial X} \| X \|_{F}^{2} = \frac{\partial}{\partial X} \textrm{Tr}(XX^{T})$ so you'd replace that with $\mathcal{P}_{\Omega}(X-A)$ – Shogun May 21 at 2:45

Define the matrices $$----------\\ P_{ij}=\begin{cases}1\quad{\rm if\,\,} i,j\in\Omega\\0\quad{\rm otherwise}\end{cases}\\ ----------\\ Y = P\odot(X-A)$$ Write the function in terms of these new variables. Then find its differential and gradient. \eqalign{ f &= \|Y\|_F^2 = Y:Y \cr df &= 2Y:dY = 2Y:P\odot dX = 2P\odot Y:dX = 2Y:dX \cr \frac{\partial f}{\partial X} &= 2Y = 2P\odot(X-A) \cr } where $$(\odot)$$ denotes the elementwise/Hadamard product, and $$(:)$$ denotes the trace/Frobenius product, i.e. \eqalign{ A:B = {\rm Tr}(A^TB) } Also note that the projection operation is idempotent, i.e. $$\,P\odot P=P$$