1
|
|
|
# Author: Simon Blanke |
2
|
|
|
# Email: [email protected] |
3
|
|
|
# License: MIT License |
4
|
|
|
|
5
|
|
|
import numpy as np |
6
|
|
|
|
7
|
|
|
from gradient_free_optimizers import DecisionTreeOptimizer |
8
|
|
|
|
9
|
|
|
n_iter = 100 |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
def get_score(pos_new): |
13
|
|
|
return -(pos_new[0] * pos_new[0]) |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
space_dim = np.array([10]) |
17
|
|
|
init_positions = [np.array([0]), np.array([1]), np.array([2]), np.array([3])] |
18
|
|
|
|
19
|
|
|
|
20
|
|
View Code Duplication |
def _base_test(opt): |
|
|
|
|
21
|
|
|
for nth_init in range(len(init_positions)): |
22
|
|
|
pos_new = opt.init_pos(nth_init) |
23
|
|
|
score_new = get_score(pos_new) |
24
|
|
|
opt.evaluate(score_new) |
25
|
|
|
|
26
|
|
|
for nth_iter in range(len(init_positions), n_iter): |
27
|
|
|
pos_new = opt.iterate(nth_iter) |
28
|
|
|
score_new = get_score(pos_new) |
29
|
|
|
opt.evaluate(score_new) |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
def _test_DecisionTreeOptimizer(opt_para): |
33
|
|
|
opt = DecisionTreeOptimizer(init_positions, space_dim, opt_para=opt_para) |
34
|
|
|
_base_test(opt) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
def test_start_up_evals(): |
38
|
|
|
for start_up_evals in [1, 100]: |
39
|
|
|
opt_para = {"start_up_evals": start_up_evals} |
40
|
|
|
_test_DecisionTreeOptimizer(opt_para) |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def test_warm_start_smbo(): |
44
|
|
|
for warm_start_smbo in [True, False]: |
45
|
|
|
opt_para = {"warm_start_smbo": warm_start_smbo} |
46
|
|
|
_test_DecisionTreeOptimizer(opt_para) |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
def test_max_sample_size(): |
50
|
|
|
for max_sample_size in [10, 100, 10000, 10000000000]: |
51
|
|
|
opt_para = {"max_sample_size": max_sample_size} |
52
|
|
|
_test_DecisionTreeOptimizer(opt_para) |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
""" |
56
|
|
|
def test_gpr(): |
57
|
|
|
opt = Hyperactive(X, y, memory=memory) |
58
|
|
|
opt.search( |
59
|
|
|
search_config, |
60
|
|
|
n_iter=n_iter, |
61
|
|
|
optimizer={"DecisionTree": {"tree_regressor": "random_forest"}}, |
62
|
|
|
) |
63
|
|
|
""" |
64
|
|
|
|