跳到内容

预期提升

smac.acquisition.function.expected_improvement #

EI #

EI(xi: float = 0.0, log: bool = False)

基类: AbstractAcquisitionFunction

预期提升 (EI) 准则用于决定下一步在何处评估函数 f(x)。目标是平衡探索与利用。预期提升(无论函数值是否在对数空间)采集函数

:math:EI(X) := \mathbb{E}\left[ \max\{0, f(\mathbf{X^+}) - f_{t+1}(\mathbf{X}) - \xi \} \right],其中 :math:f(X^+) 是最佳位置。

EI 参考文献:Jones, D.R. and Schonlau, M. and Welch, W.J. (1998). Efficient Global Optimization of Expensive Black-Box Functions. Journal of Global Optimization 13, 455–492

logEI 参考文献:Hutter, F. and Hoos, H. and Leyton-Brown, K. and Murphy, K. (2009). An experimental investigation of model-based parameter optimisation: SPO and beyond. In: Conference on Genetic and Evolutionary Computation

logEI 的实现基于原始方程的推导:Watanabe, S. (2024). Derivation of Closed Form of Expected Improvement for Gaussian Process Trained on Log-Transformed Objective. arxiv.org/abs/2411.18095

参数#

xi : float, 默认为 0.0 控制采集函数的探索与利用之间的平衡。 log : bool, 默认为 False 函数值是否在对数空间中。

属性#

_xi : float 探索-利用权衡参数。 _log: bool 函数值是否在对数空间中。 _eta : float 当前最优函数值(迄今观察到的最佳值)。

源代码位于 smac/acquisition/function/expected_improvement.py
def __init__(
    self,
    xi: float = 0.0,
    log: bool = False,
) -> None:
    super(EI, self).__init__()

    self._xi: float = xi
    self._log: bool = log
    self._eta: float | None = None

model property writable #

model: AbstractModel | None

返回采集函数中使用的代理模型。

__call__ #

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

计算给定配置的采集值。

参数#

configurations : list[Configuration] 应评估采集函数的配置。

返回值#

np.ndarray [N, 1] X 的采集值

源代码位于 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

更新计算所需的采集函数属性。

此方法将在拟合模型后但在最大化采集函数之前调用。例如,EI 使用它来更新当前的 fmin。默认实现仅更新采集函数中已存在的属性。

调用 _update 更新采集函数属性。

参数#

model : AbstractModel 用于拟合数据的模型。 kwargs : Any 更新特定采集函数的附加参数。

源代码位于 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)

EIPS #

EIPS(xi: float = 0.0)

基类: EI

每秒预期提升采集函数

:math:EI(X) := \frac{\mathbb{E}\left[\max\{0,f(\mathbf{X^+})-f_{t+1}(\mathbf{X})-\xi\right]\}]}{np.log(r(x))},其中 :math:f(X^+) 是最佳位置,:math:r(x) 是运行时。

参数#

xi : float, 默认为 0.0 控制采集函数的探索与利用之间的平衡。

源代码位于 smac/acquisition/function/expected_improvement.py
def __init__(self, xi: float = 0.0) -> None:
    super(EIPS, self).__init__(xi=xi)

model property writable #

model: AbstractModel | None

返回采集函数中使用的代理模型。

__call__ #

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

计算给定配置的采集值。

参数#

configurations : list[Configuration] 应评估采集函数的配置。

返回值#

np.ndarray [N, 1] X 的采集值

源代码位于 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

更新计算所需的采集函数属性。

此方法将在拟合模型后但在最大化采集函数之前调用。例如,EI 使用它来更新当前的 fmin。默认实现仅更新采集函数中已存在的属性。

调用 _update 更新采集函数属性。

参数#

model : AbstractModel 用于拟合数据的模型。 kwargs : Any 更新特定采集函数的附加参数。

源代码位于 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)