-
Notifications
You must be signed in to change notification settings - Fork 4
/
SimplexExitCriteriaMet.m
51 lines (46 loc) · 1.15 KB
/
SimplexExitCriteriaMet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Return true if exit criteria met
%
% seperate from SimplexMinimize.m file since users may want
% to change this criteria. The basic algorithm in SimplexMinimize.m
% should be pretty stable.
%
% aaron birenboim, 11/2015
function a = SimplexExitCriteriaMet(simplex,smallBox,nEvalSinceNewLow,errEps)
% exit when simplex can be bound within a smallBox, and
% it has been several evaluations since we found a better low
n = length(simplex);
a = 0;
if (nEvalSinceNewLow < 2*n)
return;
end
% find err range
hiErr = simplex(1).y;
loErr = hiErr;
for (i=2:n)
if (simplex(i).y < loErr), loErr = simplex(i).y; end
if (simplex(i).y > hiErr), hiErr = simplex(i).y; end
end
if (loErr <= 0)
a=1;
disp('zero error');
simplex(:).p
simplex(:).y
return
end
if ((hiErr-loErr)/loErr < errEps)
a=1;
disp('error pretty flat across simplex');
return;
end
% find boinding box of simplex
lo = simplex(1).p;
hi = simplex(1).p;
for i=2:n;
j = find(simplex(i).p > hi);
hi(j) = simplex(i).p(j);
j = find(simplex(i).p < lo);
lo(j) = simplex(i).p(j);
end
box = hi - lo;
a = (length(find(hi - lo > smallBox)) <= 0);
if (a), disp('smallbox'); end