|
12 | 12 | from typing import Callable, List, Union, Tuple
|
13 | 13 | from copy import deepcopy
|
14 | 14 | from numbers import Number
|
15 |
| - |
16 |
| -class ConstraintNotSupportedError(Exception): |
17 |
| - """Raised when constrained optimization is not supported.""" |
18 |
| - |
19 |
| - pass |
20 |
| - |
21 |
| - |
22 |
| -class NoValidPointRegisteredError(Exception): |
23 |
| - """Raised when an acquisition function depends on previous points but none are registered.""" |
24 |
| - |
25 |
| - pass |
26 |
| - |
27 |
| - |
28 |
| -class TargetSpaceEmptyError(Exception): |
29 |
| - """Raised when the target space is empty.""" |
30 |
| - |
31 |
| - pass |
| 15 | +from .util import ConstraintNotSupportedError, NoValidPointRegisteredError, TargetSpaceEmptyError |
32 | 16 |
|
33 | 17 |
|
34 | 18 | class AcquisitionFunction(abc.ABC):
|
@@ -102,9 +86,7 @@ def suggest(self, gp: GaussianProcessRegressor, target_space: TargetSpace, n_ran
|
102 | 86 | self._fit_gp(gp=gp, target_space=target_space)
|
103 | 87 |
|
104 | 88 | acq = self._get_acq(gp=gp, constraint=target_space.constraint)
|
105 |
| - x_max = self._acq_min(acq, target_space.bounds, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b) |
106 |
| - self._update_params() |
107 |
| - return x_max |
| 89 | + return self._acq_min(acq, target_space.bounds, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b) |
108 | 90 |
|
109 | 91 | def _get_acq(self, gp: GaussianProcessRegressor, constraint: Union[ConstraintModel, None] = None) -> Callable:
|
110 | 92 | """Prepare the acquisition function for minimization.
|
@@ -269,10 +251,6 @@ def _l_bfgs_b_minimize(self, acq: Callable, bounds: np.ndarray, n_x_seeds:int=10
|
269 | 251 | # point technicalities this is not always the case.
|
270 | 252 | return np.clip(x_min, bounds[:, 0], bounds[:, 1]), min_acq
|
271 | 253 |
|
272 |
| - def _update_params(self) -> None: |
273 |
| - """Update the parameters of the acquisition function.""" |
274 |
| - pass |
275 |
| - |
276 | 254 |
|
277 | 255 | class UpperConfidenceBound(AcquisitionFunction):
|
278 | 256 | r"""Upper Confidence Bound acquisition function.
|
@@ -357,10 +335,15 @@ def suggest(self, gp: GaussianProcessRegressor, target_space: TargetSpace, n_ran
|
357 | 335 | + "does not support constrained optimization."
|
358 | 336 | )
|
359 | 337 | raise ConstraintNotSupportedError(msg)
|
360 |
| - return super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 338 | + x_max = super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 339 | + self.decay_exploration() |
| 340 | + return x_max |
361 | 341 |
|
362 |
| - def _update_params(self) -> None: |
363 |
| - """Update the parameters of the acquisition function.""" |
| 342 | + def decay_exploration(self) -> None: |
| 343 | + """Decay kappa by a constant rate. |
| 344 | +
|
| 345 | + Adjust exploration/exploitation trade-off by reducing kappa. |
| 346 | + """ |
364 | 347 | if self.exploration_decay is not None:
|
365 | 348 | if self.exploration_decay_delay is None or self.exploration_decay_delay <= self.i:
|
366 | 349 | self.kappa = self.kappa*self.exploration_decay
|
@@ -463,10 +446,15 @@ def suggest(self, gp: GaussianProcessRegressor, target_space: TargetSpace, n_ran
|
463 | 446 | )
|
464 | 447 | raise NoValidPointRegisteredError(msg)
|
465 | 448 | self.y_max = y_max
|
466 |
| - return super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 449 | + x_max = super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 450 | + self.decay_exploration() |
| 451 | + return x_max |
| 452 | + |
| 453 | + def decay_exploration(self) -> None: |
| 454 | + r"""Decay xi by a constant rate. |
467 | 455 |
|
468 |
| - def _update_params(self) -> None: |
469 |
| - """Update the parameters of the acquisition function.""" |
| 456 | + Adjust exploration/exploitation trade-off by reducing xi. |
| 457 | + """ |
470 | 458 | if self.exploration_decay is not None:
|
471 | 459 | if self.exploration_decay_delay is None or self.exploration_decay_delay <= self.i:
|
472 | 460 | self.xi = self.xi*self.exploration_decay
|
@@ -578,10 +566,15 @@ def suggest(self, gp: GaussianProcessRegressor, target_space: TargetSpace, n_ran
|
578 | 566 | raise NoValidPointRegisteredError(msg)
|
579 | 567 | self.y_max = y_max
|
580 | 568 |
|
581 |
| - return super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 569 | + x_max = super().suggest(gp=gp, target_space=target_space, n_random=n_random, n_l_bfgs_b=n_l_bfgs_b, fit_gp=fit_gp) |
| 570 | + self.decay_exploration() |
| 571 | + return x_max |
| 572 | + |
| 573 | + def decay_exploration(self) -> None: |
| 574 | + r"""Decay xi by a constant rate. |
582 | 575 |
|
583 |
| - def _update_params(self) -> None: |
584 |
| - """Update the parameters of the acquisition function.""" |
| 576 | + Adjust exploration/exploitation trade-off by reducing xi. |
| 577 | + """ |
585 | 578 | if self.exploration_decay is not None:
|
586 | 579 | if self.exploration_decay_delay is None or self.exploration_decay_delay <= self.i:
|
587 | 580 | self.xi = self.xi*self.exploration_decay
|
|
0 commit comments