-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathrun_multi_functions.py
55 lines (43 loc) · 1.74 KB
/
run_multi_functions.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# Created by "Thieu" at 10:08, 02/03/2022 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%
from pathlib import Path
from opfunu.cec_basic import cec2014_nobias
from pandas import DataFrame
from mealpy.evolutionary_based.DE import BaseDE
PATH_RESULTS = "history/results/"
Path(PATH_RESULTS).mkdir(parents=True, exist_ok=True)
## Setting parameters
model_name = "DE"
lb1 = [-100, ] * 30
ub1 = [100, ] * 30
epoch = 10
pop_size = 50
wf = 0.8
cr = 0.9
func_names = ["F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19"]
## Run model
best_fit_full = {}
best_fit_columns = []
error_full = {}
error_columns = []
for func_name in func_names:
problem = {
"fit_func": getattr(cec2014_nobias, func_name),
"lb": lb1,
"ub": ub1,
"minmax": "min",
"log_to": "console",
}
model = BaseDE(epoch, pop_size, wf, cr, fit_name=func_name)
_, best_fitness = model.solve(problem)
error_full[func_name] = model.history.list_global_best_fit
error_columns.append(func_name)
best_fit_full[func_name] = [best_fitness]
best_fit_columns.append(func_name)
df_err = DataFrame(error_full, columns=error_columns)
df_err.to_csv(f"{PATH_RESULTS}{len(lb1)}D_{model_name}_error.csv", header=True, index=False)
df_fit = DataFrame(best_fit_full, columns=best_fit_columns)
df_fit.to_csv(f"{PATH_RESULTS}{len(lb1)}D_{model_name}_best_fit.csv", header=True, index=False)