跳到内容

逆尺度编码器

smac.runhistory.encoder.inverse_scaled_encoder #

RunHistoryInverseScaledEncoder #

RunHistoryInverseScaledEncoder(*args: Any, **kwargs: Any)

基类:RunHistoryEncoder

源代码位于 smac/runhistory/encoder/inverse_scaled_encoder.py
def __init__(self, *args: Any, **kwargs: Any) -> None:
    super().__init__(*args, **kwargs)
    if self._instances is not None and len(self._instances) > 1:
        raise NotImplementedError("Handling more than one instance is not supported for inverse scaled cost.")

meta 属性 可写 #

meta: dict[str, Any]

返回创建的对象的元数据。

返回#

dict[str, Any]:创建的对象的元数据:名称、考虑的状态、较低预算的状态、scale_percentage、seed。

multi_objective_algorithm 属性 可写 #

multi_objective_algorithm: AbstractMultiObjectiveAlgorithm | None

用于转换数据的多目标算法。

runhistory 属性 可写 #

runhistory: RunHistory

用于转换数据的运行历史 (RunHistory)。

get_configurations #

get_configurations(
    budget_subset: list | None = None,
) -> ndarray

返回配置的向量表示。

警告#

实例特征未附加,且成本值未考虑在内。

参数#

budget_subset : list[int|float] | None,默认为 None 要考虑的预算列表。

返回#

configs_array : np.ndarray

源代码位于 smac/runhistory/encoder/abstract_encoder.py
def get_configurations(
    self,
    budget_subset: list | None = None,
) -> np.ndarray:
    """Returns vector representation of the configurations.

    Warning
    -------
    Instance features are not
    appended and cost values are not taken into account.

    Parameters
    ----------
    budget_subset : list[int|float] | None, defaults to none
        List of budgets to consider.

    Returns
    -------
    configs_array : np.ndarray
    """
    s_trials = self._get_considered_trials(budget_subset)
    s_config_ids = set(s_trial.config_id for s_trial in s_trials)
    t_trials = self._get_timeout_trials(budget_subset)
    t_config_ids = set(t_trial.config_id for t_trial in t_trials)
    config_ids = s_config_ids | t_config_ids
    configurations = [self.runhistory._ids_config[config_id] for config_id in config_ids]
    configs_array = convert_configurations_to_array(configurations)

    return configs_array

transform #

transform(
    budget_subset: list | None = None,
) -> tuple[ndarray, ndarray]

返回 RunHistory 的向量表示。

参数#

budget_subset : list | None,默认为 None 要考虑的预算列表。

返回#

X : np.ndarray 配置向量和实例特征。 Y : np.ndarray 成本值。

源代码位于 smac/runhistory/encoder/abstract_encoder.py
def transform(
    self,
    budget_subset: list | None = None,
) -> tuple[np.ndarray, np.ndarray]:
    """Returns a vector representation of the RunHistory.

    Parameters
    ----------
    budget_subset : list | None, defaults to none
        List of budgets to consider.

    Returns
    -------
    X : np.ndarray
        Configuration vector and instance features.
    Y : np.ndarray
        Cost values.
    """
    logger.debug("Transforming RunHistory into X, y format...")

    considered_trials = self._get_considered_trials(budget_subset)
    X, Y = self._build_matrix(trials=considered_trials, store_statistics=True)

    # Get real TIMEOUT runs
    timeout_trials = self._get_timeout_trials(budget_subset)

    # Use penalization (e.g. PAR10) for EPM training
    store_statistics = True if np.any(np.isnan(self._min_y)) else False
    tX, tY = self._build_matrix(trials=timeout_trials, store_statistics=store_statistics)

    # If we don't have successful runs, we have to return all timeout runs
    if not considered_trials:
        return tX, tY

    # If we do not impute, we also return TIMEOUT data
    X = np.vstack((X, tX))
    Y = np.concatenate((Y, tY))

    logger.debug("Converted %d observations." % (X.shape[0]))
    return X, Y

transform_response_values #

transform_response_values(values: ndarray) -> ndarray

通过将响应值线性缩放到零到一之间,然后使用逆尺度转换它们。

源代码位于 smac/runhistory/encoder/inverse_scaled_encoder.py
def transform_response_values(self, values: np.ndarray) -> np.ndarray:
    """Transform the response values by linearly scaling
    them between zero and one and then use inverse scaling.
    """
    min_y = self._min_y - (
        self._percentile - self._min_y
    )  # Subtract the difference between the percentile and the minimum
    min_y -= constants.VERY_SMALL_NUMBER  # Minimal value to avoid numerical issues in the log scaling below
    # linear scaling
    # prevent diving by zero

    min_y[np.where(min_y == self._max_y)] *= 1 - 10**-10

    values = (values - min_y) / (self._max_y - min_y)
    values = 1 - 1 / values
    return values