-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy path_repeat_cde.py
More file actions
57 lines (51 loc) · 2.16 KB
/
Copy path_repeat_cde.py
File metadata and controls
57 lines (51 loc) · 2.16 KB
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
56
57
"""Repeat the following paper for `CDE`:
Storn, R.M. and Price, K.V. 1997.
Differential evolution – a simple and efficient heuristic for global optimization over continuous spaces.
Journal of Global Optimization, 11(4), pp.341–359.
https://link.springer.com/article/10.1023/A:1008202821328
Luckily our Python code could repeat the data reported in the original paper *well*.
Therefore, we argue that its repeatability could be **well-documented**.
"""
import numpy as np
from pypop7.benchmarks.base_functions import sphere, rosenbrock, griewank
from pypop7.optimizers.de.cde import CDE
if __name__ == '__main__':
problem = {'fitness_function': sphere,
'ndim_problem': 3,
'lower_boundary': -5.12*np.ones((3,)),
'upper_boundary': 5.12*np.ones((3,))}
options = {'fitness_threshold': 1e-6,
'seed_rng': 2,
'n_individuals': 5,
'f': 0.9,
'cr': 0.1}
cde = CDE(problem, options)
results = cde.optimize()
print(results['n_function_evaluations'], results['best_so_far_y'])
# 364 vs 406 (from the original paper)
problem = {'fitness_function': rosenbrock,
'ndim_problem': 2,
'lower_boundary': -2.048*np.ones((2,)),
'upper_boundary': 2.048*np.ones((2,))}
options = {'fitness_threshold': 1e-6,
'seed_rng': 1,
'n_individuals': 10,
'f': 0.9,
'cr': 0.9}
cde = CDE(problem, options)
results = cde.optimize()
print(results['n_function_evaluations'], results['best_so_far_y'])
# 528 vs 654 (from the original paper)
problem = {'fitness_function': griewank,
'ndim_problem': 10,
'lower_boundary': -400*np.ones((10,)),
'upper_boundary': 400*np.ones((10,))}
options = {'fitness_threshold': 1e-6,
'seed_rng': 0,
'n_individuals': 25,
'f': 0.5,
'cr': 0.2}
cde = CDE(problem, options)
results = cde.optimize()
print(results['n_function_evaluations'], results['best_so_far_y'])
# 11554 vs 12752 (from the original paper)