/
_repeat_res.py
44 lines (38 loc) · 1.71 KB
/
_repeat_res.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
"""Repeat the following paper for `RES` (its source code is available at
https://github.com/Evolutionary-Intelligence/pypop/blob/main/pypop7/optimizers/es/res.py):
Hansen, N., Arnold, D.V. and Auger, A., 2015.
Evolution strategies.
In Springer Handbook of Computational Intelligence (pp. 871-898).
Springer, Berlin, Heidelberg.
https://link.springer.com/chapter/10.1007%2F978-3-662-43505-2_44
All generated figures can be accessed via the following link:
https://github.com/Evolutionary-Intelligence/pypop/blob/main/docs/repeatability/res/_repeat_res.png
Luckily our Python code could repeat the data reported in the above paper *well*.
Therefore, we argue that its repeatability could be **well-documented** more or less.
"""
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from pypop7.benchmarks.base_functions import sphere
from pypop7.optimizers.es.res import RES
if __name__ == '__main__':
sns.set_theme(style='darkgrid')
plt.figure()
for i in range(3):
problem = {'fitness_function': sphere,
'ndim_problem': 10}
options = {'max_function_evaluations': 1500,
'seed_rng': i, # undefined in the original paper
'saving_fitness': 1,
'x': np.ones((10,)),
'sigma': 1e-9,
'lr_sigma': 1.0/(1.0 + 10.0/3.0),
'is_restart': False}
res = RES(problem, options)
fitness = res.optimize()['fitness']
plt.plot(fitness[:, 0], np.sqrt(fitness[:, 1]), 'b') # sqrt for distance
plt.xticks([0, 500, 1000, 1500])
plt.xlim([0, 1500])
plt.yticks([1e-9, 1e-6, 1e-3, 1e0])
plt.yscale('log')
plt.show()