Skip to content

Confidence bound

smac.acquisition.function.confidence_bound #

AbstractConfidenceBound #

AbstractConfidenceBound(
    beta: float = 1.0,
    nu: float = 1.0,
    update_beta: bool = True,
    beta_scaling_srinivas: bool = False,
)

Bases: AbstractAcquisitionFunction

Computes the lower or upper confidence bound for a given x over the best so far value as acquisition value.

Example for LCB (UCB adds the variance term instead of subtracting it):

\(LCB(X) = \mu(\mathbf{X}) - \sqrt{\beta_t}\sigma(\mathbf{X})\) SKKS10.

with

\(\beta_t = 2 \log( |D| t^2 / \beta)\) \(\text{Input space } D\)

\(\text{Number of input dimensions } |D|\)

\(\text{Number of data points } t\)

\(\text{Exploration/exploitation tradeoff } \beta\)

Returns -LCB(X) as the acquisition_function optimizer maximizes the acquisition value.

PARAMETER DESCRIPTION
beta

Controls the balance between exploration and exploitation of the acquisition function.

TYPE: float, defaults to 1.0 DEFAULT: 1.0

ATTRIBUTE DESCRIPTION
_beta

Exploration-exploitation trade-off parameter.

TYPE: float

_num_data

Number of data points seen so far.

TYPE: int

_bound_type

Type of Confidence Bound. Either UCB or LCB. Set in child class.

TYPE: str

_update_beta

Whether to update beta or not.

TYPE: bool

_beta_scaling_srinivas

Whether to use the beta scaling according to [0, 1].

TYPE: bool

References

[0] Srinivas, Niranjan, et al. "Gaussian process optimization in the bandit setting: No regret and experimental design." arXiv preprint arXiv:0912.3995 (2009). or not. [1] Makarova, Anastasia, et al. "Automatic Termination for Hyperparameter Optimization." First Conference on Automated Machine Learning (Main Track). 2022.

Source code in smac/acquisition/function/confidence_bound.py
def __init__(
    self, beta: float = 1.0, nu: float = 1.0, update_beta: bool = True, beta_scaling_srinivas: bool = False
) -> None:
    super(AbstractConfidenceBound, self).__init__()
    self._beta: float = beta
    self._nu: float = nu
    self._num_data: int | None = None
    self._update_beta = update_beta
    self._beta_scaling_srinivas = beta_scaling_srinivas

model property writable #

model: AbstractModel | None

Return the used surrogate model in the acquisition function.

__call__ #

__call__(configurations: list[Configuration]) -> ndarray

Compute the acquisition value for a given configuration.

PARAMETER DESCRIPTION
configurations

The configurations where the acquisition function should be evaluated.

TYPE: list[Configuration]

RETURNS DESCRIPTION
ndarray[N, 1]

Acquisition values for X

Source code in smac/acquisition/function/abstract_acquisition_function.py
def __call__(self, configurations: list[Configuration]) -> np.ndarray:
    """Compute the acquisition value for a given configuration.

    Parameters
    ----------
    configurations : list[Configuration]
        The configurations where the acquisition function should be evaluated.

    Returns
    -------
    np.ndarray [N, 1]
        Acquisition values for X
    """
    X = convert_configurations_to_array(configurations)
    if len(X.shape) == 1:
        X = X[np.newaxis, :]

    acq = self._compute(X)
    if np.any(np.isnan(acq)):
        idx = np.where(np.isnan(acq))[0]
        acq[idx, :] = -np.finfo(float).max

    return acq

update #

update(model: AbstractModel, **kwargs: Any) -> None

Update the acquisition function attributes required for calculation.

This method will be called after fitting the model, but before maximizing the acquisition function. As an examples, EI uses it to update the current fmin. The default implementation only updates the attributes of the acquisition function which are already present.

Calls _update to update the acquisition function attributes.

PARAMETER DESCRIPTION
model

The model which was used to fit the data.

TYPE: AbstractModel

kwargs

Additional arguments to update the specific acquisition function.

TYPE: Any DEFAULT: {}

