(gp, target_space, target_func, random_state, strategy)
| 239 | |
| 240 | @pytest.mark.parametrize("strategy", [0.0, "mean", "min", "max"]) |
| 241 | def test_constant_liar(gp, target_space, target_func, random_state, strategy): |
| 242 | base_acq = acquisition.UpperConfidenceBound() |
| 243 | acq = acquisition.ConstantLiar(base_acquisition=base_acq, strategy=strategy) |
| 244 | |
| 245 | target_space.register(params={"x": 2.5, "y": 0.5}, target=3.0) |
| 246 | target_space.register(params={"x": 1.0, "y": 1.5}, target=2.5) |
| 247 | base_samples = np.array([base_acq.suggest(gp=gp, target_space=target_space) for _ in range(10)]) |
| 248 | samples = [] |
| 249 | |
| 250 | assert len(acq.dummies) == 0 |
| 251 | for _ in range(10): |
| 252 | samples.append(acq.suggest(gp=gp, target_space=target_space, random_state=random_state)) |
| 253 | assert len(acq.dummies) == len(samples) |
| 254 | |
| 255 | samples = np.array(samples) |
| 256 | print(samples) |
| 257 | |
| 258 | base_distance = pdist(base_samples, "sqeuclidean").mean() |
| 259 | distance = pdist(samples, "sqeuclidean").mean() |
| 260 | |
| 261 | assert base_distance < distance |
| 262 | |
| 263 | for i in range(10): |
| 264 | target_space.register(params={"x": samples[i][0], "y": samples[i][1]}, target=target_func(samples[i])) |
| 265 | |
| 266 | acq.suggest(gp=gp, target_space=target_space, random_state=random_state) |
| 267 | |
| 268 | assert len(acq.dummies) == 1 |
| 269 | |
| 270 | |
| 271 | def test_constant_liar_invalid_strategy(): |
nothing calls this directly
no test coverage detected