|
1
|
|
|
import pytest |
|
2
|
|
|
from tqdm import tqdm |
|
3
|
|
|
import numpy as np |
|
4
|
|
|
|
|
5
|
|
|
from ._parametrize import pytest_parameter |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
View Code Duplication |
@pytest.mark.parametrize(*pytest_parameter) |
|
|
|
|
|
|
9
|
|
|
def test_exploration_0(Optimizer): |
|
10
|
|
|
def objective_function(para): |
|
11
|
|
|
score = -(para["x1"] * para["x1"] + para["x2"] * para["x2"]) |
|
12
|
|
|
return score |
|
13
|
|
|
|
|
14
|
|
|
search_space = { |
|
15
|
|
|
"x1": np.arange(-50, 1, 1), |
|
16
|
|
|
"x2": np.arange(0, 10, 1), |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
init1 = { |
|
20
|
|
|
"x1": -50, |
|
21
|
|
|
"x2": 1, |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
init2 = { |
|
25
|
|
|
"x1": -49, |
|
26
|
|
|
"x2": 2, |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
opt = Optimizer(search_space) |
|
30
|
|
|
opt.search( |
|
31
|
|
|
objective_function, |
|
32
|
|
|
n_iter=50, |
|
33
|
|
|
memory=False, |
|
34
|
|
|
verbosity={"print_results": False, "progress_bar": False,}, |
|
35
|
|
|
initialize={"warm_start": [init1, init2]}, |
|
36
|
|
|
) |
|
37
|
|
|
|
|
38
|
|
|
uniques_2nd_dim = list(opt.results["x2"].values) |
|
39
|
|
|
|
|
40
|
|
|
print("\n uniques_2nd_dim \n", uniques_2nd_dim, "\n") |
|
41
|
|
|
print("\n Results head \n", opt.results.head()) |
|
42
|
|
|
print("\n Results tail \n", opt.results.tail()) |
|
43
|
|
|
|
|
44
|
|
|
print("\nN iter:", len(opt.results)) |
|
45
|
|
|
|
|
46
|
|
|
assert 0 in uniques_2nd_dim |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
View Code Duplication |
@pytest.mark.parametrize(*pytest_parameter) |
|
|
|
|
|
|
50
|
|
|
def test_exploration_1(Optimizer): |
|
51
|
|
|
def objective_function(para): |
|
52
|
|
|
score = -(para["x1"] * para["x1"] + para["x2"] * para["x2"]) |
|
53
|
|
|
return score |
|
54
|
|
|
|
|
55
|
|
|
search_space = { |
|
56
|
|
|
"x1": np.arange(-50, 1, 1), |
|
57
|
|
|
"x2": np.arange(-10, 1, 1), |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
init1 = { |
|
61
|
|
|
"x1": -50, |
|
62
|
|
|
"x2": -1, |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
init2 = { |
|
66
|
|
|
"x1": -49, |
|
67
|
|
|
"x2": -2, |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
opt = Optimizer(search_space) |
|
71
|
|
|
opt.search( |
|
72
|
|
|
objective_function, |
|
73
|
|
|
n_iter=50, |
|
74
|
|
|
memory=False, |
|
75
|
|
|
verbosity={"print_results": False, "progress_bar": False,}, |
|
76
|
|
|
initialize={"warm_start": [init1]}, |
|
77
|
|
|
) |
|
78
|
|
|
|
|
79
|
|
|
uniques_2nd_dim = list(opt.results["x2"].values) |
|
80
|
|
|
|
|
81
|
|
|
print("\n uniques_2nd_dim \n", uniques_2nd_dim, "\n") |
|
82
|
|
|
print("\n Results head \n", opt.results.head()) |
|
83
|
|
|
print("\n Results tail \n", opt.results.tail()) |
|
84
|
|
|
|
|
85
|
|
|
print("\nN iter:", len(opt.results)) |
|
86
|
|
|
|
|
87
|
|
|
assert 0 in uniques_2nd_dim |
|
88
|
|
|
|
|
89
|
|
|
|