-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy path_repeat_rhc.py
More file actions
54 lines (41 loc) · 2.04 KB
/
_repeat_rhc.py
File metadata and controls
54 lines (41 loc) · 2.04 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
"""Repeat the following paper for `RHC`:
Schaul, T., Bayer, J., Wierstra, D., Sun, Y., Felder, M., Sehnke, F., Rückstieß, T. and Schmidhuber, J., 2010.
PyBrain.
Journal of Machine Learning Research, 11(24), pp.743-746.
https://jmlr.org/papers/v11/schaul10a.html
Luckily our Python code could repeat the data reported in the other reference Python code *well*.
Therefore, we argue that its repeatability could be **well-documented**.
The reference Python code (https://github.com/pybrain/pybrain) is shown below:
------------------------------------------------------------------------------
import time
import numpy as np
# use Python 2.7 to avoid possible unsuccessful installation, since PyBrain was not maintained (after 2017)
from pybrain.optimization.hillclimber import HillClimber as RHC
def ellipsoid(x):
return np.dot(np.power(10, 6*np.linspace(0, 1, x.size)), np.power(x, 2))
np.random.seed(0)
solver = RHC(ellipsoid, 4*np.ones((1000,)), minimize=True, maxEvaluations=2e6, verbose=True)
start_time = time.time()
solver.learn()
# ('Step:', 1999998, 'best:', 11215098.066122532)
print("Runtime: {:7.5e}".format(time.time() - start_time))
"""
import time
import numpy as np
from pypop7.benchmarks.base_functions import ellipsoid
from pypop7.optimizers.rs.rhc import RHC
if __name__ == '__main__':
start_run = time.time()
ndim_problem = 1000
problem = {'fitness_function': ellipsoid,
'ndim_problem': ndim_problem,
'upper_boundary': 5.0*np.ones((ndim_problem,)),
'lower_boundary': -5.0*np.ones((ndim_problem,))}
options = {'max_function_evaluations': 2e6,
'seed_rng': 0,
'x': 4*np.ones((ndim_problem,)),
'sigma': 0.1,
'verbose': 200000,
'saving_fitness': 200000}
print(RHC(problem, options).optimize()) # 1.06803861e+07
print('*** Runtime: {:7.5e}'.format(time.time() - start_run))