# What's wrong with my CVX?

(zy) #1

Hi, I want to use CVX to solve this problem:

The first and second constraints are SOCP constraints. My Matlab codes are as follow:

But I met some problems. When the CVX told me that P3 was solved, I verified the first and the second constraints in P3. But it is wrong. In my code I let sb1_left(j,k) - sb1_right(j,k) <= 0 for any j and k, but I found sometimes sb1_left(j,k) - sb1_right(j,k) >=0. It was not satisfied my constraints, but CVX solved my problem. What is the reason for this? Can anyone help me? Thank you all. Next is my experiment information

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 7.45539059e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.80e-05 relative gap = 2.80e-05 actual relative gap = 7.46e-07 rel. primal infeas (scaled problem) = 1.96e-09 rel. dual " " " = 2.30e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.5e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.23 CPU time per iteration = 0.01 termination code = 0 DIMACS: 2.0e-09 0.0e+00 4.8e-07 0.0e+00 7.5e-07 2.8e-05

Status: Solved
Optimal value (cvx_optval): -7.45539e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 5.15329210e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.90e-05 relative gap = 2.90e-05 actual relative gap = 5.15e-07 rel. primal infeas (scaled problem) = 1.10e-09 rel. dual " " " = 2.30e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.7e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.17 CPU time per iteration = 0.01 termination code = 0 DIMACS: 1.1e-09 0.0e+00 4.8e-07 0.0e+00 5.2e-07 2.9e-05

Status: Solved
Optimal value (cvx_optval): -5.15329e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 3.67839092e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.94e-05 relative gap = 2.94e-05 actual relative gap = 3.68e-07 rel. primal infeas (scaled problem) = 5.81e-10 rel. dual " " " = 2.29e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.8e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.20 CPU time per iteration = 0.01 termination code = 0 DIMACS: 5.8e-10 0.0e+00 4.8e-07 0.0e+00 3.7e-07 2.9e-05

Status: Solved
Optimal value (cvx_optval): -3.67839e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 2.85694845e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.97e-05 relative gap = 2.97e-05 actual relative gap = 2.86e-07 rel. primal infeas (scaled problem) = 3.00e-10 rel. dual " " " = 2.29e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.9e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.15 CPU time per iteration = 0.01 termination code = 0 DIMACS: 3.0e-10 0.0e+00 4.8e-07 0.0e+00 2.9e-07 3.0e-05

Status: Solved
Optimal value (cvx_optval): -2.85695e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 2.49301690e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.97e-05 relative gap = 2.97e-05 actual relative gap = 2.49e-07 rel. primal infeas (scaled problem) = 1.56e-10 rel. dual " " " = 2.29e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.9e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.18 CPU time per iteration = 0.01 termination code = 0 DIMACS: 1.6e-10 0.0e+00 4.8e-07 0.0e+00 2.5e-07 3.0e-05

Status: Solved
Optimal value (cvx_optval): -2.49302e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 residual of dual infeasibility certificate X = -3.29e-04 reldist to infeas. <= 6.33e-15 Total CPU time (secs) = 0.15 CPU time per iteration = 0.01 termination code = 2 DIMACS: 1.2e-10 0.0e+00 4.8e-07 0.0e+00 2.4e-07 3.0e-05

Status: Infeasible
Optimal value (cvx_optval): +Inf

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 primal objective value = 2.45223245e-07 dual objective value = 0.00000000e+00 gap := trace(XZ) = 2.97e-05 relative gap = 2.97e-05 actual relative gap = 2.45e-07 rel. primal infeas (scaled problem) = 1.38e-10 rel. dual " " " = 2.29e-07 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.9e+02, 2.0e+00, 3.0e+00 norm(A), norm(b), norm© = 2.2e+01, 1.0e+00, 2.7e+00 Total CPU time (secs) = 0.19 CPU time per iteration = 0.01 termination code = 0 DIMACS: 1.4e-10 0.0e+00 4.8e-07 0.0e+00 2.5e-07 3.0e-05

Status: Solved
Optimal value (cvx_optval): -2.45223e-07

## Calling SDPT3 4.0: 786 variables, 192 equality constraints For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 192
dim. of socp var = 624, num. of socp blk = 72
dim. of linear var = 162

SDPT3: Infeasible path-following algorithms

## number of iterations = 20 residual of dual infeasibility certificate X = -3.49e-04 reldist to infeas. <= 6.77e-15 Total CPU time (secs) = 0.20 CPU time per iteration = 0.01 termination code = 2 DIMACS: 1.3e-10 0.0e+00 4.8e-07 0.0e+00 2.4e-07 3.0e-05

Status: Infeasible
Optimal value (cvx_optval): +Inf

and the error_matrix = left - right

