forked from numbbo/coco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleexperiment.m
89 lines (81 loc) · 3.66 KB
/
exampleexperiment.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%
% This script runs random search for BUDGET_MULTIPLIER*DIM function
% evaluations on the biobjective 'bbob-biobj' suite.
%
% An example experiment on the single-objective 'bbob' suite can be started
% by renaming the suite_name below.
%
% This example experiment allows also for easy implementation of independent
% restarts by simply increasing NUM_OF_INDEPENDENT_RESTARTS. To make this
% effective, the algorithm should have at least one more stopping criterium
% than just a maximal budget.
%
more off; % to get immediate output in Octave
%%%%%%%%%%%%%%%%%%%%%%%%%
% Experiment Parameters %
%%%%%%%%%%%%%%%%%%%%%%%%%
BUDGET_MULTIPLIER = 2; % algorithm runs for BUDGET_MULTIPLIER*dimension funevals
NUM_OF_INDEPENDENT_RESTARTS = 1e9; % max. number of independent algorithm
% restarts; if >0, make sure that the
% algorithm is not always doing the same thing
% in each run (which is typically trivial for
% randomized algorithms)
%%%%%%%%%%%%%%%%%%%%%%%%%
% Prepare Experiment %
%%%%%%%%%%%%%%%%%%%%%%%%%
suite_name = 'bbob-biobj'; % works for 'bbob' as well
observer_name = suite_name;
observer_options = strcat('result_folder: RS_on_', ...
suite_name, ...
[' algorithm_name: RS '...
' algorithm_info: A_simple_random_search ']);
% dimension 40 is optional:
suite = cocoCall('cocoSuite', suite_name, 'year: 2016', 'dimensions: 2,3,5,10,20,40');
observer = cocoCall('cocoObserver', observer_name, observer_options);
% set log level depending on how much output you want to see, e.g. 'warning'
% for fewer output than 'info'.
cocoCall('cocoSetLogLevel', 'info');
%%%%%%%%%%%%%%%%%%%%%%%%%
% Run Experiment %
%%%%%%%%%%%%%%%%%%%%%%%%%
while true
% get next problem and dimension from the chosen suite:
problem = cocoCall('cocoSuiteGetNextProblem', suite, observer);
if (~cocoCall('cocoProblemIsValid', problem))
break;
end
dimension = cocoCall('cocoProblemGetDimension', problem);
% restart functionality: do at most NUM_OF_INDEPENDENT_RESTARTS+1
% independent runs until budget is used:
i = -1; % count number of independent restarts
while BUDGET_MULTIPLIER*dimension > cocoCall('cocoProblemGetEvaluations', problem)
i = i+1;
if (i > 0)
fprintf('INFO: algorithm restarted\n');
end
doneEvalsBefore = cocoCall('cocoProblemGetEvaluations', problem);
% start algorithm with remaining number of function evaluations:
my_optimizer(problem,...
cocoCall('cocoProblemGetSmallestValuesOfInterest', problem),...
cocoCall('cocoProblemGetLargestValuesOfInterest', problem),...
BUDGET_MULTIPLIER*dimension - doneEvalsBefore);
% check whether things went wrong or whether experiment is over:
doneEvalsAfter = cocoCall('cocoProblemGetEvaluations', problem);
if (cocoCall('cocoProblemFinalTargetHit', problem) == 1) || (doneEvalsAfter >= BUDGET_MULTIPLIER * dimension)
break;
end
if (doneEvalsAfter == doneEvalsBefore)
fprintf('WARNING: Budget has not been exhausted (%d/%d evaluations done)!\n', ....
doneEvalsBefore, BUDGET_MULTIPLIER * dimension);
break;
end
if (doneEvalsAfter < doneEvalsBefore)
fprintf('ERROR: Something weird happened here which should not happen: f-evaluations decreased');
end
if (i >= NUM_OF_INDEPENDENT_RESTARTS)
break;
end
end
end
cocoCall('cocoObserverFree', observer);
cocoCall('cocoSuiteFree', suite);