-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize.py
42 lines (37 loc) · 1.45 KB
/
optimize.py
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
from argparse import ArgumentParser
from tqdm import tqdm
import numpy as np
from benchmarks.cec import CEC13, CEC17
from algs.MGFWA import MGFWA
from algs.LoTFWA import LoTFWA
parser = ArgumentParser()
parser.add_argument('--alg', type=str, required=True, choices=['MGFWA', 'LoTFWA'], help='which optimization algorithm you want to use')
parser.add_argument('--benchmark', type=str, required=True, choices=['cec2013', 'cec2017'], help='the benchmark you want to test on')
args = parser.parse_args()
alg = {
"MGFWA": MGFWA,
"LoTFWA": LoTFWA
}[args.alg]()
benchmark = {
"cec2013": CEC13,
"cec2017": CEC17
}[args.benchmark]()
for fun_id in range(benchmark.func_num):
print("Function #{}, Optimizing...".format(fun_id+1))
alg.load_prob(evaluator=benchmark.funcs[fun_id])
bestFit, runTime = [], []
for run_id in tqdm(range(benchmark.eval_num)):
best_fit, run_time, _ = alg.run()
if benchmark.name == 'cec2013':
bestFit.append(best_fit - (fun_id - 13 - (fun_id <= 13)) * 100)
elif benchmark.name == 'cec2017':
bestFit.append(best_fit - (fun_id + 1) * 100)
else:
raise ValueError('No such benchmark!')
runTime.append(run_time)
print("MAX:", np.max(bestFit))
print("MIN:", np.min(bestFit))
print("MEAN:", np.mean(bestFit))
print("MEDIAN:", np.median(bestFit))
print("STD:", np.std(bestFit))
print("Average runtime of a run: {} \n".format(np.mean(runTime)))