Source code in smac/acquisition/function/abstract_acquisition_function.py
def update(self, model: AbstractModel, **kwargs: Any) -> None:
    """Update the acquisition function attributes required for calculation.

    This method will be called after fitting the model, but before maximizing the acquisition
    function. As an examples, EI uses it to update the current fmin. The default implementation only updates the
    attributes of the acquisition function which are already present.

    Calls `_update` to update the acquisition function attributes.

    Parameters
    ----------
    model : AbstractModel
        The model which was used to fit the data.
    kwargs : Any
        Additional arguments to update the specific acquisition function.
    """
    self.model = model
    self._update(**kwargs)

LCB #

LCB(
    beta: float = 1.0,
    nu: float = 1.0,
    update_beta: bool = True,
    beta_scaling_srinivas: bool = False,
)

Bases: AbstractConfidenceBound

Computes the lower confidence bound for a given x over the best so far value as acquisition value.

\(LCB(X) = \mu(\mathbf{X}) - \sqrt{\beta_t}\sigma(\mathbf{X})\) SKKS10.

with

\(\beta_t = 2 \log( |D| t^2 / \beta)\)

\(\text{Input space } D\)

\(\text{Number of input dimensions } |D|\)

\(\text{Number of data points } t\)

\(\text{Exploration/exploitation tradeoff } \beta\)

Returns -LCB(X) as the acquisition_function optimizer maximizes the acquisition value.

PARAMETER DESCRIPTION
beta

Controls the balance between exploration and exploitation of the acquisition function.

TYPE: float, defaults to 1.0 DEFAULT: 1.0

ATTRIBUTE DESCRIPTION
_beta

Exploration-exploitation trade-off parameter.

TYPE: float

_num_data

Number of data points seen so far.

TYPE: int

_bound_type

Type of Confidence Bound. Either UCB or LCB.

TYPE: str

Source code in smac/acquisition/function/confidence_bound.py
def __init__(
    self, beta: float = 1.0, nu: float = 1.0, update_beta: bool = True, beta_scaling_srinivas: bool = False
) -> None:
    super(AbstractConfidenceBound, self).__init__()
    self._beta: float = beta
    self._nu: float = nu
    self._num_data: int | None = None
    self._update_beta = update_beta
    self._beta_scaling_srinivas = beta_scaling_srinivas

model property writable #

model: AbstractModel | None

Return the used surrogate model in the acquisition function.

__call__ #

__call__(configurations: list[Configuration]) -> ndarray

Compute the acquisition value for a given configuration.

PARAMETER DESCRIPTION
configurations

The configurations where the acquisition function should be evaluated.

TYPE: list[Configuration]

RETURNS DESCRIPTION
ndarray[N, 1]

Acquisition values for X

Source code in smac/acquisition/function/abstract_acquisition_function.py
def __call__(self, configurations: list[Configuration]) -> np.ndarray:
    """Compute the acquisition value for a given configuration.

    Parameters
    ----------
    configurations : list[Configuration]
        The configurations where the acquisition function should be evaluated.

    Returns
    -------
    np.ndarray [N, 1]
        Acquisition values for X
    """
    X = convert_configurations_to_array(configurations)
    if len(X.shape) == 1:
        X = X[np.newaxis, :]

    acq = self._compute(X)
    if np.any(np.isnan(acq)):
        idx = np.where(np.isnan(acq))[0]
        acq[idx, :] = -np.finfo(float).max

    return acq

update #

update(model: AbstractModel, **kwargs: Any) -> None

Update the acquisition function attributes required for calculation.

This method will be called after fitting the model, but before maximizing the acquisition function. As an examples, EI uses it to update the current fmin. The default implementation only updates the attributes of the acquisition function which are already present.

Calls _update to update the acquisition function attributes.

PARAMETER DESCRIPTION
model

The model which was used to fit the data.

TYPE: AbstractModel

kwargs

Additional arguments to update the specific acquisition function.

TYPE: Any DEFAULT: {}

Source code in smac/acquisition/function/abstract_acquisition_function.py
def update(self, model: AbstractModel, **kwargs: Any) -> None:
    """Update the acquisition function attributes required for calculation.

    This method will be called after fitting the model, but before maximizing the acquisition
    function. As an examples, EI uses it to update the current fmin. The default implementation only updates the
    attributes of the acquisition function which are already present.

    Calls `_update` to update the acquisition function attributes.

    Parameters
    ----------
    model : AbstractModel
        The model which was used to fit the data.
    kwargs : Any
        Additional arguments to update the specific acquisition function.
    """
    self.model = model
    self._update(**kwargs)

