CVX return NaN in most runs,and sometimes it works


#1

Dear all,
I have tried to solve the following convex optimization problem but it always returned NaN. And when the Channel was set 1, it may worked sometimes.
image

clc
clear
global UserL;
UserL=zeros(7,2);
Station=7;
Channel=2;
Radius=500;
max_iteration=10;
K1=1.1120;
K2=4.6746;
FSn=320;%page size;
sigma=1e-8;%awgn
bn=FSn/exp(K2/K1);%const
PowerAllocation=zeros(Station,Channel,max_iteration);%recorder power allocation in each iteration
CGain=ChannelGain(Station,Channel,Radius); %ChannelGain(j,m,n) from j station to m user in n station;
tRecorder=zeros(1,max_iteration);
Bandwidth=1000/Channel; %kHZ
StationPowerLimit=20;
MOSRecorder=zeros(7,max_iteration);
%initialization%
PowerAllocation(:,:,1)= StationPowerLimit/Channel*ones(Station,Channel);
for i=1:Station
    MOSRecorder(i,1)=-K1*log(FSn/(sum(Bandwidth*log2(1+(CGain(i,:,i).*PowerAllocation(i,:,1))./(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,1),1))),2)))+K2;
end
%DC Programing%
for iteration=2:max_iteration
    cvx_begin 
    variables PA(Station,Channel) t;
    maximize t
    subject to
    for i=1:Station
        
            A=0;B=0;
        for j=1:Channel
            A1=0;B1=0;C1=0;
            for k=1:Station
                A1=CGain(k,j,i)*PA(k,j);
                B1=CGain(k,j,i)*PA(k,j);
                C1=CGain(k,j,i)*PowerAllocation(k,j,iteration-1);
            end
            A=A+log(sigma+A1)/log(2);
            B=B+(B1-CGain(i,j,i)*PA(i,j))/(sigma+C1-CGain(i,j,i)*PowerAllocation(i,j,iteration-1));
        end
        c=-Bandwidth*sum((sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))./(sigma+(sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))))...
                    +Bandwidth*sum(log(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))/log(2),2)+bn/K1*exp(tRecorder(iteration-1)/K1)*tRecorder(iteration-1)-bn*exp(tRecorder(iteration-1)/K1);
        -A+2*bn*exp(t/K1)+B-bn/K1*exp(tRecorder(iteration-1)/K1)*t+c<=0;
        sum(PA(i,:))<=StationPowerLimit;
    end
    PA>=0
    cvx_end
    PowerAllocation(:,:,iteration)=PA;
    tRecorder(iteration)=t;
    for i=1:Station
        MOSRecorder(i,iteration)=-K1*log(FSn/(sum(Bandwidth*log2(1+(CGain(i,:,i).*PowerAllocation(i,:,iteration))./(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,iteration),1))),2)))+K2;
    end
end
MINMOS=min(MOSRecorder);

function CGain=ChannelGain(Station,Channel,Radius)
    global UserL;
    CGain=zeros(Station,Channel,Station);
    C1=cos(pi/3);C2=sin(pi/2);
    StationLocation=[0,0;2*Radius*C1,2*Radius*C2;2*Radius,0;2*Radius*C1,-2*Radius*C2;-2*Radius*C1,-2*Radius*C2;-2*Radius,0;-2*Radius*C1,2*Radius*C2];
    hold on
    plot(StationLocation(:,1),StationLocation(:,2),'O');


for i=1:Station
    UserLocationRadius=(sqrt(rand)/2+0.5)*Radius;
    UserLocationTheta=rand*2*pi;
    UserLocation=[StationLocation(i,1)+UserLocationRadius*cos(UserLocationTheta),StationLocation(i,2)+UserLocationRadius*sin(UserLocationTheta)];
    UserL(i,1)=UserLocation(1);UserL(i,2)=UserLocation(2);               %储存用户的位置;
    for j=1:Station
        CGain(j,:,i)=repmat(1/(sqrt((UserLocation(1)-StationLocation(j,1))^2+(UserLocation(2)-StationLocation(j,2))^2))^3,1,Channel);
    end
    
end
    plot(UserL(:,1),UserL(:,2),'*');
    hold off;
end

I do not know why the program can’t run successfully? Please help me to check this problem.

Thanks.


(Mark L. Stone) #2

Follow the instructions to use CVXQUAD 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

I can not try to solve your problem because you have not provided all the inputs to make it reproducible. Please let us know what happens when you use CVXQUAD.


#3

The program ran successfully after using CVXQUAD. Thanks for your help!!!


#4

Hi,Mark, sorry to bother you again!
The program ran successfully , but there was something wrong with the return value. I’ve checked the the model expression and I’m sure it is right.
The variable has two parts. One part is power allocation, another part is a value called t. It can compute a value called MINMOS through power allocation, and the variable t is a value less than or equal to MINMOS. The object is to maximize t. But the computed value MINMOS is very different from the t. I don’t know if the error is caused by Pade approximation. And how can i fix it?
The program have no inputs, all the parameters are randomly generated and there are two .m file.
This is the main function:

