the uncertain wrong of minimizing
Posted: Sun Aug 13, 2023 6:03 am
Hello,everyone! I have a question that I am trying to balance the SAM table using the cross entropy method, but the corresponding command cannot achieve the minimization of the objective function Z, but I really can't find out where the problem is.
This is the command.
*********************
set ac /sec1,sec2,lab,hh,total/;
set i(ac) /sec1,sec2,lab,hh/;
alias (ac,acp);
alias (i,j);
table sam(*,*)
sec1 sec2 lab hh total
sec1 52 45 150 247
sec2 95 48 90 233
lab 120 89 209
hh 192 192
total 267 182 192 240
;
parameters
Q0(i,j) initial value of SAM
H0 sum of all transaction flows ;
*Assignment for parameters
Q0(i,j)=sam(i,j);
H0=sum((i,j),sam(i,j));
display H0,sam;
Variables
Q(i,j) the target values of SAM
H the adjust sum of all transaction flows(total)
Hratio the ratio of Initial and adjusted total
z Expected entropy value;
*nonneg values must be non-negative
Positive variable Q(i,j);
equations
totalsum adjusted total
directentropy objective function
balance Balancing restrictions for each account
Hratiodef the ratio of Initial and adjusted total;
totalsum.. H =e= sum((i,j),Q(i,j));
Hratiodef.. Hratio =e= H/H0;
directentropy.. z=e=sum((i,j)$sam(i,j),(1/H)*Q(i,j)*log(Q(i,j)/sam(i,j)))-log(Hratio);
balance(i).. sum(j$sam(i,j),Q(i,j)) =e= sum(j,Q(j,i));
*Assign values to the initial values of variables.
*There are special limitations on the scope of Hratio here. Because without limitation, when the objective function is minimized,
*H will tend towards infinity, and the true result cannot be obtained
Q.l(i,j)=Q0(i,j);
H.l=H0;
Hratio.lo=0.5;
Hratio.up=2.0;
model sambal /all/;
solve sambal using dnlp minimizing z;
display Q.l,z.l,H.l,H0,Hratio.l;
*end
**********************
This is the corresponding result.
“Hratio.lo=0.5;
Hratio.up=2.0”
‘balance(i).. sum(j$sam(i,j),Q(i,j)) =e= sum(j,Q(j,i));
’
---- 60 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 96.000 119.000
sec2 95.000 48.000 90.000
lab 120.000 89.000
hh 209.000
---- 60 VARIABLE z.L = 0.754 Expected entropy value
VARIABLE H.L = 866.000 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.983 the ratio of Initial and adjusted total
“ Hratio.fx=0.984”
---- 59 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 51.515 52.535 140.353
sec2 79.862 47.552 71.460
lab 113.026 98.787
hh 2.96948E-19 211.813
---- 59 VARIABLE z.L = 0.007 Expected entropy value
VARIABLE H.L = 866.904 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.984 the ratio of Initial and adjusted total
It can be seen that when the Hratio ratio is between 0.5 and 2, a program value of 0.983 cannot achieve the minimum z. As I fx it 0.984,the Z is 0.007,much less than 0.983, and the 0.984 is also not the real solution.
And there is a weird thing that in logical, whither I add the ' $sam(i,j)' of the definition 'balance(i).. ' will not influence the result as that all Q(i,j) is positive, but the result shows that if I delete this, the Z is ZERO, but the table is totally not changed.
“balance(i).. sum(j ,Q(i,j)) =e= sum(j,Q(j,i));”
---- 60 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 96.000 119.000
sec2 95.000 48.000 90.000
lab 120.000 89.000
hh 209.000
---- 60 VARIABLE z.L = 0.000 Expected entropy value
VARIABLE H.L = 866.000 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.983 the ratio of Initial and adjusted total
Thanks a lot
This is the command.
*********************
set ac /sec1,sec2,lab,hh,total/;
set i(ac) /sec1,sec2,lab,hh/;
alias (ac,acp);
alias (i,j);
table sam(*,*)
sec1 sec2 lab hh total
sec1 52 45 150 247
sec2 95 48 90 233
lab 120 89 209
hh 192 192
total 267 182 192 240
;
parameters
Q0(i,j) initial value of SAM
H0 sum of all transaction flows ;
*Assignment for parameters
Q0(i,j)=sam(i,j);
H0=sum((i,j),sam(i,j));
display H0,sam;
Variables
Q(i,j) the target values of SAM
H the adjust sum of all transaction flows(total)
Hratio the ratio of Initial and adjusted total
z Expected entropy value;
*nonneg values must be non-negative
Positive variable Q(i,j);
equations
totalsum adjusted total
directentropy objective function
balance Balancing restrictions for each account
Hratiodef the ratio of Initial and adjusted total;
totalsum.. H =e= sum((i,j),Q(i,j));
Hratiodef.. Hratio =e= H/H0;
directentropy.. z=e=sum((i,j)$sam(i,j),(1/H)*Q(i,j)*log(Q(i,j)/sam(i,j)))-log(Hratio);
balance(i).. sum(j$sam(i,j),Q(i,j)) =e= sum(j,Q(j,i));
*Assign values to the initial values of variables.
*There are special limitations on the scope of Hratio here. Because without limitation, when the objective function is minimized,
*H will tend towards infinity, and the true result cannot be obtained
Q.l(i,j)=Q0(i,j);
H.l=H0;
Hratio.lo=0.5;
Hratio.up=2.0;
model sambal /all/;
solve sambal using dnlp minimizing z;
display Q.l,z.l,H.l,H0,Hratio.l;
*end
**********************
This is the corresponding result.
“Hratio.lo=0.5;
Hratio.up=2.0”
‘balance(i).. sum(j$sam(i,j),Q(i,j)) =e= sum(j,Q(j,i));
’
---- 60 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 96.000 119.000
sec2 95.000 48.000 90.000
lab 120.000 89.000
hh 209.000
---- 60 VARIABLE z.L = 0.754 Expected entropy value
VARIABLE H.L = 866.000 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.983 the ratio of Initial and adjusted total
“ Hratio.fx=0.984”
---- 59 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 51.515 52.535 140.353
sec2 79.862 47.552 71.460
lab 113.026 98.787
hh 2.96948E-19 211.813
---- 59 VARIABLE z.L = 0.007 Expected entropy value
VARIABLE H.L = 866.904 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.984 the ratio of Initial and adjusted total
It can be seen that when the Hratio ratio is between 0.5 and 2, a program value of 0.983 cannot achieve the minimum z. As I fx it 0.984,the Z is 0.007,much less than 0.983, and the 0.984 is also not the real solution.
And there is a weird thing that in logical, whither I add the ' $sam(i,j)' of the definition 'balance(i).. ' will not influence the result as that all Q(i,j) is positive, but the result shows that if I delete this, the Z is ZERO, but the table is totally not changed.
“balance(i).. sum(j ,Q(i,j)) =e= sum(j,Q(j,i));”
---- 60 VARIABLE Q.L the target values of SAM
sec1 sec2 lab hh
sec1 96.000 119.000
sec2 95.000 48.000 90.000
lab 120.000 89.000
hh 209.000
---- 60 VARIABLE z.L = 0.000 Expected entropy value
VARIABLE H.L = 866.000 the adjust sum of all transaction flows(total)
PARAMETER H0 = 881.000 sum of all transaction flows
VARIABLE Hratio.L = 0.983 the ratio of Initial and adjusted total
Thanks a lot