Skip to content

Local search

LocalSearch #

LocalSearch(
    configspace: ConfigurationSpace,
    acquisition_function: (
        AbstractAcquisitionFunction | None
    ) = None,
    challengers: int = 5000,
    max_steps: int | None = None,
    n_steps_plateau_walk: int = 10,
    vectorization_min_obtain: int = 2,
    vectorization_max_obtain: int = 64,
    seed: int = 0,
)

Bases: AbstractAcquisitionMaximizer

Implementation of SMAC's local search.

Parameters#

configspace : ConfigurationSpace acquisition_function : AbstractAcquisitionFunction challengers : int, defaults to 5000 Number of challengers. max_steps: int | None, defaults to None Maximum number of iterations that the local search will perform. n_steps_plateau_walk: int, defaults to 10 Number of steps during a plateau walk before local search terminates. vectorization_min_obtain : int, defaults to 2 Minimal number of neighbors to obtain at once for each local search for vectorized calls. Can be tuned to reduce the overhead of SMAC. vectorization_max_obtain : int, defaults to 64 Maximal number of neighbors to obtain at once for each local search for vectorized calls. Can be tuned to reduce the overhead of SMAC. seed : int, defaults to 0

Source code in smac/acquisition/maximizer/local_search.py
def __init__(
    self,
    configspace: ConfigurationSpace,
    acquisition_function: AbstractAcquisitionFunction | None = None,
    challengers: int = 5000,
    max_steps: int | None = None,
    n_steps_plateau_walk: int = 10,
    vectorization_min_obtain: int = 2,
    vectorization_max_obtain: int = 64,
    seed: int = 0,
) -> None:
    super().__init__(
        configspace,
        acquisition_function,
        challengers=challengers,
        seed=seed,
    )

    self._max_steps = max_steps
    self._n_steps_plateau_walk = n_steps_plateau_walk
    self._vectorization_min_obtain = vectorization_min_obtain
    self._vectorization_max_obtain = vectorization_max_obtain

acquisition_function property writable #

acquisition_function: AbstractAcquisitionFunction | None

The acquisition function used for maximization.

maximize #

maximize(
    previous_configs: list[Configuration],
    n_points: int | None = None,
    random_design: AbstractRandomDesign | None = None,
) -> Iterator[Configuration]

Maximize acquisition function using _maximize, implemented by a subclass.

Parameters#

previous_configs: list[Configuration] Previous evaluated configurations. n_points: int, defaults to None Number of points to be sampled & number of configurations to be returned. If n_points is not specified, self._challengers is used. Semantics depend on concrete implementation. random_design: AbstractRandomDesign, defaults to None Part of the returned ChallengerList such that we can interleave random configurations by a scheme defined by the random design. The method random_design.next_iteration() is called at the end of this function.

Returns#

challengers : Iterator[Configuration] An iterable consisting of configurations.

Source code in smac/acquisition/maximizer/abstract_acquisition_maximizer.py
def maximize(
    self,
    previous_configs: list[Configuration],
    n_points: int | None = None,
    random_design: AbstractRandomDesign | None = None,
) -> Iterator[Configuration]:
    """Maximize acquisition function using `_maximize`, implemented by a subclass.

    Parameters
    ----------
    previous_configs: list[Configuration]
        Previous evaluated configurations.
    n_points: int, defaults to None
        Number of points to be sampled & number of configurations to be returned. If `n_points` is not specified,
        `self._challengers` is used. Semantics depend on concrete implementation.
    random_design: AbstractRandomDesign, defaults to None
        Part of the returned ChallengerList such that we can interleave random configurations
        by a scheme defined by the random design. The method `random_design.next_iteration()`
        is called at the end of this function.

    Returns
    -------
    challengers : Iterator[Configuration]
        An iterable consisting of configurations.
    """
    if n_points is None:
        n_points = self._challengers

    def next_configs_by_acquisition_value() -> list[Configuration]:
        assert n_points is not None
        # since maximize returns a tuple of acquisition value and configuration,
        # and we only need the configuration, we return the second element of the tuple
        # for each element in the list
        return [t[1] for t in self._maximize(previous_configs, n_points)]

    challengers = ChallengerList(
        self._configspace,
        next_configs_by_acquisition_value,
        random_design,
    )

    if random_design is not None:
        random_design.next_iteration()

    return challengers