How to define variable quantity symmetric vairiable matrix?

(feifan) #1

I want to define ‘n’ symmetric variable matrix, but the n is not a fixed value. How to define the variables?

(Mark L. Stone) #2

n has to have a numerical value at the time of the variable declaration.

% This will work
n = 3;
cvx_begin
variable X(n,n) symmetric
...
cvx_end

If n does not have a numerical value, it will not work in CVX. You can’t formulate a CVX problem in terms of a generic “unfixed” n. If you want to solve the problem for several different values of n, CVX will have to be invoked separately for each value.

For instance, you can do

for n = 1:10
   cvx_begin
    variable X(n,n) symmetric
    ...
    cvx_end
end
(feifan) #3

Thanks for replying. My expression is unclear. ‘n’ is not related to the dimension of ‘x’, I want to define ‘n’ variable matrix which have same dimension and are symmetric.
For instance
n = 3;
cvx_begin
variable X(k*n,n)

cvx_end

What I want is to define ‘k’ variable symmetric matrix ‘X(n,n)’, and ‘k’ is a unfixed number, how to define?

(Mark L. Stone) #4

variable X(n,n,k) symmetric
declares a 3D array X, for which the 2D slices X(:,:,j) are symmetric n by n matrices, for each value of j from 1 to k. n and k must have numerical values at the time the variable declaration is made. This can’t be done with unfixed values of n or k at the time of declaration.

(feifan) #5

Thanks. It is useful for me.

(feifan) #6

I have another question. Due to my constraints are unreasonable, the status of cvx may be infeasible or failed, it is normal for me, because I need to adjust the constraints. Is there special identifier to show the status of cvx.

(Mark L. Stone) #7

Is cvx_status http://cvxr.com/cvx/doc/solver.html#interpreting-the-results what you are looking for?

(feifan) #8

Thanks. My algorithm is bisection method. The constraint is my optimal goal, so the cvx_status may be not ‘Solved’.

(feifan) #9

My original optimization problem is non-convex SDP, and I use Taylor series approximation method to solve the problem.So the some original values of variables are random, and the status of cvx may be not ‘Solved’. And the constraints of my optimization problem contain the trace of matrix. So I don’t know the reason of not ‘Solved’ status is my error original values or the limitation of cvx. Is CVXQUAD helpful for my problem?

(Mark L. Stone) #10

If you show your complete program and the solver and CVX output from running it on a not Solved example, perhaps specific advice can be offered.

(feifan) #11

W_old = Iteration_old.W_old;
beta_old = Iteration_old.beta_old;
eta_old = Iteration_old.eta_old;
delta_old = Iteration_old.delta_old;
rho_old = Iteration_old.rho_old;

Num_UE = size(CSI_Matrix_RF,1);
Num_UE_RF = Num_UE;
Num_UE_VLC = size(CSI_Matrix_VLC,1);
Num_antenna_VLC = size(CSI_Matrix_VLC,2);
Num_antenna_RF = size(CSI_Matrix_RF,2);

cvx_begin sdp
variable t nonnegative
variable W(Num_antenna_VLC,Num_antenna_VLC,Num_UE_VLC) symmetric%VLC
variable V(Num_antenna_RF,Num_antenna_RF,Num_UE_RF) symmetric%RF
variable alpha_iteration(Num_UE_VLC,1) %VLC
variable beta_iteration(Num_UE_VLC,1)%VLC
variable gamma_iteration(Num_UE_RF,1)%RF
variable eta_iteration(Num_UE_RF,1)%RF
variable delta_iteration(Num_UE_VLC,1)%VLC
variable rho_iteration(Num_UE_RF,1)%RF
variable r_VLC(Num_UE_VLC,1) nonnegative
variable r_RF(Num_UE_RF,1) nonnegative

