MCPcopy Index your code
hub / github.com/bayesian-optimization/BayesianOptimization / test_probe

Function test_probe

tests/test_target_space.py:132–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130
131
132def test_probe():
133 PBOUNDS = {"p1": (0, 10), "p2": (1, 100)}
134 space = TargetSpace(target_func, PBOUNDS, allow_duplicate_points=True)
135
136 assert len(space) == 0
137 # probing with dict
138 space.probe(params={"p1": 1, "p2": 2})
139 assert len(space) == 1
140 assert all(space.params[-1] == np.array([1, 2]))
141 assert all(space.target == np.array([3]))
142
143 # probing with array
144 space.probe(np.array([5, 4]))
145 assert len(space) == 2
146 assert all(space.params[1] == np.array([5, 4]))
147 assert all(space.target == np.array([3, 9]))
148
149 # probing same point with dict
150 space.probe(params={"p1": 1, "p2": 2})
151 assert len(space) == 3
152 assert all(space.params[2] == np.array([1, 2]))
153 assert all(space.target == np.array([3, 9, 3]))
154
155 # probing same point with array
156 space.probe(np.array([5, 4]))
157 assert len(space) == 4
158 assert all(space.params[1] == np.array([5, 4]))
159 assert all(space.target == np.array([3, 9, 3, 9]))
160
161 space = TargetSpace(target_func, PBOUNDS, allow_duplicate_points=False)
162
163 # register wrong target to check probe doesn't recompute a duplicate point
164 space.register(params={"p1": 1, "p2": 2}, target=5)
165
166 # probing same point with dict
167 target_ = space.probe(params={"p1": 1, "p2": 2})
168 assert target_ == 5
169
170 # probing same point with array
171 target_ = space.probe(np.array([1, 2]))
172 assert target_ == 5
173
174
175def test_random_sample():

Callers

nothing calls this directly

Calls 3

probeMethod · 0.95
registerMethod · 0.95
TargetSpaceClass · 0.90

Tested by

no test coverage detected