Skip to content

Commit d4cc5d7

Browse files
Add files via upload
1 parent 8d332e4 commit d4cc5d7

File tree

4 files changed

+399
-0
lines changed

4 files changed

+399
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""This script plots the *median* convergence curves for
2+
various DE w.r.t. actual runtime (to be needed).
3+
4+
Chinese: 该绘图脚本被段琦琦的博士论文(哈工大与南科大联合培养)所使用。
5+
"""
6+
import os
7+
import sys
8+
import pickle5 as pickle
9+
10+
import seaborn as sns
11+
import matplotlib.pyplot as plt
12+
13+
from pypop7.optimizers.core import optimizer
14+
sys.modules['optimizer'] = optimizer
15+
16+
17+
def read_pickle(a, f, i):
18+
folder = './docs/pypop7_benchmarks_lso/single-core'
19+
file_name = a + '/Algo-' + a + '_Func-' + f +\
20+
'_Dim-2000_Exp-' + i + '.pickle'
21+
with open(os.path.join(folder, file_name), 'rb') as handle:
22+
return pickle.load(handle)
23+
24+
25+
if __name__ == '__main__':
26+
font_size = 11
27+
sns.set_theme(style='darkgrid')
28+
plt.rcParams['font.family'] = 'Times New Roman'
29+
plt.rcParams['font.size'] = '11'
30+
31+
n_trials = 4 # number of trials (independent experiments)
32+
algos = ['DEAPDE', 'CDE', 'TDE', 'CODE', 'JADE', 'SHADE']
33+
max_runtime, fitness_threshold = 3600.0 * 3 - 10.0 * 60, 1e-10
34+
# funcs = ['cigar', 'cigar_discus', 'ackley', 'bohachevsky',
35+
# 'different_powers', 'discus', 'griewank', 'levy_montalvo',
36+
# 'ellipsoid', 'rosenbrock', 'michalewicz', 'rastrigin',
37+
# 'schwefel12', 'schwefel221', 'salomon', 'scaled_rastrigin',
38+
# 'step', 'schaffer', 'sphere', 'skew_rastrigin']
39+
funcs = ['cigar', 'ackley', 'bohachevsky',
40+
'discus', 'ellipsoid', 'rosenbrock',
41+
'rastrigin', 'schwefel12', 'schwefel221']
42+
fig = plt.figure(figsize=(9, 11))
43+
no_of_rows, no_of_cols = 3, 3 # 5, 4
44+
axs = fig.subplots(no_of_rows, no_of_cols)
45+
for k, f in enumerate(funcs):
46+
time, fitness = [], []
47+
for i in range(len(algos)):
48+
time.append([])
49+
fitness.append([])
50+
for _ in range(n_trials):
51+
time[i].append([])
52+
fitness[i].append([])
53+
for i in range(n_trials):
54+
for j, a in enumerate(algos):
55+
results = read_pickle(a, f, str(i + 1))
56+
time[j][i] = results['fitness'][:, 0] *\
57+
results['runtime'] /\
58+
results['n_function_evaluations']
59+
y = results['fitness'][:, 1]
60+
if f == 'michalewicz':
61+
y += 600 # to plot log-scale y-axis
62+
fitness[j][i] = y
63+
top_order = []
64+
for j, a in enumerate(algos):
65+
run, fit, r_f = [], [], []
66+
for i in range(len(time[j])):
67+
run.append(time[j][i][-1] if time[j][i][-1] <= max_runtime else max_runtime)
68+
fit.append(fitness[j][i][-1] if fitness[j][i][-1] >= fitness_threshold else fitness_threshold)
69+
r_f.append([run[i], fit[i], i])
70+
r_f.sort(key=lambda x: (x[0], x[1]))
71+
order = r_f[int(n_trials / 2)][2] # for median (but non-standard)
72+
top_order.append(order)
73+
m, n = divmod(k, no_of_cols)
74+
axs[m][n].set_yscale('log')
75+
for j, a in enumerate(algos):
76+
axs[m][n].plot(time[j][top_order[j]],
77+
fitness[j][top_order[j]],
78+
label=a)
79+
axs[m][n].set_title(f, fontsize=font_size) # , fontweight='bold'
80+
x_label = axs[m][n].get_xticklabels()
81+
[xl.set_fontsize(font_size) for xl in x_label]
82+
# [xl.set_fontweight('bold') for xl in x_label]
83+
y_label = axs[m][n].get_yticklabels()
84+
[yl.set_fontsize(font_size) for yl in y_label]
85+
# [yl.set_fontweight('bold') for yl in y_label]
86+
87+
lines, labels = axs[-1][-1].get_legend_handles_labels()
88+
leg = fig.legend(lines, labels, loc='center', ncol=6,
89+
fontsize=font_size,
90+
bbox_to_anchor=(0.51, 0.93))
91+
# for text in leg.get_texts():
92+
# text.set_fontweight('bold')
93+
fig.text(0.05, 0.5, 'Fitness (Minimized)', va='center',
94+
rotation='vertical', fontsize=font_size) # 'xx-large'
95+
fig.text(0.5, 0.05, 'Runtime (Seconds)', va='center',
96+
ha='center', fontsize=font_size) # 'xx-large'
97+
plt.savefig('DE.png', dpi=700, bbox_inches='tight')
98+
plt.show()
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""This script plots the *median* convergence curves for
2+
various EDA/CEM w.r.t. actual runtime (to be needed).
3+
4+
Chinese: 该绘图脚本被段琦琦的博士论文(哈工大与南科大联合培养)所使用。
5+
"""
6+
import os
7+
import sys
8+
import pickle5 as pickle
9+
10+
import seaborn as sns
11+
import matplotlib.pyplot as plt
12+
13+
from pypop7.optimizers.core import optimizer
14+
sys.modules['optimizer'] = optimizer
15+
16+
17+
def read_pickle(a, f, i):
18+
folder = './docs/pypop7_benchmarks_lso/single-core'
19+
file_name = a + '/Algo-' + a + '_Func-' + f +\
20+
'_Dim-2000_Exp-' + i + '.pickle'
21+
with open(os.path.join(folder, file_name), 'rb') as handle:
22+
return pickle.load(handle)
23+
24+
25+
if __name__ == '__main__':
26+
font_size = 11
27+
sns.set_theme(style='darkgrid')
28+
plt.rcParams['font.family'] = 'Times New Roman'
29+
plt.rcParams['font.size'] = '11'
30+
31+
n_trials = 4 # number of trials (independent experiments)
32+
algos = ['DEAPEDA', 'EMNA', 'AEMNA', 'UMDA', 'RPEDA',
33+
'DCEM', 'DSCEM', 'MRAS', 'SCEM']
34+
max_runtime, fitness_threshold = 3600.0 * 3 - 10.0 * 60, 1e-10
35+
# funcs = ['cigar', 'cigar_discus', 'ackley', 'bohachevsky',
36+
# 'different_powers', 'discus', 'griewank', 'levy_montalvo',
37+
# 'ellipsoid', 'rosenbrock', 'michalewicz', 'rastrigin',
38+
# 'schwefel12', 'schwefel221', 'salomon', 'scaled_rastrigin',
39+
# 'step', 'schaffer', 'sphere', 'skew_rastrigin']
40+
funcs = ['cigar', 'ackley', 'bohachevsky',
41+
'discus', 'ellipsoid', 'rosenbrock',
42+
'rastrigin', 'schwefel12', 'schwefel221']
43+
fig = plt.figure(figsize=(9, 11))
44+
no_of_rows, no_of_cols = 3, 3 # 5, 4
45+
axs = fig.subplots(no_of_rows, no_of_cols)
46+
for k, f in enumerate(funcs):
47+
time, fitness = [], []
48+
for i in range(len(algos)):
49+
time.append([])
50+
fitness.append([])
51+
for _ in range(n_trials):
52+
time[i].append([])
53+
fitness[i].append([])
54+
for i in range(n_trials):
55+
for j, a in enumerate(algos):
56+
results = read_pickle(a, f, str(i + 1))
57+
time[j][i] = results['fitness'][:, 0] *\
58+
results['runtime'] /\
59+
results['n_function_evaluations']
60+
y = results['fitness'][:, 1]
61+
if f == 'michalewicz':
62+
y += 600 # to plot log-scale y-axis
63+
fitness[j][i] = y
64+
top_order = []
65+
for j, a in enumerate(algos):
66+
run, fit, r_f = [], [], []
67+
for i in range(len(time[j])):
68+
run.append(time[j][i][-1] if time[j][i][-1] <= max_runtime else max_runtime)
69+
fit.append(fitness[j][i][-1] if fitness[j][i][-1] >= fitness_threshold else fitness_threshold)
70+
r_f.append([run[i], fit[i], i])
71+
r_f.sort(key=lambda x: (x[0], x[1]))
72+
order = r_f[int(n_trials / 2)][2] # for median (but non-standard)
73+
top_order.append(order)
74+
m, n = divmod(k, no_of_cols)
75+
axs[m][n].set_yscale('log')
76+
for j, a in enumerate(algos):
77+
axs[m][n].plot(time[j][top_order[j]],
78+
fitness[j][top_order[j]],
79+
label=a)
80+
axs[m][n].set_title(f, fontsize=font_size) # , fontweight='bold'
81+
x_label = axs[m][n].get_xticklabels()
82+
[xl.set_fontsize(font_size) for xl in x_label]
83+
# [xl.set_fontweight('bold') for xl in x_label]
84+
y_label = axs[m][n].get_yticklabels()
85+
[yl.set_fontsize(font_size) for yl in y_label]
86+
# [yl.set_fontweight('bold') for yl in y_label]
87+
88+
lines, labels = axs[-1][-1].get_legend_handles_labels()
89+
leg = fig.legend(lines, labels, loc='center', ncol=5,
90+
fontsize=font_size,
91+
bbox_to_anchor=(0.51, 0.93))
92+
# for text in leg.get_texts():
93+
# text.set_fontweight('bold')
94+
fig.text(0.05, 0.5, 'Fitness (Minimized)', va='center',
95+
rotation='vertical', fontsize=font_size) # 'xx-large'
96+
fig.text(0.5, 0.05, 'Runtime (Seconds)', va='center',
97+
ha='center', fontsize=font_size) # 'xx-large'
98+
plt.savefig('EDA.png', dpi=700, bbox_inches='tight')
99+
plt.show()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""This script plots the *median* convergence curves for
2+
various ES w.r.t. actual runtime (to be needed).
3+
4+
Chinese: 该绘图脚本被段琦琦的博士论文(哈工大与南科大联合培养)所使用。
5+
"""
6+
import os
7+
import sys
8+
import pickle5 as pickle
9+
10+
import seaborn as sns
11+
import matplotlib.pyplot as plt
12+
13+
from pypop7.optimizers.core import optimizer
14+
sys.modules['optimizer'] = optimizer
15+
16+
17+
def read_pickle(a, f, i):
18+
folder = './docs/pypop7_benchmarks_lso/single-core'
19+
file_name = a + '/Algo-' + a + '_Func-' + f +\
20+
'_Dim-2000_Exp-' + i + '.pickle'
21+
with open(os.path.join(folder, file_name), 'rb') as handle:
22+
return pickle.load(handle)
23+
24+
25+
if __name__ == '__main__':
26+
font_size = 11
27+
sns.set_theme(style='darkgrid')
28+
plt.rcParams['font.family'] = 'Times New Roman'
29+
plt.rcParams['font.size'] = '11'
30+
31+
n_trials = 4 # number of trials (independent experiments)
32+
algos = ['DEAPCMAES', 'MMES', 'FCMAES', 'LMMAES', 'LMCMA',
33+
'RMES', 'R1ES', 'VKDCMA', 'VDCMA', 'CCMAES2016',
34+
'OPOA2015', 'OPOA2010', 'CCMAES2009', 'OPOC2009', 'OPOC2006',
35+
'SEPCMAES', 'DDCMA', 'MAES', 'FMAES', 'SAES',
36+
'CSAES', 'RES', 'R1NES']
37+
max_runtime, fitness_threshold = 3600.0 * 3 - 10.0 * 60, 1e-10
38+
# funcs = ['cigar', 'cigar_discus', 'ackley', 'bohachevsky',
39+
# 'different_powers', 'discus', 'griewank', 'levy_montalvo',
40+
# 'ellipsoid', 'rosenbrock', 'michalewicz', 'rastrigin',
41+
# 'schwefel12', 'schwefel221', 'salomon', 'scaled_rastrigin',
42+
# 'step', 'schaffer', 'sphere', 'skew_rastrigin']
43+
funcs = ['cigar', 'ackley', 'bohachevsky',
44+
'discus', 'ellipsoid', 'rosenbrock',
45+
'rastrigin', 'schwefel12', 'schwefel221']
46+
47+
fig = plt.figure(figsize=(9, 11))
48+
no_of_rows, no_of_cols = 3, 3 # 5, 4
49+
axs = fig.subplots(no_of_rows, no_of_cols)
50+
for k, f in enumerate(funcs):
51+
time, fitness = [], []
52+
for i in range(len(algos)):
53+
time.append([])
54+
fitness.append([])
55+
for _ in range(n_trials):
56+
time[i].append([])
57+
fitness[i].append([])
58+
for i in range(n_trials):
59+
for j, a in enumerate(algos):
60+
results = read_pickle(a, f, str(i + 1))
61+
time[j][i] = results['fitness'][:, 0] *\
62+
results['runtime'] /\
63+
results['n_function_evaluations']
64+
y = results['fitness'][:, 1]
65+
if f == 'michalewicz':
66+
y += 600 # to plot log-scale y-axis
67+
fitness[j][i] = y
68+
top_order = []
69+
for j, a in enumerate(algos):
70+
run, fit, r_f = [], [], []
71+
for i in range(len(time[j])):
72+
run.append(time[j][i][-1] if time[j][i][-1] <= max_runtime else max_runtime)
73+
fit.append(fitness[j][i][-1] if fitness[j][i][-1] >= fitness_threshold else fitness_threshold)
74+
r_f.append([run[i], fit[i], i])
75+
r_f.sort(key=lambda x: (x[0], x[1]))
76+
order = r_f[int(n_trials / 2)][2] # for median (but non-standard)
77+
top_order.append(order)
78+
m, n = divmod(k, no_of_cols)
79+
axs[m][n].set_yscale('log')
80+
for j, a in enumerate(algos):
81+
axs[m][n].plot(time[j][top_order[j]],
82+
fitness[j][top_order[j]],
83+
label=a)
84+
axs[m][n].set_title(f, fontsize=font_size) # , fontweight='bold'
85+
x_label = axs[m][n].get_xticklabels()
86+
[xl.set_fontsize(font_size) for xl in x_label]
87+
# [xl.set_fontweight('bold') for xl in x_label]
88+
y_label = axs[m][n].get_yticklabels()
89+
[yl.set_fontsize(font_size) for yl in y_label]
90+
# [yl.set_fontweight('bold') for yl in y_label]
91+
92+
lines, labels = axs[-1][-1].get_legend_handles_labels()
93+
leg = fig.legend(lines, labels, loc='center', ncol=5,
94+
fontsize=font_size,
95+
bbox_to_anchor=(0.51, 0.95))
96+
# for text in leg.get_texts():
97+
# text.set_fontweight('bold')
98+
fig.text(0.05, 0.5, 'Fitness (Minimized)', va='center',
99+
rotation='vertical', fontsize=font_size) # 'xx-large'
100+
fig.text(0.5, 0.05, 'Runtime (Seconds)', va='center',
101+
ha='center', fontsize=font_size) # 'xx-large'
102+
plt.savefig('ES.png', dpi=700, bbox_inches='tight')
103+
plt.show()

0 commit comments

Comments
 (0)