Coverage for mlos_core/mlos_core/optimizers/random_optimizer.py: 100%
11 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-05 00:36 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-05 00:36 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Contains the RandomOptimizer class.
7"""
9from typing import Optional
11import pandas as pd
13from mlos_core.optimizers.optimizer import BaseOptimizer
16class RandomOptimizer(BaseOptimizer):
17 """Optimizer class that produces random suggestions.
18 Useful for baseline comparison against Bayesian optimizers.
20 Parameters
21 ----------
22 parameter_space : ConfigSpace.ConfigurationSpace
23 The parameter space to optimize.
24 """
26 def _register(self, configurations: pd.DataFrame, scores: pd.Series,
27 context: Optional[pd.DataFrame] = None) -> None:
28 """Registers the given configurations and scores.
30 Doesn't do anything on the RandomOptimizer except storing configurations for logging.
32 Parameters
33 ----------
34 configurations : pd.DataFrame
35 Dataframe of configurations / parameters. The columns are parameter names and the rows are the configurations.
37 scores : pd.Series
38 Scores from running the configurations. The index is the same as the index of the configurations.
40 context : None
41 Not Yet Implemented.
42 """
43 if context is not None:
44 raise NotImplementedError()
45 # should we pop them from self.pending_observations?
47 def _suggest(self, context: Optional[pd.DataFrame] = None) -> pd.DataFrame:
48 """Suggests a new configuration.
50 Sampled at random using ConfigSpace.
52 Parameters
53 ----------
54 context : None
55 Not Yet Implemented.
57 Returns
58 -------
59 configuration : pd.DataFrame
60 Pandas dataframe with a single row. Column names are the parameter names.
61 """
62 if context is not None:
63 # not sure how that works here?
64 raise NotImplementedError()
65 return pd.DataFrame(dict(self.optimizer_parameter_space.sample_configuration()), index=[0])
67 def register_pending(self, configurations: pd.DataFrame,
68 context: Optional[pd.DataFrame] = None) -> None:
69 raise NotImplementedError()
70 # self._pending_observations.append((configurations, context))