跳到内容

汤普森

smac.acquisition.function.thompson #

TS #

TS()

继承自: AbstractAcquisitionFunction

汤普森采样

警告#

汤普森采样只能与 RandomSearch 一起使用。请不要使用 LocalAndSortedRandomSearch 来优化 TS 采集函数!

:math:`TS(X) ~ \mathcal{N}(\mu(\mathbf{X}),\sigma(\mathbf{X}))` 返回 -TS(X),以便采集函数优化器可以对其进行最大化。

参数#

xi : float,默认为 0.0。汤普森采样在这里不需要 xi,我们这样做只是为了与其他采集函数保持一致。

源代码位于 smac/acquisition/function/abstract_acquisition_function.py
def __init__(self) -> None:
    self._model: AbstractModel | None = None

meta property #

meta: dict[str, Any]

返回创建对象的元数据。

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)