跳到内容

置信区间

smac.acquisition.function.confidence_bound #

LCB #

LCB(beta: float = 1.0)

基类:抽象获取函数

计算给定 x 的下置信界作为获取值,相对于目前为止的最佳值。

:math:LCB(X) = \mu(\mathbf{X}) - \sqrt(\beta_t)\sigma(\mathbf{X}) [SKKS10]

其中

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

:math:\text{输入空间} D :math:\text{输入维度数} |D| :math:\text{数据点数} t :math:\text{探索/利用权衡} \beta

返回 -LCB(X) 作为获取值,因为 acquisition_function 优化器会最大化获取值。

参数#

beta : float, 默认为 1.0 控制获取函数探索与利用之间的平衡。

属性#

_beta : float 探索-利用权衡参数。_num_data : int 目前为止已见数据点数。

源代码位于 smac/acquisition/function/confidence_bound.py
def __init__(self, beta: float = 1.0) -> None:
    super(LCB, self).__init__()
    self._beta: float = beta
    self._num_data: int | 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)