-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate.m
54 lines (52 loc) · 1.8 KB
/
generate.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
function generate()
% Generate a dataset
clc; format compact; addpath('Optimizer');
try
load Dataset Input Output
catch
Input = {};
Output = {};
end
Algorithm = {@ABC,@ACO,@CMAES,@CSO,@DE,@FEP,@GA,@PSO,@SA,@Rand};
for i = 1 : 100000
clc; fprintf('#Generated functions: %d\n#Valid samples: %d\n',i,length(Input));
% Randomly generate a function
tree = generate_tree(8,12);
exp = generate_tree2exp(tree);
fun = generate_exp2fun(exp);
Data = zeros(10,length(Algorithm));
valid = true;
for r = 1 : size(Data,1)
for a = 1 : size(Data,2)
% Obtain the minimum value found by each algorithm, where
% the number of variable is 10, the population size is 100,
% the number of generations is 100.
Data(r,a) = Algorithm{a}(fun,10,100,100);
end
if any(isnan(Data(r,:))) || any(abs(Data(r,:))>1e10)
% If the function has nan value or extremely large value,
% ignore the function
valid = false;
break;
end
end
% If the best algorithm is statistically similar to another
% algorithm, ignore the function
if valid
[~,best] = min(mean(Data,1));
for a = [1:best-1,best+1:size(Data,2)]
[~,diff] = ranksum(Data(:,a),Data(:,best));
if ~diff
valid = false;
break;
end
end
end
% Save this sample
if valid
Input = [Input,exp];
Output = [Output,mean(Data,1)];
save Dataset Input Output
end
end
end