| @@ 11-82 (lines=72) @@ | ||
| 8 | from ..optimizers import ForestOptimizer as _ForestOptimizer |
|
| 9 | ||
| 10 | ||
| 11 | class ForestOptimizer(_ForestOptimizer, Search): |
|
| 12 | """ |
|
| 13 | A class implementing the **forest optimizer** for the public API. |
|
| 14 | Inheriting from the `Search`-class to get the `search`-method and from |
|
| 15 | the `ForestOptimizer`-backend to get the underlying algorithm. |
|
| 16 | ||
| 17 | Parameters |
|
| 18 | ---------- |
|
| 19 | search_space : dict[str, list] |
|
| 20 | The search space to explore. A dictionary with parameter |
|
| 21 | names as keys and a numpy array as values. |
|
| 22 | initialize : dict[str, int] |
|
| 23 | The method to generate initial positions. A dictionary with |
|
| 24 | the following key literals and the corresponding value type: |
|
| 25 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
| 26 | constraints : list[callable] |
|
| 27 | A list of constraints, where each constraint is a callable. |
|
| 28 | The callable returns `True` or `False` dependend on the input parameters. |
|
| 29 | random_state : None, int |
|
| 30 | If None, create a new random state. If int, create a new random state |
|
| 31 | seeded with the value. |
|
| 32 | rand_rest_p : float |
|
| 33 | The probability of a random iteration during the the search process. |
|
| 34 | warm_start_smbo |
|
| 35 | The warm start for SMBO. |
|
| 36 | max_sample_size : int |
|
| 37 | The maximum number of points to sample. |
|
| 38 | sampling : dict |
|
| 39 | The sampling method to use. |
|
| 40 | replacement : bool |
|
| 41 | Whether to sample with replacement. |
|
| 42 | tree_regressor : str |
|
| 43 | The tree regressor model to use. |
|
| 44 | tree_para : dict |
|
| 45 | The model specific parameters for the tree regressor. |
|
| 46 | xi : float |
|
| 47 | The xi parameter for the tree regressor. |
|
| 48 | """ |
|
| 49 | ||
| 50 | def __init__( |
|
| 51 | self, |
|
| 52 | search_space: Dict[str, list], |
|
| 53 | initialize: Dict[ |
|
| 54 | Literal["grid", "vertices", "random", "warm_start"], |
|
| 55 | Union[int, list[dict]], |
|
| 56 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 57 | constraints: List[callable] = [], |
|
| 58 | random_state: int = None, |
|
| 59 | rand_rest_p: float = 0, |
|
| 60 | nth_process: int = None, |
|
| 61 | warm_start_smbo=None, |
|
| 62 | max_sample_size: int = 10000000, |
|
| 63 | sampling: Dict[Literal["random"], int] = {"random": 1000000}, |
|
| 64 | replacement: bool = True, |
|
| 65 | tree_regressor="extra_tree", |
|
| 66 | tree_para={"n_estimators": 100}, |
|
| 67 | xi=0.03, |
|
| 68 | ): |
|
| 69 | super().__init__( |
|
| 70 | search_space=search_space, |
|
| 71 | initialize=initialize, |
|
| 72 | constraints=constraints, |
|
| 73 | random_state=random_state, |
|
| 74 | rand_rest_p=rand_rest_p, |
|
| 75 | nth_process=nth_process, |
|
| 76 | warm_start_smbo=warm_start_smbo, |
|
| 77 | max_sample_size=max_sample_size, |
|
| 78 | sampling=sampling, |
|
| 79 | replacement=replacement, |
|
| 80 | tree_regressor=tree_regressor, |
|
| 81 | tree_para=tree_para, |
|
| 82 | xi=xi, |
|
| 83 | ) |
|
| 84 | ||
| @@ 12-79 (lines=68) @@ | ||
| 9 | from ..optimizers.smb_opt.bayesian_optimization import gaussian_process |
|
| 10 | ||
| 11 | ||
| 12 | class BayesianOptimizer(_BayesianOptimizer, Search): |
|
| 13 | """ |
|
| 14 | A class implementing the **bayesian optimizer** for the public API. |
|
| 15 | Inheriting from the `Search`-class to get the `search`-method and from |
|
| 16 | the `BayesianOptimizer`-backend to get the underlying algorithm. |
|
| 17 | ||
| 18 | Parameters |
|
| 19 | ---------- |
|
| 20 | search_space : dict[str, list] |
|
| 21 | The search space to explore. A dictionary with parameter |
|
| 22 | names as keys and a numpy array as values. |
|
| 23 | initialize : dict[str, int] |
|
| 24 | The method to generate initial positions. A dictionary with |
|
| 25 | the following key literals and the corresponding value type: |
|
| 26 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
| 27 | constraints : list[callable] |
|
| 28 | A list of constraints, where each constraint is a callable. |
|
| 29 | The callable returns `True` or `False` dependend on the input parameters. |
|
| 30 | random_state : None, int |
|
| 31 | If None, create a new random state. If int, create a new random state |
|
| 32 | seeded with the value. |
|
| 33 | rand_rest_p : float |
|
| 34 | The probability of a random iteration during the search process. |
|
| 35 | warm_start_smbo |
|
| 36 | The warm start for SMBO. |
|
| 37 | max_sample_size : int |
|
| 38 | The maximum number of points to sample. |
|
| 39 | sampling : dict |
|
| 40 | The sampling method to use. |
|
| 41 | replacement : bool |
|
| 42 | Whether to sample with replacement. |
|
| 43 | gpr : dict |
|
| 44 | The Gaussian Process Regressor to use. |
|
| 45 | xi : float |
|
| 46 | The exploration-exploitation trade-off parameter. |
|
| 47 | """ |
|
| 48 | ||
| 49 | def __init__( |
|
| 50 | self, |
|
| 51 | search_space: Dict[str, list], |
|
| 52 | initialize: Dict[ |
|
| 53 | Literal["grid", "vertices", "random", "warm_start"], |
|
| 54 | Union[int, list[dict]], |
|
| 55 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 56 | constraints: List[callable] = [], |
|
| 57 | random_state: int = None, |
|
| 58 | rand_rest_p: float = 0, |
|
| 59 | nth_process: int = None, |
|
| 60 | warm_start_smbo=None, |
|
| 61 | max_sample_size: int = 10000000, |
|
| 62 | sampling: Dict[Literal["random"], int] = {"random": 1000000}, |
|
| 63 | replacement: bool = True, |
|
| 64 | gpr=gaussian_process["gp_nonlinear"], |
|
| 65 | xi: float = 0.03, |
|
| 66 | ): |
|
| 67 | super().__init__( |
|
| 68 | search_space=search_space, |
|
| 69 | initialize=initialize, |
|
| 70 | constraints=constraints, |
|
| 71 | random_state=random_state, |
|
| 72 | rand_rest_p=rand_rest_p, |
|
| 73 | nth_process=nth_process, |
|
| 74 | warm_start_smbo=warm_start_smbo, |
|
| 75 | max_sample_size=max_sample_size, |
|
| 76 | sampling=sampling, |
|
| 77 | replacement=replacement, |
|
| 78 | gpr=gpr, |
|
| 79 | xi=xi, |
|
| 80 | ) |
|
| 81 | ||