forked from bayesian-optimization/BayesianOptimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_seq_domain_red.py
66 lines (50 loc) · 1.69 KB
/
test_seq_domain_red.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from bayes_opt import SequentialDomainReductionTransformer
from bayes_opt import BayesianOptimization
def black_box_function(x, y):
"""Function with unknown internals we wish to maximize.
This is just serving as an example, for all intents and
purposes think of the internals of this function, i.e.: the process
which generates its output values, as unknown.
"""
return -x ** 2 - (y - 1) ** 2 + 1
def test_bound_x_maximize():
class Tracker:
def __init__(self):
self.start_count = 0
self.step_count = 0
self.end_count = 0
def update_start(self, event, instance):
self.start_count += 1
def update_step(self, event, instance):
self.step_count += 1
def update_end(self, event, instance):
self.end_count += 1
def reset(self):
self.__init__()
bounds_transformer = SequentialDomainReductionTransformer()
pbounds = {'x': (-10, 10), 'y': (-10, 10)}
n_iter = 10
standard_optimizer = BayesianOptimization(
f=black_box_function,
pbounds=pbounds,
verbose=2,
random_state=1,
)
standard_optimizer.maximize(
init_points=2,
n_iter=n_iter,
)
mutated_optimizer = BayesianOptimization(
f=black_box_function,
pbounds=pbounds,
verbose=2,
random_state=1,
bounds_transformer=bounds_transformer
)
mutated_optimizer.maximize(
init_points=2,
n_iter=n_iter,
)
assert len(standard_optimizer.space) == len(mutated_optimizer.space)
assert not (standard_optimizer._space.bounds ==
mutated_optimizer._space.bounds).any()