maximize t
subject to
    power_consumption = 0;
    for num_ue_VLC = 1:Num_UE_VLC
        power_consumption = power_consumption + trace( W(:,:,num_ue_VLC) ); 
    end
    for num_ue_RF = 1:Num_UE_RF
        power_consumption = power_consumption + trace( V(:,:,num_ue_VLC) ); 
    end
    power_consumption <= Power_max;
    
    for num_ue_VLC = 1:Num_UE_VLC
       exp(alpha_iteration(num_ue_VLC)) - 2*trace(   W(:,:,num_ue_VLC)*(CSI_Matrix_VLC(num_ue_VLC,:)'*CSI_Matrix_VLC(num_ue_VLC,:))  ) <= 0; 
    end
    for num_ue_VLC = 1:Num_UE_VLC
        W(:,:,num_ue_VLC) >= 0;
    end
    clear num_ue_VLC
    
    for num_ue_RF = 1:Num_UE_RF
       exp(gamma_iteration(num_ue_RF)) - 2*trace(   V(:,:,num_ue_RF)*(CSI_Matrix_RF(num_ue_RF,:)'*CSI_Matrix_RF(num_ue_RF,:))  ) <= 0; 
    end    
    for num_ue_RF = 1:Num_UE_RF
       V(:,:,num_ue_RF) >=  0; 
    end         
    
    for num_ue_VLC = 1:Num_UE_VLC
        if Num_UE_VLC == num_ue_VLC
            pi*exp(1)*sigma_square_VLC - exp(beta_old(num_ue_VLC))*(1 + beta_iteration(num_ue_VLC) - beta_old(num_ue_VLC)) <= 0;
        else
            temp = 0;
            for num_ue_VLC_ = num_ue_VLC+1:Num_UE_VLC
                temp = temp + trace( W(:,:,num_ue_VLC_)*(CSI_Matrix_VLC(num_ue_VLC,:)'*CSI_Matrix_VLC(num_ue_VLC,:)) );
            end
            pi*exp(1)*(temp + sigma_square_VLC) - exp(beta_old(num_ue_VLC))*(1 + beta_iteration(num_ue_VLC) - beta_old(num_ue_VLC)) <= 0;
        end
    end
    clear num_ue_VLC
    
    for num_ue_RF = 1:Num_UE_RF
        if Num_UE_RF == num_ue_RF
            sigma_square_RF - exp(eta_old(num_ue_RF))*(1 + eta_iteration(num_ue_RF) - eta_old(num_ue_RF)) <= 0;
        else
            temp = 0;
            for num_ue_RF_ = num_ue_RF+1:Num_UE_RF
                temp = temp + trace( V(:,:,num_ue_RF_)*(CSI_Matrix_RF(num_ue_RF,:)'*CSI_Matrix_RF(num_ue_RF,:)) );
            end
            (temp + sigma_square_RF) - exp(eta_old(num_ue_RF))*(1 + eta_iteration(num_ue_RF) - eta_old(num_ue_RF)) <= 0;
        end
    end        
    
    for num_ue_VLC = 1:Num_UE_VLC
         delta_iteration(num_ue_VLC)== ( alpha_iteration(num_ue_VLC) - beta_iteration(num_ue_VLC) );
    end
    clear num_ue_VLC;
    
    for num_ue_RF = 1:Num_UE_RF
       rho_iteration(num_ue_RF) == ( gamma_iteration(num_ue_RF) - eta_iteration(num_ue_RF) );      
    end
    
    for num_ue_VLC = 1:Num_UE_VLC
      r_VLC(num_ue_VLC) -  B_VLC/2*(1/log(2))*( log(1 + exp(delta_old(num_ue_VLC))) +...
                        ( exp(delta_old(num_ue_VLC))/(1 +exp(delta_old(num_ue_VLC)) ) )*(delta_iteration(num_ue_VLC) - delta_old(num_ue_VLC))) <= 0; 
    end
    clear num_ue_VLC
    
    for num_ue_RF = 1:Num_UE_RF
      r_RF(num_ue_RF) -  B_RF*(1/log(2))*( log(1 + exp(rho_old(num_ue_RF))) +...
                        ( exp(rho_old(num_ue_RF))/(1 +exp(rho_old(num_ue_RF)) ) )*(rho_iteration(num_ue_RF) - rho_old(num_ue_RF))) <= 0; 
    end        
    
    for num_ue = 1:Num_UE
        multiple_VLC = (Index_UE_corresponding_relation(num_ue,3) ~= 0);
        index_VLC =  Index_UE_corresponding_relation(num_ue,3);
        index_RF =  Index_UE_corresponding_relation(num_ue,2);
        if 0 == multiple_VLC 
           r_RF(index_RF) >= t;
        else
           r_RF(index_RF) + r_VLC(index_VLC) >= t;
        end
    end

cvx_end

Successive approximation method to be employed.
SDPT3 will be called several times to refine the solution.
Original size: 90 variables, 26 equality constraints
7 exponentials add 56 variables, 35 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
7/ 7 | 8.000e+00 8.392e+00 0.000e+00 | Solved
4/ 4 | 5.914e+00 1.879e+00 0.000e+00 | Failed
1/ 1 | 1.068e+00 4.861e-02 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Failed

Status: Failed
Optimal value (cvx_optval): NaN

The above is my code and the output of CVX in a optimization process.

(Mark L. Stone) #12

Following the advice in this link might help. CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions

Also (whether with or without CVXQUAD), use of Mosek rather than SDPT3 might help. The nest chance of success will be with using both CVXQUAD and Mosek.

I have no idea what the scaling is in your problem, but bad scaling can contribute to difficulties in solving. And no matter what else you do, good scaling is a good thing to have.

(feifan) #13

Thanks. I’ll try them.

(feifan) #14

I use MOSEK as solver, it’s helpful for my question.But it sometimes shows bug information

not define function or variable ‘last_act’。

wrong in cvxprob/solve (line 348)
if ~found && last_solved == solved &&
last_act == nact,

wrong in cvx_end (line 88)
solve( prob );

Because my language is not english, it is the version of my translation. And what is the reason of this bug?

Furthermore,I have read the introduction of CVXQUAD, and have sveral question. To my understanding, I just need add the master file to my Matlab path and copy the file “exponential/exponential.m” to replace the method of successive approximation, then will CVX use the new method to deal my optimization problem? Is the special functions of CVXQUAD optional? Must I use the special functions if I want to use CVXQUAD?

(Mark L. Stone) #15

I don’t know what the cause of that bug is.

For CVXQUAD:

  1. Install CVXQUAD and its exponential.m replacement.
  2. Some problems require reformulation in order for CVXQUAD’s pade apprcximant method to be used instead of CVX"s successive approximation method, The link I provided has the details on what, if any, reformulation is needed.

I haven’t looked very carefully at your problem. Either you need to reformulate exp(cvx_expression) per the link. Or if it turns out you can reformulate all instances as 'exp(cvx_expression) <= constant, then you can change that to cvx_expression <= log(constant) and avoid the need for CVX’s successive approximation method or CVXQUAD.

(feifan) #16

OK.Thanks for your advice.

(feifan) #17

After I change the solver to MOSEK, it is really helpful my problem, bu why my previous right cods is ‘Unbounded’, which show ‘Solved’ before. It always show ‘Unbounded’ even I reinstall matlab and cvx.

(Mark L. Stone) #18

Please state more clearly what results you got in what configuration, and what your question is.

(feifan) #19

My code is as:

cvx_begin 
    variable w(Num_UE,1)
    minimize sum(exp(w)) % minimize the power consumption of all UE
    subject to
        %sum(exp(w/2)) <= D;% ensure the LED work in the line range
        % QoS constraint
        for num_UE = 1:Num_UE
            if Num_UE == num_UE
                SINR_QoS(num_UE)*N0*exp(-w(num_UE)) <= H_channel(num_UE)^2;
            else
               temp = w(num_UE+1:end);
               temp = temp - w(num_UE);
               SINR_QoS(num_UE)*H_channel(num_UE)^2*sum(exp(temp)) + SINR_QoS(num_UE)*N0*exp(-w(num_UE)) <= H_channel(num_UE)^2;
            end
        end
cvx_end

Successive approximation method to be employed.
For improved efficiency, Mosek is solving the dual problem.
Mosek will be called several times to refine the solution.
Original size: 59 variables, 27 equality constraints
16 exponentials add 112 variables, 64 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
3/ 3 | 8.000e+00 1.173e+01 0.000e+00 | Unbounded
3/ 3 | 8.000e+00s 3.209e+00 0.000e+00 | Unbounded
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Unbounded

Status: Infeasible
Optimal value (cvx_optval): +Inf

I am sure it have a solver result before. But it is ‘Unbounded’, why?

(Mark L. Stone) #20

CVX is claiming the problem is infeasible (I believe unbounded pertains to the dual problem which is being solved).

I advise you to install CVXQUAD and follow the reformulation instructions as mentioned in my reply before my previous reply. When you have done so, you should not see any

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status

output.