mlos_core.optimizers.bayesian_optimizers.SmacOptimizer

class mlos_core.optimizers.bayesian_optimizers.SmacOptimizer(*, parameter_space: ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: BaseSpaceAdapter | None = None, seed: int | None = 0, run_name: str | None = None, output_directory: str | None = None, max_trials: int = 100, n_random_init: int | None = None, max_ratio: float | None = None, use_default_config: bool = False, n_random_probability: float = 0.1)

Wrapper class for SMAC based Bayesian optimization.

Attributes:
n_random_init

Gets the number of random samples to use to initialize the optimizer’s search space sampling.

space_adapter

Get the space adapter instance (if any).

Methods

acquisition_function(*, configs[, context])

Invokes the acquisition function from this Bayesian optimizer for the given configuration.

cleanup()

Remove temp files, release resources, etc.

get_best_observations(*[, n_max])

Get the N best observations so far as a triplet of DataFrames (config, score, context).

get_observations()

Returns the observations as a triplet of DataFrames (config, score, context).

register(*, configs, scores[, context, metadata])

Wrapper method, which employs the space adapter (if any), before registering the configs and scores.

register_pending(*, configs[, context, metadata])

Registers the given configs as "pending".

suggest(*[, context, defaults])

Wrapper method, which employs the space adapter (if any), after suggesting a new configuration.

surrogate_predict(*, configs[, context])

Obtain a prediction from this Bayesian optimizer's surrogate model for the given configuration(s).

__init__(*, parameter_space: ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: BaseSpaceAdapter | None = None, seed: int | None = 0, run_name: str | None = None, output_directory: str | None = None, max_trials: int = 100, n_random_init: int | None = None, max_ratio: float | None = None, use_default_config: bool = False, n_random_probability: float = 0.1)

Instantiate a new SMAC optimizer wrapper.

Parameters:
parameter_spaceConfigSpace.ConfigurationSpace

The parameter space to optimize.

optimization_targetsList[str]

The names of the optimization targets to minimize.

objective_weightsOptional[List[float]]

Optional list of weights of optimization targets.

space_adapterBaseSpaceAdapter

The space adapter class to employ for parameter space transformations.

seedOptional[int]

By default SMAC uses a known seed (0) to keep results reproducible. However, if a None seed is explicitly provided, we let a random seed be produced by SMAC.

run_nameOptional[str]

Name of this run. This is used to easily distinguish across different runs. If set to None (default), SMAC will generate a hash from metadata.

output_directoryOptional[str]

The directory where SMAC output will saved. If set to None (default), a temporary dir will be used.

max_trialsint

Maximum number of trials (i.e., function evaluations) to be run. Defaults to 100. Note that modifying this value directly affects the value of n_random_init, if latter is set to None.

n_random_initOptional[int]

Number of points evaluated at start to bootstrap the optimizer. Default depends on max_trials and number of parameters and max_ratio. Note: it can sometimes be useful to set this to 1 when pre-warming the optimizer from historical data. See Also: mlos_bench.optimizer.bulk_register

max_ratioOptional[int]

Maximum ratio of max_trials to be random configs to be evaluated at start to bootstrap the optimizer. Useful if you want to explicitly control the number of random configs evaluated at start.

use_default_config: bool

Whether to use the default config for the first trial after random initialization.

n_random_probability: float

Probability of choosing to evaluate a random configuration during optimization. Defaults to 0.1. Setting this to a higher value favors exploration over exploitation.

acquisition_function(*, configs: DataFrame, context: DataFrame | None = None) ndarray[Any, dtype[_ScalarType_co]]

Invokes the acquisition function from this Bayesian optimizer for the given configuration.

Parameters:
configspd.DataFrame

Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.

contextpd.DataFrame

Not Yet Implemented.

cleanup() None

Remove temp files, release resources, etc.

after use. Default is no-op. Redefine this method in optimizers that require cleanup.

property n_random_init: int

Gets the number of random samples to use to initialize the optimizer’s search space sampling.

Note: This may not be equal to the value passed to the initializer, due to logic present in the SMAC. See Also: max_ratio

Returns:
int

The number of random samples used to initialize the optimizer’s search space sampling.

register_pending(*, configs: DataFrame, context: DataFrame | None = None, metadata: DataFrame | None = None) None

Registers the given configs as “pending”. That is it say, it has been suggested by the optimizer, and an experiment trial has been started. This can be useful for executing multiple trials in parallel, retry logic, etc.

Parameters:
configspd.DataFrame

Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.

contextpd.DataFrame

Not Yet Implemented.

metadataOptional[pd.DataFrame]

Metadata returned by the backend optimizer’s suggest method.

surrogate_predict(*, configs: DataFrame, context: DataFrame | None = None) ndarray[Any, dtype[_ScalarType_co]]

Obtain a prediction from this Bayesian optimizer’s surrogate model for the given configuration(s).

Parameters:
configspd.DataFrame

Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.

contextpd.DataFrame

Not Yet Implemented.