Find $X$ such that $ \left\| A \odot X - B \right\|_F^2$ is minimized

65 Views Asked by At

Find $X$ such that $ \left\| A \odot X - B \right\|_F^2$ is minimized, where $\odot$ denotes elementwise multiplication (or Hadamard product).

My solution is as follows as: Let $f(X) = \left\| A \odot X - B \right\|_F^2$. Then, the gradient is $\nabla f(x) = 2 A \odot \left( A \odot X - B \right) $. Thereafter, setting $\nabla f(x) = 0$ and solving for $X$, which reads \begin{align} X = \left(A \odot B\right) \oslash \left( A \odot A \right), \end{align} where $\oslash $ denotes elementwise division.

Is my solution correct?

1

There are 1 best solutions below

0
On

Your answer is correct as confirmed by greg but I started writing this before they replied and I don't want it to go to waste.

Let's compute the gradient of $f(X) = \|B\odot X-A\|^2$:

$$\mathrm{d}f = \mathrm{d}\left(h\circ g\right) = 2\langle B\odot X-A,\mathrm{d}g\rangle$$

where $h(X) = \frac{1}{2}\|X\|^2$ and $g(X) = B\odot X-A$. Then

$$dg = \mathrm{d}(B\odot X) - \mathrm{d}A = B\odot \mathrm{d}X.$$

So

$$\mathrm{d}f = 2\langle B\odot X-A,B\odot \mathrm{d}X\rangle = 2\langle B\odot(B\odot X-A),\mathrm{d}X\rangle.$$

The gradient is thus

$\nabla f(X) = 2B\odot(B\odot X-A).$

Setting this equal to $0$ gives

$$2B\odot(B\odot X-A) = 0\Leftarrow B\odot X = A \Leftarrow X = A\oslash B$$