L2 norm minimization
32 views (last 30 days)
Show older comments
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!
4 Comments
Beverly Grunden
on 27 Feb 2018
I appreciate your comments and suggestions. Unfortunately I did not choose this minimization problem. The one norm is intended to force sparsity on the vector components. I am attempting to replicate what the authors of a certain article did and then make a comparison to my novel method.
Thanks for your input. I will explore your ideas.
John D'Errico
on 27 Feb 2018
You can obviously do as you wish, even if it seems absurd to me.
You will have little choice but to use an optimization, because of the mixed norms. Thus, were it entirely an L1 norm, you can solve the problem using linprog. Were it entirely an L2 norm, you can just use backslash. The hybrid? Just a brute force optimization, and as I said, it may exhibit some issues at that.
Accepted Answer
John D'Errico
on 2 Jun 2011
Edited: John D'Errico
on 10 Mar 2017
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.
2 Comments
Shankararama Sharma R
on 10 Mar 2017
This gives a W with dimension 1*(M+N). But we should only get 1*M, right?
John D'Errico
on 10 Mar 2017
Edited: John D'Errico
on 10 Mar 2017
It was a long time ago that I wrote that. :)
As it turns out, I was sloppy, and wrote the wrong expression, I forgot to append zeros to Y. I've fixed that, as well as adding an example. As you can see, the solution has the correct number of values.
You are mistaking the solution for one where you solve the problem
X*W = Y
Here, you would use BACKSLASH. Thus
W = X\Y
or with the simple ridge regression regularization employed here, that becomes
W = [X;eye(N)]\[Y;zeros(N,1)]
Note the differences. In this case, I append X as rows to X, also zero rows to Y.
It is important whether you are using / or \ to solve the problem. In turn, that depends on which form your original problem was in.
More Answers (1)
Laura Proctor
on 2 Jun 2011
For example, you have indicated that you have the equation WX = Y where X and Y are given. To arrive at the least-squares fit for an overdetermined system, MATLAB has the algorithm built-in to the forward slash operator, so that you simply need to type in the following line:
W = Y/X
Often the system of equations is written as Ax = b where one must solve for x --- in this case use the backslash operator:
x = A\b
If you are interested in the optimization functions available, check out this page which shows all of the functions available in base MATLAB:
1 Comment
John D'Errico
on 2 Jun 2011
Note that slash by itself fails to solve the problem given by the OP. You must augment the system with an identity to introduce a term consistent with the square of the norm of X.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!