How to get the values of dual variables for an SDP solved by MOSEK?

600 views
Skip to first unread message

Jiaxin Yang

unread,
May 12, 2015, 7:07:22 PM5/12/15
to yal...@googlegroups.com
Hi Johan,

Any idea on how to get the values of dual variables associated with a specific constraint in an SDP, which is solved by YALMIP along with MOSEK? P.S., I do not know where the value of dual variable is stored in the solution struct.

Johan Löfberg

unread,
May 13, 2015, 1:56:40 AM5/13/15
to yal...@googlegroups.com

Jiaxin Yang

unread,
May 13, 2015, 3:17:17 PM5/13/15
to yal...@googlegroups.com
Hi Johan,

Thanks a lot. But when I try to get the dual variable of an LMI, which should be a positive semidefinite matrix, I only get the NaN results. Do you know what the problem is?

Jiaxin Yang

unread,
May 13, 2015, 3:40:51 PM5/13/15
to yal...@googlegroups.com
Below is the report returned by MOSEK:

%%%%%%%%%%%%%%%%%%%%%%%%
Interior-point solution summary
  Problem status  : PRIMAL_AND_DUAL_FEASIBLE
  Solution status : NEAR_OPTIMAL
  Primal.  obj: 4.5083116281e+001   Viol.  con: 1e-006   var: 0e+000   barvar: 0e+000   cones: 0e+000 
  Dual.    obj: 4.5083113633e+001   Viol.  con: 0e+000   var: 4e-006   barvar: 0e+000   cones: 0e+000 
Optimizer summary
  Optimizer                 -                        time: 0.14    
    Interior-point          - iterations : 13        time: 0.09    
      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    
        Clean primal-dual   - iterations : 0         time: 0.00    
    Simplex                 -                        time: 0.00    
      Primal simplex        - iterations : 0         time: 0.00    
      Dual simplex          - iterations : 0         time: 0.00    
      Primal-dual simplex   - iterations : 0         time: 0.00    
    Mixed integer           - relaxations: 0         time: 0.00    

Mosek error: MSK_RES_TRM_STALL ()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Is it because the solution is only near-optimal? 

drw5ff

unread,
May 13, 2015, 4:05:54 PM5/13/15
to yal...@googlegroups.com
MSK_RES_TRM_STALL is defined here. It usually means you have an ill defined constraints. 

Johan Löfberg

unread,
May 14, 2015, 2:38:30 PM5/14/15
to yal...@googlegroups.com
supply reproducible code

Jiaxin Yang

unread,
May 14, 2015, 2:54:24 PM5/14/15
to yal...@googlegroups.com
clearvars
clc
K = 1; NR = 4; SR = sqrt(0.01); SD = sqrt(0.05); SE = sqrt(0.01);
ep1 = 0.05; ep2 = 0.05;
h1 = 1/sqrt(2)*randn(NR,1)+1i/sqrt(2)*randn(NR,1);
h2 = 1/sqrt(2)*randn(NR,1)+1i/sqrt(2)*randn(NR,1);
ge1 = 1/sqrt(2)*randn(1,K)+1i/sqrt(2)*randn(1,K);
ge2 = 1/sqrt(2)*randn(NR,K)+1i/sqrt(2)*randn(NR,K);
Rd = 2;
PS = 1; PR = 1; kappa=1; 
gamma = 2^(2*kappa*Rd)-1;
ops = sdpsettings('solver','mosek','verbose',0,'savesolveroutput',1,'cachesolvers',1);

