mlos_core.optimizers.optimizer
.BaseOptimizer¶
- class mlos_core.optimizers.optimizer.BaseOptimizer(*, parameter_space: ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: BaseSpaceAdapter | None = None)¶
Optimizer abstract base class defining the basic interface.
- Attributes:
space_adapter
Get the space adapter instance (if any).
Methods
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).
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.
- __init__(*, parameter_space: ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: BaseSpaceAdapter | None = None)¶
Create a new instance of the base optimizer.
- 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.
- cleanup() None ¶
Remove temp files, release resources, etc.
after use. Default is no-op. Redefine this method in optimizers that require cleanup.
- get_best_observations(*, n_max: int = 1) Tuple[DataFrame, DataFrame, DataFrame | None] ¶
Get the N best observations so far as a triplet of DataFrames (config, score, context). Default is N=1. The columns are ordered in ASCENDING order of the optimization targets. The function uses pandas.DataFrame.nsmallest(…, keep=”first”) method under the hood.
- Parameters:
- n_maxint
Maximum number of best observations to return. Default is 1.
- Returns:
- observationsTuple[pd.DataFrame, pd.DataFrame, Optional[pd.DataFrame]]
A triplet of best (config, score, context) DataFrames of best observations.
- get_observations() Tuple[DataFrame, DataFrame, DataFrame | None] ¶
Returns the observations as a triplet of DataFrames (config, score, context).
- Returns:
- observationsTuple[pd.DataFrame, pd.DataFrame, Optional[pd.DataFrame]]
A triplet of (config, score, context) DataFrames of observations.
- register(*, configs: DataFrame, scores: DataFrame, context: DataFrame | None = None, metadata: DataFrame | None = None) None ¶
Wrapper method, which employs the space adapter (if any), before registering the configs and scores.
- Parameters:
- configspd.DataFrame
Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.
- scorespd.DataFrame
Scores from running the configs. The index is the same as the index of the configs.
- contextpd.DataFrame
Not Yet Implemented.
- metadataOptional[pd.DataFrame]
Metadata returned by the backend optimizer’s suggest method.
- abstract 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.
- property space_adapter: BaseSpaceAdapter | None¶
Get the space adapter instance (if any).
- suggest(*, context: DataFrame | None = None, defaults: bool = False) Tuple[DataFrame, DataFrame | None] ¶
Wrapper method, which employs the space adapter (if any), after suggesting a new configuration.
- Parameters:
- contextpd.DataFrame
Not Yet Implemented.
- defaultsbool
Whether or not to return the default config instead of an optimizer guided one. By default, use the one from the optimizer.
- Returns:
- configurationpd.DataFrame
Pandas dataframe with a single row. Column names are the parameter names.
- metadataOptional[pd.DataFrame]
The metadata associated with the given configuration used for evaluations. Backend optimizer specific.