clc
clear
global UserL;
UserL=zeros(7,2);
Station=7;
Channel=10;
Radius=500;
max_iteration=10;
K1=1.1120;
K2=4.6746;
FSn=320;%page size;
sigma=1e-7;%awgn
bn=FSn/exp(K2/K1);%const
PowerAllocation=zeros(Station,Channel,max_iteration);%recorder power allocation in each iteration
CGain=ChannelGain(Station,Channel,Radius); %ChannelGain(j,m,n) from j station to m user in n station;
tRecorder=zeros(1,max_iteration);
Bandwidth=1000/Channel; %kHZ
StationPowerLimit=20;
MOSRecorder=zeros(7,max_iteration);
%initialization%
PowerAllocation(:,:,1)= StationPowerLimit/Channel*ones(Station,Channel);
for i=1:Station
    MOSRecorder(i,1)=-K1*log(FSn/(sum(Bandwidth*log2(1+(CGain(i,:,i).*PowerAllocation(i,:,1))./(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,1),1)-CGain(i,:,i).*PowerAllocation(i,:,1))),2)))+K2;
end
tRecorder(1)=min(MOSRecorder(:,1));
%DC Programing%
for iteration=2:max_iteration
    cvx_begin
    cvx_solver sedumi
    %     veriables PA(Station,Channel) t;
    variables PA(Station,Channel) t z; %cvxquad additional variable
    maximize t
    subject to
    for i=1:Station
        c=-Bandwidth*sum((sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))./(sigma+(sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))))...
            +Bandwidth*sum(log(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1))./log(2),2);
        -Bandwidth*sum(-rel_entr(1,sigma+sum(CGain(:,:,i).*PA(:,:),1))./log(2),2)+bn*z...
            +Bandwidth*sum((sum(CGain(:,:,i).*PA(:,:),1)-CGain(i,:,i).*PA(i,:))./(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,iteration-1),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration-1)),2)+c<=0;
        t/K1 + rel_entr(1,z) <= 0;
        sum(PA(i,:))<=StationPowerLimit;
    end
    PA>=0;
    cvx_end
    PowerAllocation(:,:,iteration)=PA;
    tRecorder(iteration)=t;
    for i=1:Station
        MOSRecorder(i,iteration)=-K1*log(FSn/(sum(Bandwidth*log2(1+(CGain(i,:,i).*PowerAllocation(i,:,iteration))./(sigma+sum(CGain(:,:,i).*PowerAllocation(:,:,iteration),1)-CGain(i,:,i).*PowerAllocation(i,:,iteration))),2)))+K2;
    end
    MINMOS(iteration)=min(MOSRecorder(:,iteration));
end

This is the custom function:

function CGain=ChannelGain(Station,Channel,Radius)
    global UserL;
    CGain=zeros(Station,Channel,Station);
    C1=cos(pi/3);C2=sin(pi/2);
    StationLocation=[0,0;2*Radius*C1,2*Radius*C2;2*Radius,0;2*Radius*C1,-2*Radius*C2;-2*Radius*C1,-2*Radius*C2;-2*Radius,0;-2*Radius*C1,2*Radius*C2];
    hold on
    plot(StationLocation(:,1),StationLocation(:,2),'O');

for i=1:Station
    UserLocationRadius=(sqrt(rand)/2+0.5)*Radius;
    UserLocationTheta=rand*2*pi;
    UserLocation=[StationLocation(i,1)+UserLocationRadius*cos(UserLocationTheta),StationLocation(i,2)+UserLocationRadius*sin(UserLocationTheta)];
    UserL(i,1)=UserLocation(1);UserL(i,2)=UserLocation(2);               %储存用户的位置;
    for j=1:Station
        CGain(j,:,i)=repmat(1/(sqrt((UserLocation(1)-StationLocation(j,1))^2+(UserLocation(2)-StationLocation(j,2))^2))^3,1,Channel);
    end
    
end
    plot(UserL(:,1),UserL(:,2),'*');
    hold off;
end

(Mark L. Stone) #5

Please choose the simplest problem (smallest dimensions and numbers of everything) which demonstrates your issue. Then show all CVX and solver output, together with whatever MATLAB calculations you have made which demonstrate the issue, and explain why the calculations demonstrate the issue.

In doing so, presume that the reader has no understanding of the real-world problem your optimization model pertains to. Show why the solution obtained from CVX does not solve the model you provided to CVX. Keep in min that this is not a modeling forum. It is your responsibility to formulate a mathematical optimization problem for your real world problem of interest. Readers on this forum might help you with any mathematically equivalent reformulations or solution difficulties you might encounter trying to enter and solve your model using CVX.