CVX inaccuracy vs. mincx

I solved a sdp with matlab lmi using mincx but when i used cvx to solve it i got inaccurate warning and my cost function was much greater than the first run using mincx and infeasible for some other examples.
why is cvx failing to solve simple LMIs?

1 Like

The inaccurate warning and inaccuracy are due to the solver called by CVX, not CVX itself. You may find that Mosek works more relaibly than SeDuMi or SDPT3, especially on numerically challenging problems, which perhaps yours is; but we wonā€™t know until we see it.

Perhaps a forum reader can provide some assessment if you provide a complete reproducible example, to include all the input data as well as the solver and CVX output.

Aside from the differing abilities and numerical robustness of the solvers, one other possibility to consider is that you did not actually submit the same problem to mincx and CVX. In the interest of completeness, you should post your mincx code and output as well, although there may not necessarily be readers on this forum knowledegeable in mincx.

Thanks. checked my codes, I think solver is causing problem. also installed mosek but it is not helping.

here is my cvx code:
% sys is chosen arbitrary
[A,B,C,D]=ssdata(sys);

[no,n]=size( C);
[n,ni]=size(B);

cvx_begin sdp
% cvx_precision high
cvx_solver mosek

variable g
variable R(n,n) symmetric
variable S(n,n) symmetric
minimize g
subject to

-[AR+RAā€™ B;
Bā€™ -g*eye(ni)]==semidefinite(n+ni)

-[Aā€™S+SA Cā€™;
C -g*eye(no)]==semidefinite(n+no)

[R eye(n);
eye(n) S]==semidefinite(2*n)

cvx_end

here is my matlab code:
[A,B,C,D]=ssdata(sys);

[no,n]=size( C);
[n,ni]=size(B);

gmin=-1e12; tol=1e-3;
options=[tol 200 1e8 0 0];
setlmis([]);

R=lmivar(1,[n 1]);
S=lmivar(1,[n 1]);
g=lmivar(1,[1 0]);

lmiterm([1 1 1 R],A,1,ā€˜sā€™);
lmiterm([1 1 2 0],B);
lmiterm([1 2 2 g],-1,1);

lmiterm([2 1 1 S],1,A,ā€˜sā€™);
lmiterm([2 1 2 0],Cā€™);
lmiterm([2 2 2 g],-1,1);

lmiterm([-3 1 1 R],1,1);
lmiterm([-3 1 2 0],1);
lmiterm([-3 2 2 S],1,1);

clear c_obj

lmisys=getlmis;

nn=decnbr(lmisys);
c_obj(nn)= 1;

[gopt,xopt1]=mincx(lmisys,c_obj,options,[],gmin);

if ~isempty(gopt),
R=dec2mat(lmisys,xopt1,R);
S=dec2mat(lmisys,xopt1,S);
g=dec2mat(lmisys,xopt1,g);
else
return
end

You havenā€™t provided input data, and you havenā€™t shown output. Also donā€™t assume the forum readers have the ssdata function.

this is one of the systems that Iā€™ve simulated:

n0=27.48;
n1=-0.632;
n2=16.06;
n3=-0.756;
n4=2;
n5=-0.737;
d0=34.31;
d1=112.5;
d2=101.9;
d3=58.06;
d4=23.4;
d5=4.757;

sys=tf([n5 n4 n3 n2 n1 n0],[1 d5 d4 d3 d2 d1 d0]);

Can you please provide a complete CVX code, with all inputs, which does not require any toolboxes? You ought to be able to get the output from the toolbox functions, and provide it as input in your posted code.

If your original l code has
[A.B] = toolbox_function(c,d);
and this results in A = 1.2, B = 2ā€¦1, then your posted code should have A = 1.2,; B = 2.1;
Then execute the version of the code you have prepared in this way in a fresh MATLAB session and show us the output.

I need to solve this optimization with high precision(optimal value should be around 1e-8. I know this because mincx successfully solves my problem).
mosek fails, sdp3 inaccurately solves it and with sedumi optimal value is 6.9e-05. I cannot accept sedumiā€™s results because I am using them in two other sdp optimizations that run in succession which become infeasible if precision is low.
I also have provided my cvx code with inputs bellow:

clc, clear all;
A=[-0.2430   -0.1154   -1.5739   -1.1832    0.1111    0.0683;
   -0.1154   -0.0561   -2.9457   -0.7756    0.0619    0.0384;
    1.5739    2.9457   -0.4444   -0.9775    0.1923    0.1116;
    1.1832    0.7756   -0.9775   -2.5443    0.7207    0.3991;
    0.1111    0.0619   -0.1923   -0.7207   -0.8264   -1.8543;
   -0.0683   -0.0384    0.1116    0.3991    1.8543   -0.6428];
B=[0.4945;
    0.2038;
   -0.5436;
   -0.8579;
   -0.1148;
    0.0690];
C=[    0.4945    0.2038    0.5436    0.8579   -0.1148   -0.0690];
D=0;
[no,n]=size(C );
[n,ni]=size(B);
cvx_begin sdp
% cvx_precision high
% cvx_solver mosek
% cvx_solver sedumi
 cvx_solver SDPT3 


variable g
variable R(n,n) symmetric
variable S(n,n) symmetric
minimize g
%+1e-10*trace(R)+1e-10*trace(S)
subject to

-[A*R+R*A' B;
    B' -g*eye(ni)]==semidefinite(n+ni)

-[A'*S+S*A C';
    C -g*eye(no)]==semidefinite(n+no)

[R eye(n);
eye(n) S]==semidefinite(2*n)

cvx_end

Regards,

Your problem is ill-posed.

Using Mosek 9.0.87 produces

Calling Mosek 9.0.87: 134 variables, 43 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 9.0.87 (Build date: 2019-5-8 09:19:53)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 43              
  Cones                  : 0               
  Scalar variables       : 0               
  Matrix variables       : 3               
  Integer variables      : 0               

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.02    
Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 43              
  Cones                  : 0               
  Scalar variables       : 0               
  Matrix variables       : 3               
  Integer variables      : 0               

Optimizer  - threads                : 8               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 43
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 0                 conic                  : 0               
Optimizer  - Semi-definite variables: 3                 scalarized             : 134             
Factor     - setup time             : 0.00              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 946               after factor           : 946             
Factor     - dense dim.             : 0                 flops                  : 6.75e+04        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   1.3e+00  1.0e+00  1.0e+00  0.00e+00   0.000000000e+00   0.000000000e+00   1.0e+00  0.05  
1   2.2e-01  1.7e-01  2.6e-01  -7.88e-01  -4.203056913e+00  -2.299921100e+00  1.7e-01  0.13  
2   3.1e-02  2.3e-02  1.3e-02  5.98e-01   -1.301814435e+00  -1.052672273e+00  2.3e-02  0.13  
3   4.1e-03  3.1e-03  8.7e-04  8.06e-01   -4.180042387e-01  -3.522413446e-01  3.1e-03  0.13  
4   5.0e-04  3.7e-04  8.9e-05  2.76e-01   -1.791853323e-01  -1.257568582e-01  3.7e-04  0.13  
5   6.3e-05  4.7e-05  9.7e-06  1.45e-01   -8.566595977e-02  -4.418532382e-02  4.7e-05  0.14  
6   1.2e-05  8.8e-06  1.2e-06  4.33e-01   -4.645256878e-02  -2.845478043e-02  8.8e-06  0.14  
7   2.1e-06  1.6e-06  1.6e-07  3.84e-01   -2.593006053e-02  -1.555055329e-02  1.6e-06  0.14  
8   4.7e-07  3.5e-07  2.8e-08  5.06e-01   -1.538324103e-02  -9.098928259e-03  3.5e-07  0.16  
9   1.2e-07  9.4e-08  5.3e-09  5.97e-01   -9.881680665e-03  -6.668739845e-03  9.4e-08  0.16  
10  4.8e-08  3.6e-08  2.4e-09  1.40e-01   -7.452837380e-03  -3.187845465e-03  3.6e-08  0.16  
11  8.2e-09  6.2e-09  2.1e-10  7.06e-01   -3.778673804e-03  -2.643217619e-03  6.2e-09  0.17  
12  1.3e-09  9.8e-10  2.6e-11  4.51e-01   -2.142965789e-03  -1.462841396e-03  9.8e-10  0.17  
13  5.6e-10  4.2e-10  1.3e-11  1.33e-01   -1.707725691e-03  -6.948816421e-04  4.2e-10  0.17  
14  8.9e-11  6.7e-11  1.0e-12  7.14e-01   -8.257356440e-04  -5.839109400e-04  6.7e-11  0.19  
15  1.8e-11  1.4e-11  1.7e-13  4.54e-01   -5.128554415e-04  -3.648877608e-04  1.4e-11  0.19  
16  5.2e-12  3.9e-12  5.1e-14  1.70e-01   -3.339469038e-04  -1.654109190e-04  3.9e-12  0.19  
17  9.5e-13  7.2e-13  5.3e-15  6.65e-01   -1.841987395e-04  -1.291230942e-04  7.2e-13  0.20  
18  1.3e-13  9.7e-14  5.6e-16  4.39e-01   -9.799057648e-05  -6.330275474e-05  9.5e-14  0.20  
19  6.6e-14  5.3e-14  3.4e-16  4.32e-01   -8.330955324e-05  -3.611397792e-05  5.0e-14  0.20  
20  1.4e-14  1.6e-14  3.8e-17  7.60e-01   -4.535494749e-05  -3.250483990e-05  1.1e-14  0.20  
21  3.3e-15  4.9e-15  8.5e-18  3.63e-01   -2.780569015e-05  -1.612474357e-05  2.5e-15  0.22  
22  8.3e-16  4.4e-15  1.4e-18  6.41e-01   -1.779855361e-05  -1.282894159e-05  6.2e-16  0.22  
23  2.4e-16  3.3e-15  4.4e-19  2.83e-01   -1.175294775e-05  -6.100990529e-06  1.8e-16  0.22  
24  4.8e-17  2.0e-15  5.1e-20  6.82e-01   -6.797485486e-06  -4.866177337e-06  3.6e-17  0.23  
25  8.0e-18  2.7e-15  7.3e-21  4.17e-01   -3.770924061e-06  -2.305963359e-06  6.0e-18  0.23  
26  2.7e-18  2.4e-15  1.7e-21  7.08e-01   -2.676342257e-06  -1.944487822e-06  2.0e-18  0.23  
27  1.1e-18  2.9e-15  9.6e-22  1.12e-01   -2.117097552e-06  -8.545261702e-07  8.5e-19  0.25  
28  1.5e-19  3.6e-15  6.3e-23  7.09e-01   -9.734029712e-07  -6.821365263e-07  1.2e-19  0.25  
29  4.0e-20  2.9e-15  1.2e-23  5.25e-01   -6.565806959e-07  -4.913282517e-07  3.0e-20  0.25  
30  1.2e-20  4.0e-15  4.5e-24  1.10e-01   -4.432024168e-07  -2.074135639e-07  9.2e-21  0.25  
31  1.8e-21  4.4e-15  3.6e-25  6.73e-01   -2.236080939e-07  -1.567538193e-07  1.4e-21  0.27  
32  4.6e-22  2.0e-15  6.9e-26  5.15e-01   -1.489665686e-07  -1.099102367e-07  3.5e-22  0.27  
33  1.4e-22  3.6e-15  2.3e-26  1.29e-01   -9.889971045e-08  -4.738959834e-08  1.0e-22  0.28  
Optimizer terminated. Time: 0.34    


Interior-point solution summary
  Problem status  : ILL_POSED
  Solution status : PRIMAL_ILLPOSED_CER
  Dual.    obj: -3.4819661704e-15   nrm: 2e+00    Viol.  con: 0e+00    barvar: 7e-08  
Optimizer summary
  Optimizer                 -                        time: 0.34    
    Interior-point          - iterations : 33        time: 0.28    
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        Clean primal        - iterations : 0         time: 0.00    
        Clean dual          - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

------------------------------------------------------------
Status: Failed
Optimal value (cvx_optval): NaN

If the primal is solved instead (via YALMIP), Mosek reports
Problem status : UNKNOWN
Solution status : UNKNOWN

Setting g to a constant as small as 1e-7 allows the feasibility problem to be solved in all of SeDuMi, SDPT3, and Mosek.

It is obvious that negative value of g can not be feasible.due to making lower right blocks of the first tw0 constraints the wrong definiteness.

value of g is positive! I think you missed the negative before bracket.
I am currently working on ill-posed problems. further recommendations for improving the formulation would be a great help.

I didnā€™t miss either of the negative signs (directly preceding g as well as outside the brackets for the entire matrix) . So g nonnegative is necessary for feasibility. As g decreases toward zero, the problem becomes ill-posed, with min(trace(R)) increasing toward infinity as g decreases. The problem is theoretically infeasible (i.e., in exact arithmetic) if g is negative.

I think the infimum, but not minimum, of g is at g = 0, and this is achieved by driving trace(R) to infinity. Numerical solvers are not good at dealing with an infinum which is not a minimum. And in this case, the infimum is ā€œachievedā€ (well, not really achieved) at the boundary of feasibility. So that is very ill-posed for a numerical solver.

I will leave corroboration of my assertions and any further diagnosis and recommendations for how to improve the formulation to the Mosek guys.

If your research aim is to work on ill-posed problems, at least you now have an example. :smile:

1 Like

The Mosek log shows that the problem is illposed. To me it seems Mosek is doing the best it can.

I installed an older version of cvx and my problem was solved!

Can you show us the output of cvx_version, as well as all CVX and solver output?

I approved this results because my next two optimization problem become feasible using the output!?
cvx_version:

CVX version 1.22
Code: build 841, 2012-08-16 16:01:21
Documentation: build 827, 2012-02-01 09:48:08
MATLAB version 9.3 (R2017b) on PCWIN64

here is my output:

Calling sedumi: 134 variables, 43 equality constraints
For improved efficiency, sedumi is solving the dual problem.

SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 43, order n = 27, dim = 243, blocks = 4
nnz(A) = 446 + 0, nnz(ADA) = 1849, nnz(L) = 946
it : by gap delta rate t/tP t/tD* feas cg cg prec
0 : 2.51E+00 0.000
1 : -2.63E+00 4.86E-01 0.000 0.1933 0.9000 0.9000 -0.02 1 1 3.9E+00
2 : -8.92E-01 3.54E-02 0.000 0.0728 0.9900 0.9900 1.02 1 1 3.3E-01
3 : -3.76E-01 7.35E-03 0.000 0.2080 0.9000 0.9000 0.75 1 1 7.0E-02
4 : -1.96E-01 1.43E-03 0.000 0.1945 0.9000 0.9000 0.19 1 1 2.7E-02
5 : -5.91E-02 1.11E-04 0.017 0.0776 0.9900 0.9900 -0.10 1 1 5.7E-03
6 : -1.83E-02 3.66E-05 0.315 0.3294 0.9000 0.9000 -0.41 1 1 3.8E-03
7 : -1.97E-02 8.13E-06 0.000 0.2223 0.9000 0.9000 0.24 1 1 9.2E-04
8 : -7.98E-03 3.86E-07 0.000 0.0475 0.9900 0.9900 0.47 1 1 6.5E-05
9 : -4.59E-03 8.10E-08 0.000 0.2099 0.9000 0.9000 0.18 1 1 2.6E-05
10 : -2.41E-03 1.63E-08 0.000 0.2017 0.9000 0.9000 0.11 1 1 1.0E-05
11 : -1.21E-03 3.28E-09 0.000 0.2010 0.9000 0.9000 0.15 1 1 3.5E-06
12 : -7.45E-04 7.30E-10 0.000 0.2224 0.9000 0.9000 0.32 1 1 1.2E-06
13 : -5.28E-04 2.00E-10 0.000 0.2742 0.9000 0.9000 0.45 1 1 4.4E-07
14 : -3.16E-04 4.84E-11 0.000 0.2419 0.9000 0.9000 0.38 1 1 1.8E-07
15 : -2.09E-04 1.29E-11 0.000 0.2654 0.9000 0.9000 0.44 1 1 7.1E-08
16 : -1.25E-04 3.35E-12 0.000 0.2609 0.9000 0.9000 0.38 1 1 3.1E-08
17 : -9.05E-05 9.67E-13 0.000 0.2885 0.9000 0.9000 0.50 1 1 1.2E-08

iter seconds digits cx by
17 0.8 Inf -1.3413692316e-04 -9.0479108730e-05
|Ax-b| = 2.1e-08, [Ay-c]_+ = 0.0E+00, |x|= 7.1e-01, |y|= 2.7e+04

Detailed timing (sec)
Pre IPM Post
9.375E-02 7.500E-01 7.813E-02
Max-norms: ||b||=1, ||c|| = 2,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.19306.

Status: Solved
Optimal value (cvx_optval): +9.04791e-05

That is an ancient version of CVX and of Sedumiā€¦ Can you show the output running the exact same problem, but calling SeDuMi with CVX 2.1? Note that the version of SeDuMi which is included with CVX 2.1 is 1.34 (beta).