(zy) #2

There are 12 users in my experiment. My optimization problem is to make the 9-12 users all have a rate of more than 3.7. The rest of the users are maximizing their minimum values. However, there were times when the results were poor, but CVX told me that there was already a solution.
The following results were obtained when CVX told me that there was a solution

Obviously sometimes the rate is not greater than 3.7

(Mark L. Stone) #3

Your posts are not easy to follow. Your code is nor reproducible (missing input data). It is better to copy and paste your code as text, rather than using an image, and use the “Preformatted text”

In my code I let sb1_left(j,k) - sb1_right(j,k) <= 0 for any j and k, but I found sometimes sb1_left(j,k) - sb1_right(j,k) >=0. It was not satisfied my constraints, but CVX solved my problem.

How big was the violation? Was it by more than solver tolerance?

My optimization problem is to make the 9-12 users all have a rate of more than 3.7. The rest of the users are maximizing their minimum values. However, there were times when the results were poor, but CVX told me that there was already a solution.

I am not following your code. What exactly were these “poor” results, and how are they incompatible with CVX telling you there already was a solution? Is this related to a sequence of CVX instances over the course of the bisection?

(zy) #4

Thanks for your reply. Here is my code:

``````function etaa = Bisection( BETAA,Gammaa,M,J,Kn,N,Pd )
format long
top = 15;
bot = 0;
err = 1e-4;

