How to compute the gradient of
$$\eqalign{
f(x) &= 1^T \left[ \left( x - 1 \left[1^T x\right] \right) \odot \left(x - 1 \left[1^T x\right] \right) \right]\cr
}$$ where $x \in M_{n,1}(\mathbb{R})$, $1 \in M_{n,1}$ is a column vector with all ones, $\odot$ is an element-wise multiplication.
Asked
Active
Viewed 90 times
0
learning
- 661
-
The quantity $(x-1^Tx)$ is dimensionally incompatible. If $x$ is a vector and $1$ is a vector, then $1^Tx$ is a scalar. You can't subtract a scalar from a vector. – greg Apr 07 '19 at 23:49
-
I have done some modification. How about now? – learning Apr 08 '19 at 04:42
1 Answers
3
Setting the matrix of ones $11^T = J$, we can write $f$ in terms of a variable $a$ with differential:
\begin{align} a&= (I-J)x \\ da &= (I - J)dx \end{align}
where $I$ is the identity matrix.
Replacing $a$ and writing the expression in terms of the Frobenius product we can calculate the differential of $f$:
\begin{align} f &= 1 : a \odot a\\ df &= 1: 2a \odot da\\ &= 1 \odot 2a : da\\ &= 2a : da \\ &= 2(I-J)x : (I - J)dx\\ &= 2(I-J)^2x : dx \end{align}
Thus:
\begin{equation} \frac{\partial f}{\partial x} = 2(I-J)^2x = 2x +2(n-2)Jx \end{equation}
edit: thanks @greg
Traws
- 541