|
Hi,
The following code shows that the function to be optimized was called 121 times. But fmincon's output says funcCount = 11. I think that funcCount means the number of times the objective function is called. Is it so? Why there is a discrepancy here?
~/linux/test/octave/matlab/lang/function/fmincon/lb/illcondquad_func_count$ ./main.sh
~/linux/test/octave/matlab/lang/function/fmincon/lb/illcondquad_func_count$ wc -l illcondquad.txt
121 illcondquad.txt
~/linux/test/octave/matlab/lang/function/fmincon/lb/illcondquad_func_count$ cat.sh illcondquad.m main.m main.sh output.txt
==> illcondquad.m <==
function fg=illcondquad(n)
A=rand(n, n);
%A=eye(n);
A=(A+A')/2;
[v lambda]=eig(A);
lam=2.^(1:n);
A=v * diag(lam) * v';
%A=eye(n)
function [f g]=fg1(x)
myfile=fopen('illcondquad.txt', 'a');
fprintf(myfile, 'illcondquad: %s\n', num2str(x'));
f=x' * A * x;
g=2 * A * x;
end
fg=@fg1;
end
==> main.m <==
%#!/usr/bin/env bash
%shopt -s lastpipe; tail -n +3 "$0" | exec /usr/bin/env mlb.sh
rand('seed', 0)
n=10;
A = [];
b = [];
Aeq = [];
beq = [];
lb=datasample([-1 1], n)';
ub=repmat(Inf, n, 1);
nonlcon=[];
options=optimset('GradObj', 'on');
x0=exprnd(1, n, 1) + lb;
myfunill=illcondquad(n);
[x, fval, exitflag, output, lambda, grad, hessian] = fmincon(myfunill, x0, A, b, Aeq, beq, lb, ub, nonlcon, options)
==> main.sh <==
#!/usr/bin/env bash
rm -rf illcondquad.txt
mlb.sh main.m > output.txt
==> output.txt <==
Local minimum possible.
fmincon stopped because the final change in function value relative to
its initial value is less than the default value of the function tolerance.
x =
-1.0000
-1.0000
1.0000
1.0000
1.0000
-0.1099
1.0000
1.0000
0.0172
-1.0000
fval =
984.1129
exitflag =
3
output =
iterations: 10
funcCount: 11
cgiterations: 22
firstorderopt: 0.0185
algorithm: 'trust-region-reflective'
message: [1x471 char]
constrviolation: 0
lambda =
lower: [10x1 double]
upper: [10x1 double]
ineqlin: []
eqlin: []
ineqnonlin: []
eqnonlin: []
grad =
1.0e+03 *
0.0795
0.6761
1.0113
0.5743
0.1265
-0.0000
0.5756
0.5332
0.0000
0.0970
hessian =
(1,1) 451.2280
(2,1) 31.8247
(3,1) 103.6172
(4,1) 164.7138
(5,1) 231.2332
(6,1) 263.5440
(7,1) 188.1010
(8,1) 152.5811
(9,1) 119.6538
(10,1) 250.7486
(1,2) 31.8247
(2,2) 441.2794
(3,2) 337.7628
(4,2) 293.7881
(5,2) 123.9783
(6,2) 145.3209
(7,2) 293.9171
(8,2) 216.5754
(9,2) 263.9140
(10,2) 105.3319
(1,3) 103.6172
(2,3) 337.7628
(3,3) 647.1246
(4,3) 271.0592
(5,3) 27.1238
(6,3) -15.3438
(7,3) 293.9432
(8,3) 281.7906
(9,3) -102.1304
(10,3) 68.2905
(1,4) 164.7138
(2,4) 293.7881
(3,4) 271.0592
(4,4) 451.1535
(5,4) 168.3756
(6,4) 269.2394
(7,4) 256.1507
(8,4) 150.6301
(9,4) 173.3424
(10,4) 237.9292
(1,5) 231.2332
(2,5) 123.9783
(3,5) 27.1238
(4,5) 168.3756
(5,5) 225.6586
(6,5) 265.3401
(7,5) 162.2246
(8,5) 97.2748
(9,5) 277.1988
(10,5) 174.5485
(1,6) 263.5440
(2,6) 145.3209
(3,6) -15.3438
(4,6) 269.2394
(5,6) 265.3401
(6,6) 489.3641
(7,6) 116.8861
(8,6) 66.3989
(9,6) 382.6284
(10,6) 246.4503
(1,7) 188.1010
(2,7) 293.9171
(3,7) 293.9432
(4,7) 256.1507
(5,7) 162.2246
(6,7) 116.8861
(7,7) 308.9009
(8,7) 203.5620
(9,7) 176.1976
(10,7) 157.3754
(1,8) 152.5811
(2,8) 216.5754
(3,8) 281.7906
(4,8) 150.6301
(5,8) 97.2748
(6,8) 66.3989
(7,8) 203.5620
(8,8) 243.5427
(9,8) 63.5783
(10,8) 68.2036
(1,9) 119.6538
(2,9) 263.9140
(3,9) -102.1304
(4,9) 173.3424
(5,9) 277.1988
(6,9) 382.6284
(7,9) 176.1976
(8,9) 63.5783
(9,9) 604.6164
(10,9) 172.9282
(1,10) 250.7486
(2,10) 105.3319
(3,10) 68.2905
(4,10) 237.9292
(5,10) 174.5485
(6,10) 246.4503
(7,10) 157.3754
(8,10) 68.2036
(9,10) 172.9282
(10,10) 229.1317
|