Skip to content

Annealing design

smac.random_design.annealing_design #

CosineAnnealingRandomDesign #

CosineAnnealingRandomDesign(
    min_probability: float,
    max_probability: float,
    restart_iteration: int,
    seed: int = 0,
)

Bases: AbstractRandomDesign

Interleaves a random configuration according to a given probability which is decreased according to a cosine annealing schedule.

Parameters#

max_probability : float Initial (maximum) probability of a random configuration. min_probability : float Final (minimal) probability of a random configuration used in iteration restart_iteration. restart_iteration : int Restart the annealing schedule every restart_iteration iterations. seed : int Integer used to initialize random state.

Source code in smac/random_design/annealing_design.py
def __init__(self, min_probability: float, max_probability: float, restart_iteration: int, seed: int = 0):
    super().__init__(seed)
    assert 0 <= min_probability <= 1
    assert 0 <= max_probability <= 1
    assert max_probability > min_probability
    assert restart_iteration > 2
    self._max_probability = max_probability
    self._min_probability = min_probability

    # Internally, iteration indices start at 0, so we need to decrease this
    self._restart_iteration = restart_iteration - 1
    self._iteration = 0
    self._probability = max_probability

next_iteration #

next_iteration() -> None

Moves to the next iteration and set self._probability.

Source code in smac/random_design/annealing_design.py
def next_iteration(self) -> None:  # noqa: D102
    """Moves to the next iteration and set ``self._probability``."""
    self._iteration += 1
    if self._iteration > self._restart_iteration:
        self._iteration = 0
        logger.debug("Perform a restart.")

    self._probability = self._min_probability + (
        0.5
        * (self._max_probability - self._min_probability)
        * (1 + np.cos(self._iteration * np.pi / self._restart_iteration))
    )
    logger.debug(f"Probability for random configs: {self._probability}")