Indexing of variables in objective functions

Hello!

I have a problem formulating a SOCP problem in Matlab with cvx, it works for a simple example, but fails if i want to implement a larger set of constraints using indexed parameters:

% A: a cell of N*1 matrices each with a size of 2*30
% r: a 30*1 vector
cvx_begin
variables x(30) t(N) c(N)
n = 1:N;
minimize sum(t(n))
subject to
r.'*x == 1;
{[A{n,1}*x; 0.5*c(n)-0.5],0.5*c(n)+0.5} <In> lorentz(3);
{[c(n); 0.5*t(n)-0.5],0.5*t(n)+0.5} <In> lorentz(2);
t(n)  >= 0;
c(n)  >= 0; 
cvx_end

For this code, I get the error “Too many input arguments.” in the first lorentz-cone constraint. But when using only one element A{1,1} and consequently removing the indexing…

cvx_begin
variables x(30) t c
minimize t
subject to
r.'*x == 1;
{[A{1,1}*x; 0.5*c-0.5],0.5*c+0.5} <In> lorentz(3);
{[c; 0.5*t-0.5], 0.5*t+0.5} <In> lorentz(2);
t  >= 0;
c  >= 0;
cvx_end

… the optimization works. Is the indexing (n) for the constraint variables the problem and if so, how can I fix it?

Thanks a lot and best wishes!

A couple of things.

First of all, as a general rule (though it’s not 100% ironclad), if an expression doesn’t work when x is a numeric vector, it’s not going to work when x is a CVX variable. What exactly is A{n,1}*x supposed to do? It produces an error even outside of CVX:

>> A=cell(10,1);
>> for k =1  : 10,
A{k,1} = randn(2,30);
end
>> x=randn(30,1);
>> A{1:10,1}*x
Error using  * 
Too many input arguments.

So I don’t see how we can expect CVX to interpret it properly. I’m frankly not even sure what you’re trying to accomplish with this.

I would also say this: unless you have a specific reason, do not use lorentz when the norm function will do. That is to say, in your second example, you can just say this:

norm([A{1,1}*x; 0.5*c-0.5]) <= 0.5*c+0.5;
norm([c; 0.5*t-0.5]) <= 0.5*t+0.5;

Not only that, but your use of 0.5*c-0.5 and 0.5*c+0.5 suggests you’re trying to build up a quadratic or quartic. Well, if that’s the case, just do that: use square_pos or something like that.

The point of CVX is to help people avoid these kinds of tedious and error-prone transformations. I have actually fielded support requests from people who think there is a bug in CVX, when the actual problem is that they didn’t build their lorentz constraint properly. Let CVX do that!

EDIT: I found this copy of the paper. The actual CVX model is surprisingly easy. Let A\in\mathbb{C}^{(2N-1)\times P} be the matrix described at the beginning of part A—the conjugates of the vectors a are stacked as rows in the matrix A. Then an equivalent CVX model is just this:

cvx_begin
    variable x(P) complex
    minimize(norm(A*x),2*p)
    real(A(N,:)*x) == b
cvx_end

That’s it! This isn’t exactly the same model as they used, but it produces the same values of x. They really did not need to spend all that time converting it to an SOCP. But academics still feel the need to do that these days, I guess, even though they use tools like CVX to do it for them.

Thanks a lot, of course the n=1:N part does not make sense in the constraint functions. I actually implemented the algorithm in a way simpler form, as you suggested, and it works perfectly. But the paper I have this from claims that the above approach is “more efficient”.

This is the paper where the approach is described: link

Well, they certainly could not have implemented it this way! CVX has never accepted the A{n,1}*x construction. And I doubt their assertion that using lorentz is more efficient than the equivalent pow_pos, since CVX uses lorentz internally in such cases.

I think what you’ll find is that academic papers transform problems from their “natural” form to SOCP form for purely academic reasons. There is no practical reason to bother, if they’re using CVX, YALMIP, etc. to solve the problem.

Yep, I just looked at their paper. Their original problem, in equation (4), is already very close to a form that CVX can solve, using the pow_abs function. You have to build the sum up with a for loop, but other than that, you can solve (4) directly! No conversion to SOCP needed.

In fact, even (4) is more complex than CVX needs. It’s actually just a complex L_{2p}-norm minimization problem with a single equality constraint. With some care, you could express this in just 4-5 lines of CVX.

That actually is how I have this part of my optimization problem currently implemented. Thank you so much for your help!