Error using sparse. sparse(A) does not accept char inputs A


(John Wick) #1

I am trying to solve the optimization problem given below:

\max log_2det(\delta * H * H')
subject to
trace(\delta) < 3

Here, H is a 3$\times$3 matrix and \delta (the optimization variable) is a diagonal matrix of the same size. Here is the code I have written:

H = [1 2 3; 4 5 6; 7 8 9];
cvx begin

variables double(v(1,3))

% Objective Function
maximize (log2 (det (diag((v)) * H * H')))

% Constraints
subject to
1 <= trace(diag(v)) < 3;

cvx end

However, I am getting an error that says, “Error using sparse sparse(A) does not accept char inputs A. Use sparse(double(A)) instead.” What am I doing wrong here? Thanks in advance for the help.


(Mark L. Stone) #2

You have several syntax errors as well as optimization formulation problems.

Use cvx_begin and cvx_end. Use log_det (you can divide by log(2) if you want, but I won’t bother). Don’t use double.

The argument of log_det, namely diag((v)) * H * H' is not symmetric, so I think. is not a convex optimization problem. I will now guess that you intended H*diag(v)*H' to be that argument. Making all these changes, a problem which can be accepted by CVX can be entered (I also changed < 3 to <= 3, which is how it will be interpreted by CVX).

H = [1 2 3; 4 5 6; 7 8 9];
cvx_begin
variables v(1,3)
maximize (log_det (H*diag((v))* H'))
% Constraints
subject to
1 <= trace(diag(v)) <= 3;
cvx_end

However, this problem is unbounded, as can be seen by making v(1) large and v(2) = -v(1), which will still meet the constraint 1 <= trace(diag(v)) <= 3.

If you add a constraint such as v >= 0, the problem will be bounded and have a finite solution. However, with sedumi, sdpt3, and scs, in CVX3.0beta build 1177, this problem incorrectly is reported as being unbounded (i.e., with constraint v >= 0 added) which appears to be a bug in CVX 3.0 beta build 1177, because CVX 's successive approximation method is not being used when scs is used.


(John Wick) #3

Wow! Thanks a lot for your reply. I have two more questions.

When I solve this system, the result is not integer. I tried to add some if/else statement to round the variable but CVx does not allow it. Is there anyway to get the optimized variable in binary form?

Also, if its not possible to get the binary result, how should I rewrite the problem to get the integer form solution for the diagonal matrix? Thanks a lot.


(Mark L. Stone) #4

I think you’re out of luck for solving a mixed integer version of this problem with CVX and current versions of solvers. If you have CVX Professional and MOSEK, there is an integer capability for MILP/MIQP/MISOCP, but not for MISDP. Note that although CVX will call MOSEK for mixed integer problems in which CVX"s successive approximation method is used, CVX’s successive approximation will not work correctly, and will return unreliable, quite possibly erroneous results.

Although I suggested using logdet, for your problem, you could maximize det_rootn instead. The argmax will be the same. This will not cause CVX"s successive approximation method to be invoked. The bad news is that I believe that would require making use of a mixed integer SDP capability, which MOSEK does not currently have (for problems which can not be expressed as mixed integer SOCP)…

I recommend using det_rootn instead of log_det fo rthe continuous variable version of the problem… Actually, you could solve the problem by brute force enumeration of all possible integer vectors v satisfying the constraints, and evaluating the objective function. Largest objective function wins.