Quadratic to matrix form

64 Views Asked by At

How can I show that $J(w) = \Sigma_{i=0}^m u_i(w^Tx_i-y_i)^2$ can be re-written to $J(w)=(Xw-y)^TU(Xw-y)$ and how can I differentiate the 2nd equation with respect to w? where $x_i \in\mathbb {R^n}, u_i \in\mathbb {R}, i = 1.....m, w \in\mathbb{R^n} $

btw, w, x and y are matrices, w is the weight for each value of x, y is the result for each x.

I tried like this: $\Sigma_{i=0}^m u_i((w^Tx_i)^2 - 2w^Tx_iy_i + y_i^2)$

$\Sigma_{i=0}^m u_i(w^Tx_i (w^Tx_i - 2y_i) + y_i^2)$

I have been out of touch with the matrices/linear algebra for a long time and I am just not seeing how I could transform this, any help is much appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

Let $U$ be the diagonal matrix $U:={\rm diag}(u_1,u_2,\dots,u_n)$. Then, for a vector $a=(a_1,\dots,a_n)^T$ we have $Ua=(u_1a_1,\dots,u_na_n)^T$, and hence $$a^TUa= \sum_{i=1}^n u_ia_i^2\,.$$ Now apply it to $a:=Xw-y$.
(If you want to arrive strictly at $w^Tx_i$, first note that $x_i^Tw=w^Tx_i$ as the inner product is commutative, then I think the $x_i$ should be a column vector: the transpose of the $i$th row of matrix $X$... so there seem to be a twist in this story..)

For differentiation, see e.g. the matrix cookbook or wikipedia.