MATLAB: L2 norm minimization

mathematicsoptimization

Hello, I'd like to find a transformation of a set of vectors X that maps to known vectors Y. This can be expressed as a standard least square optimization problem, i.e min |WX – Y|^2 where W is the transformation matrix I'm looking for.
Additionally, I would like to minimize the L2 norm of the matrix W so the full minimization problem becomes : min |W|^2 + |WX – Y|^2
This problem can be solved with gradient descent and I was just wondering which function from the Matlab optimization tool I should use ?
Thanks!

Best Answer

Using an nonlinear optimizer to solve this is overkill and completely silly, when a linear solver does it for you. Besides, with an optimizer you need to worry about convergence issues, starting values, etc.
Append an identity matrix to X, in this case as extra columns of X. Also append zeros to y. Then use slash (i.e /) to solve the problem.
W = [Y,zeros(1,N)]/[X,eye(N)];
This solves the regularized problem, where N is the number of rows in X. This solves the problem you have, with no optimizer needed at all. See that when [X,ones(N)] has more columns than rows, it solves the least squares problem you are asking to solve.
doc slash
help slash
As an example,
For example, make up some data:
X = rand(10,20);
Y = rand(1,20);
We wish to solve the problem
W*X = Y
This is easily accomplished using slash, if we did no regularization at all.
u = Y/X
u =
-0.10061 -0.039857 -0.087301 0.14731 0.40622 0.36113 -0.31992 0.32343 0.071708 0.16989
With regularization, thus solving the penalized sum of squares, we do it as:
u = [Y,zeros(1,10)]/[X,eye(10)]
u =
-0.013147 0.042605 0.0085151 0.089504 0.24349 0.1602 -0.11616 0.20876 0.14126 0.13649
The solution has been biased towards zero, as we should expect.