UCB #

UCB(
    beta: float = 1.0,
    nu: float = 1.0,
    update_beta: bool = True,
    beta_scaling_srinivas: bool = False,
)

Bases: AbstractConfidenceBound

Computes the upper confidence bound for a given x over the best so far value as acquisition value.

\(UCB(X) = \mu(\mathbf{X}) + \sqrt{\beta_t}\sigma(\mathbf{X})\) SKKS10.

with

\(\beta_t = 2 \log( |D| t^2 / \beta)\)

\(\text{Input space } D\)

\(\text{Number of input dimensions } |D|\)

\(\text{Number of data points } t\)

\(\text{Exploration/exploitation tradeoff } \beta\)

Returns -UCB(X) as the acquisition_function optimizer maximizes the acquisition value.

PARAMETER DESCRIPTION
beta

Controls the balance between exploration and exploitation of the acquisition function.

TYPE: float, defaults to 1.0 DEFAULT: 1.0

ATTRIBUTE DESCRIPTION
_beta

Exploration-exploitation trade-off parameter.

TYPE: float

_num_data

Number of data points seen so far.

TYPE: int

_bound_type

Type of Confidence Bound. Either UCB or LCB.

TYPE: str

Source code in smac/acquisition/function/confidence_bound.py
def __init__(
    self, beta: float = 1.0, nu: float = 1.0, update_beta: bool = True, beta_scaling_srinivas: bool = False
) -> None:
    super(AbstractConfidenceBound, self).__init__()
    self._beta: float = beta
    self._nu: float = nu
    self._num_data: int | None = None
    self._update_beta = update_beta
    self._beta_scaling_srinivas = beta_scaling_srinivas

model property writable #

model: AbstractModel | None

Return the used surrogate model in the acquisition function.

__call__ #

__call__(configurations: list[Configuration]) -> ndarray

Compute the acquisition value for a given configuration.

PARAMETER DESCRIPTION
configurations

The configurations where the acquisition function should be evaluated.

TYPE: list[Configuration]

RETURNS DESCRIPTION
ndarray[N, 1]

Acquisition values for X

Source code in smac/acquisition/function/abstract_acquisition_function.py
def __call__(self, configurations: list[Configuration]) -> np.ndarray:
    """Compute the acquisition value for a given configuration.

    Parameters
    ----------
    configurations : list[Configuration]
        The configurations where the acquisition function should be evaluated.

    Returns
    -------
    np.ndarray [N, 1]
        Acquisition values for X
    """
    X = convert_configurations_to_array(configurations)
    if len(X.shape) == 1:
        X = X[np.newaxis, :]

    acq = self._compute(X)
    if np.any(np.isnan(acq)):
        idx = np.where(np.isnan(acq))[0]
        acq[idx, :] = -np.finfo(float).max

    return acq

update #

update(model: AbstractModel, **kwargs: Any) -> None

Update the acquisition function attributes required for calculation.

This method will be called after fitting the model, but before maximizing the acquisition function. As an examples, EI uses it to update the current fmin. The default implementation only updates the attributes of the acquisition function which are already present.

Calls _update to update the acquisition function attributes.

PARAMETER DESCRIPTION
model

The model which was used to fit the data.

TYPE: AbstractModel

kwargs

Additional arguments to update the specific acquisition function.

TYPE: Any DEFAULT: {}

Source code in smac/acquisition/function/abstract_acquisition_function.py
def update(self, model: AbstractModel, **kwargs: Any) -> None:
    """Update the acquisition function attributes required for calculation.

    This method will be called after fitting the model, but before maximizing the acquisition
    function. As an examples, EI uses it to update the current fmin. The default implementation only updates the
    attributes of the acquisition function which are already present.

    Calls `_update` to update the acquisition function attributes.

    Parameters
    ----------
    model : AbstractModel
        The model which was used to fit the data.
    kwargs : Any
        Additional arguments to update the specific acquisition function.
    """
    self.model = model
    self._update(**kwargs)