%% G-PDCA
x = sdpvar(1,1); y = sdpvar(1,1); t1 = sdpvar(1,1); t2 = sdpvar(1,1); W = sdpvar(NR,NR,'full','complex');
S = sdpvar(NR+1,NR+1,K,'hermitian','complex'); Psi = sdpvar(NR,NR,'hermitian','complex'); rho = sdpvar(1,K); s = sdpvar(1,1);
F = sdpvar(NR+1,NR+1,K,'hermitian','complex');
Q = 10^4; mu = 10; maxiter = 20; SS = sqrt(min(PS, min(gamma*SE^2./abs(abs(ge1)+sqrt(ep1)).^2)));
qq=1/SS^2; WW=0.99*sqrt(PR/(h1'*h1/qq+SR^2*NR))*eye(NR); tt2=real(SR^2*h2'*WW*WW'*h2+SD^2);
tau=0.01; 
for iter = 1:maxiter  
    Psi = 0;
    SINR(iter)=abs(h2'*WW*h1)^2/qq/tt2;
    M1 = [qq*eye(NR), W*h1; h1'*W', t3];
    Omega = [SR^2*h2'*W*W'*h2+trace(h2*h2'*Psi)+SD^2<=t2; M1>=0;...
         t3+SR^2*trace(W*W')+trace(Psi)<=PR; Psi>=0];
    Obj = -abs(h2'*WW*h1)^2/tt2-2*real(h2'*(W-WW)*h1*h1'*WW'*h2)/tt2+abs(h2'*WW*h1)^2/tt2^2*(t2-tt2);
    %M2 = [x, t2, t1; t2, y, q; t1, q, 1];
    C=[t1>=0; t2>=0];
     for k=1:K
         P = [eye(NR),ge2(:,k)];
         Lambda = blkdiag(rho(k)*eye(NR),gamma*SE^2-ep2*rho(k));
         M3 = [qq, h1'*W'*P; P'*W*h1, F(:,:,k)]; % Correct
         C=[C; M3>=0; F(:,:,k)-Lambda-gamma*P'*Psi*P-gamma*SR^2*P'*(WW*WW'+(W-WW)*WW'+WW*(W-WW)')*P<=S(:,:,k); S(:,:,k)>=0];
         Obj=Obj+tau*trace(S(:,:,k));
     end
     %DC = [x-2*tt1*(t1-tt1)<=0];
     C = [C; Omega];
     Obj=Obj+5*trace((W-WW)*(W-WW)');
    sol=optimize(C,Obj,ops);
    tt2=double(t2); WW=double(W); 
    Phi=dual(C(4));
    tau=min(mu*tau,10^4);
    sv(iter)=double(trace(S(:,:,1)));
end

Johan Löfberg

unread,
May 14, 2015, 3:23:11 PM5/14/15
to yal...@googlegroups.com
YALMIP does not save duals when it has to convert from a complex-valued problem to a real-valued one. If you want the duals, you'll ave to define the real LMIs manually

Jiaxin Yang

unread,
May 14, 2015, 3:43:10 PM5/14/15
to yal...@googlegroups.com
Any possible solution that I can get the values of dual variables directly from MOSEK?

Johan Löfberg

unread,
May 14, 2015, 3:50:31 PM5/14/15
to yal...@googlegroups.com
yes, use the option savesolveroutput and it will be saved in the sol structure

Jiaxin Yang

unread,
May 14, 2015, 3:57:00 PM5/14/15
to yal...@googlegroups.com
I found the values of the dual variables are stored in sol.solveroutput.res.sol.itr.snx
But I do not know which is value is corresponding to which constraint

Johan Löfberg

unread,
May 14, 2015, 4:02:34 PM5/14/15
to yal...@googlegroups.com
same order as in yalmip. however, I would recommend you to derive the real lmi instead and then apply dual (X>0 is [re(X) im(X);-im(X) re(x)] >0). then you just have to figure out how that double size dual relates to you original complex valued lmi

Erling D. Andersen

unread,
May 15, 2015, 1:53:28 AM5/15/15
to yal...@googlegroups.com
First note that independent what MOSEK calls the solution then it is an approximation to the optimal solution. We are doing computations in finite precision and the solution may not be rational . Just as well as your model most likely only is an approximation to the real problem. Therefore, nevertheless independent what MOSEK calls the solution you will have ask yourself is the approximation good enough for my purpose.

Near optimal means it does satisfy the normal termination criterion relaxed by a factor of 100. A near optimal solution is in my experience good enough for most practical purposes. The factor of 100 is user adjustable.

The solution summary also shows the solution is quite good.




Erling D. Andersen

unread,
May 15, 2015, 1:55:43 AM5/15/15
to yal...@googlegroups.com
.snx is dual variables related to conic quadratic constraints. More info. about the dual problem employed by MOSEK at

Jiaxin Yang

unread,
May 16, 2015, 3:18:20 PM5/16/15
to yal...@googlegroups.com
Thx so much Erling.
Reply all
Reply to author
Forward
0 new messages