while abs(top-bot)>err
t=(bot+top)/2;
%% --------------------------------------------------------------CVX
cvx_begin
variable V(M)
variable cauy(M,J)
sb1_left =  cvx(zeros(J,Kn));
sb1_right = cvx(zeros(J,Kn));
%%-----------------------------subject 1 left
for j=1:J
for k=1:Kn
vk1 = ( (1/(N^0.5) ) .* (BETAA(:,j,k).^0.5) .*V(:) ).';
vk2 = 1/( (N*N*Pd)^0.5 );
sb1_left(j,k) = norm([vk1 vk2].');
end
end
%%-----------------------------calculate subject 1 right
for j=1:2
for k=1:Kn
sb1_right(j,k) = sum( (Gammaa(:,j,k).^0.5) .* cauy(:,j)) * (1/(t^0.5));
end
end
for j=3:J
for k=1:Kn
sb1_right(j,k) = sum( (Gammaa(:,j,k).^0.5) .* cauy(:,j)) * (1/(12^0.5));
end
end
%%-----------------------------subject------------------------------
subject to
for j=1:J
for k=1:Kn
sb1_left(j,k) - sb1_right(j,k) <= 0;
end
end

for m=1:M
norm(cauy(m,:)) - V(m) <= 0;
end

for m=1:M
norm(cauy(m,:)) - 1/(N^0.5) <= 0;
end

for m=1:M
for j=1:J
-cauy(m,j) <= 0;
end
end
cvx_end
%% ---------------------------------------------------------------------
s1 = 'Solved';
flag = strcmp(s1,cvx_status);
if flag == 1    %% means solved
bot = t;
Cauy = cauy;
left = sb1_left;
right = sb1_right;
error_matrix = left-right;
else
top = t;
end
end
etaa = Cauy.^2;
end
``````

After calling Bisection, I got the eta matrixtrix and then substituted it into a statement in my main function：

`wp_Ran_R_cf_user = DL_CF_Rate( BETAA,Gammaa,wp_etaa,M,J,Kn,N,Pd );` which corresponds to the next function：

The optimal power control aims to guarantee the last four users’ rates are great than 3.7, and maximize the minimum rate of the rest of user. If the above conditions are not met, the status of CVX should be infeasible （Otherwise, the second constraint will not be established）.
But in my some simulations, it often occurs ‘Poor Results’. The ‘poor result’ means that CVX told me that the problem status is ‘solved’, but the final result (the last four users’ rates) is not greater than 3.7. The pictures I posted on the 2nd floor are the results of several experiments. One of them is ideal. Therefore, I have doubts. Since CVX has said “solved”, why does it not satisfy the constraint?
In my simulations，

``````Kn = 4;
N=4; %number of access points' antenna
M=30; %number of access points
J=3;  % 5group
K = Kn * J;
``````

BETAA is a random matrix whose element varies from 10-6 to 10-11.

(zy) #5

Because the BETAA matrix is generated randomly, the frequency of the ideal result (>3.7) is about 30%. I don’t understand why the result of CVX doesn’t satisfy the constraint, but the status is ‘Solved’. Thank you for your attention

(zy) #6
``````The whole code is follows：
%Downlink
%Consider a rectangular area with DxD m^2
%M distributed APs serves K terminals, they all randomly located in the area

clc;  clear all;
Kn = 4;
N=4; %number of access points' antenna
M=30; %number of access points
J=3;  % 3group
K = Kn * J;
tau_c=200; % coherence intervals

B=20; %Mhz
D=1; %in kilometer
sigma_shd = 8; %in dB

tau = J;

power_f=0.2; %downlink power: 200 mW
noise_p = (B*10^6)*(1.381*10^-23)*290*(10^0.9);
Pd = power_f/noise_p;%nomalized receive SNR
Pp=Pd/2;%pilot power: 100 mW

[U,S,V]=svd(randn(tau,tau));  % U includes tau orthogonal sequences

ITIAL=1;  %这个是迭代次数

% Ran_min_peruser_rate = zeros(ITIAL,1);
Ran_R_cf_user = zeros(J,Kn,ITIAL);
wp_Ran_R_cf_user = zeros(J,Kn,ITIAL);

for itial=1:ITIAL
%% Large_scale_uncorrelation
BETAA_initial = Cellfree_Large_scale_uncorrelation(D,M,K,sigma_shd);
BETAA = reshape(BETAA_initial,M,J,Kn);

%% Create Gamma matrix for uncorrelation shadowing
Gammaa = zeros(M,J,Kn);
for m=1:M
for j=1:J
for k=1:Kn
nominator = tau*Pp*(BETAA(m,j,k)^2);
denominator = 1 + tau*Pp*sum(BETAA(m,j,:));
Gammaa(m,j,k) = nominator / denominator;
end
end
end

%% Each AP has equal power allocations for J groups for uncorrelation shadowing
%%Compute etaa(m):
etaa=zeros(M,J);
for m=1:M
for j=1:J
etaa(m,j)=1/(N*J);
end
end
wp_etaa =  Bisection( BETAA,Gammaa,M,J,Kn,N,Pd  );
%% Compute Rate for Greedy && Random on uncorrelation and EqPower
%%per-user Rate:
Ran_R_cf_user(:,:,itial) = DL_CF_Rate( BETAA,Gammaa,etaa,M,J,Kn,N,Pd );
wp_Ran_R_cf_user(:,:,itial) = DL_CF_Rate( BETAA,Gammaa,wp_etaa,M,J,Kn,N,Pd );
end
% set( cdfplot(Ran_min_peruser_rate(:)), 'Color', 'r');
set( cdfplot(Ran_R_cf_user(:)), 'Color', 'b');
hold on
set( cdfplot(wp_Ran_R_cf_user(:)), 'Color', 'r');``````

(Mark L. Stone) #7

Perhaps it is obvious to you, but it is not obvious to me. Why should all user rates be > 3.7 when CVX has solved a problem? What specifically is the evidence that CVX/solver have incorrectly solved your problem?

You did not answer my previous question as to your finding a violation of sb1_left(j,k) - sb1_right(j,k) <= 0 .

(zy) #8

I am sorry I did not answer your question, the ‘all user rates > 3.7’ is because P2 is equivalent to P3

where Xjk is the vector representation of the denominator of the objective function. Because I let the Rj,given is equal to 3.7, hence, the second constraint can be written as

Hence I say when CVX has solved a problem the last four users’ rates should >3.7
The evidence is when the Bisection function is used, cvx tells me that this problem can be solved.
Just as：

``````Calling SDPT3 4.0: 786 variables, 192 equality constraints
For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

num. of constraints = 192
dim. of socp   var  = 624,   num. of socp blk  = 72
dim. of linear var  = 162
*******************************************************************
SDPT3: Infeasible path-following algorithms
*******************************************************************
version  predcorr  gam  expon  scale_data
NT      1      0.000   1        0
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
0|0.000|0.000|1.5e+02|4.4e+01|2.7e+04| 3.000000e+01  0.000000e+00| 0:0:00| chol  1  1
1|0.238|0.419|1.1e+02|2.6e+01|1.7e+04| 1.186392e+02  0.000000e+00| 0:0:00| chol  1  1
2|0.878|0.846|1.4e+01|4.0e+00|2.8e+03| 2.363348e+02  0.000000e+00| 0:0:00| chol  1  1
3|0.983|0.984|2.3e-01|6.4e-02|2.3e+02| 1.944722e+02  0.000000e+00| 0:0:00| chol  1  1
4|0.981|0.900|4.5e-03|6.5e-03|6.3e+00| 5.650680e+00  0.000000e+00| 0:0:00| chol  1  1
5|0.962|0.776|1.9e-04|1.9e-03|3.7e-01| 2.360570e-01  0.000000e+00| 0:0:00| chol  1  1
6|0.921|0.763|1.3e-04|4.8e-04|5.4e-02| 2.373695e-02  0.000000e+00| 0:0:00| chol  1  1
7|0.977|0.592|1.2e-04|2.1e-04|2.0e-02| 5.529352e-03  0.000000e+00| 0:0:00| chol  1  1
8|1.000|0.746|8.2e-05|5.8e-05|6.6e-03| 2.899332e-03  0.000000e+00| 0:0:00| chol  1  1
9|0.792|0.648|3.3e-05|2.3e-05|2.7e-03| 1.198825e-03  0.000000e+00| 0:0:00| chol  1  1
10|0.845|0.685|5.1e-06|8.5e-06|1.1e-03| 5.054321e-04  0.000000e+00| 0:0:00| chol  1  1
11|0.748|0.714|1.3e-06|3.0e-06|4.4e-04| 2.240097e-04  0.000000e+00| 0:0:00| chol  1  1
12|0.717|0.588|3.6e-07|1.4e-06|2.1e-04| 9.235086e-05  0.000000e+00| 0:0:00| chol  1  1
13|0.564|0.457|1.6e-07|8.6e-07|1.3e-04| 3.074573e-05  0.000000e+00| 0:0:00| chol  1  1
14|0.309|0.303|1.1e-07|6.3e-07|1.1e-04|-2.911411e-06  0.000000e+00| 0:0:00| chol  1  1
15|0.271|0.250|7.9e-08|4.9e-07|1.0e-04|-6.417004e-05  0.000000e+00| 0:0:00| chol  1  1
16|0.317|0.161|5.4e-08|4.2e-07|1.5e-04|-3.494149e-04  0.000000e+00| 0:0:00| chol  1  1
17|0.263|0.155|4.0e-08|3.6e-07|2.7e-04|-2.255937e-03  0.000000e+00| 0:0:00| chol  1  1
18|0.041|0.035|3.8e-08|3.5e-07|9.5e-04|-1.371501e-02  0.000000e+00| 0:0:00|
lack of progress in infeas
-------------------------------------------------------------------
number of iterations   = 18
primal objective value = -6.41700379e-05
dual   objective value =  0.00000000e+00
gap := trace(XZ)       = 1.00e-04
relative gap           = 1.00e-04
actual relative gap    = -6.42e-05
rel. primal infeas (scaled problem)   = 7.95e-08
rel. dual     "        "       "      = 4.93e-07
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual     "        "       "      = 0.00e+00
norm(X), norm(y), norm(Z) = 5.5e+02, 2.8e+00, 4.4e+00
norm(A), norm(b), norm(C) = 2.2e+01, 1.0e+00, 3.7e+00
Total CPU time (secs)  = 0.19
CPU time per iteration = 0.01
termination code       =  0
DIMACS: 7.9e-08  0.0e+00  1.2e-06  0.0e+00  -6.4e-05  1.0e-04
-------------------------------------------------------------------

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

But the users’ rates are

``````|2.49161845244555|2.08158377727123|2.55409426911668|2.69119574278756|
|2.35584608689656|2.53259033075255|2.43784255482793|2.38388110468925|
|3.42336790476673|3.24657130708203|3.21599229947159|3.84482967739608|
``````

The last four users is not all > 3.7. So I think that CVX did not satisfy my second constraint. I don‘t know about the violation. But I stored the data when the status was resolved. The sb_left(j,k) - sb_right(j,k) is

``````|5.63589182329949e-08|4.23387208898495e-08|-4.26740649639895e-08|4.89730799978814e-08|
|5.15363567870340e-08|1.16594590316789e-08|5.03591289160568e-08|4.19410916033776e-08|
|5.35884439326209e-08|5.15602585022491e-08|5.40895019994182e-08|5.57745049268226e-08|
``````

not all <= 0
The solve is SDPT3 and I don’t know the solvers’ tolerance.

(Mark L. Stone) #9

These “violations” are within solver tolerance, and therefore are not considered by the solver, and hence by CVX, to be violations.

I’m afraid I don’t have the energy to get to the bottom of the rates > 3.7 thing. So I leave that to you and/or other forum readers.

(zy) #10

Thanks for your reply. Can you tell me how to modify the tolerance of CVX’s solver?

(Mark L. Stone) #11

http://cvxr.com/cvx/doc/solver.html#controlling-precision although I’m not sure whether cvx_precision affects the feasibility tolerance.

If that doesn’t do what you want, then try http://cvxr.com/cvx/doc/solver.html#advanced-solver-settings . For sdpt3, I think you want to specify
`cvx_solver_settings('inftol',1e-8)`
to change feasibility tolerance to 1e-8, from what I think is its default value (?) of 1e-7. I am not sure exactly what this will do, but you can try it.

You can also try building in a buffer, of for instance, 1e-7, in your statement of the constraint, so that a violation by the solver by that amount will still result in your “real” constraint being strictly satisfied.