1
|
|
|
# Author: Simon Blanke |
2
|
|
|
# Email: [email protected] |
3
|
|
|
# License: MIT License |
4
|
|
|
|
5
|
|
|
from typing import List, Dict, Literal, Union |
6
|
|
|
|
7
|
|
|
from ..search import Search |
8
|
|
|
from ..optimizers import LipschitzOptimizer as _LipschitzOptimizer |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class LipschitzOptimizer(_LipschitzOptimizer, Search): |
12
|
|
|
""" |
13
|
|
|
A class implementing the **lipschitz optimizer** for the public API. |
14
|
|
|
Inheriting from the `Search`-class to get the `search`-method and from |
15
|
|
|
the `LipschitzOptimizer`-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
|
|
|
""" |
43
|
|
|
|
44
|
|
|
def __init__( |
45
|
|
|
self, |
46
|
|
|
search_space: Dict[str, list], |
47
|
|
|
initialize: Dict[ |
48
|
|
|
Literal["grid", "vertices", "random", "warm_start"], |
49
|
|
|
Union[int, list[dict]], |
50
|
|
|
] = {"grid": 4, "random": 2, "vertices": 4}, |
51
|
|
|
constraints: List[callable] = [], |
52
|
|
|
random_state: int = None, |
53
|
|
|
rand_rest_p: float = 0, |
54
|
|
|
nth_process: int = None, |
55
|
|
|
warm_start_smbo=None, |
56
|
|
|
max_sample_size: int = 10000000, |
57
|
|
|
sampling: Dict[Literal["random"], int] = {"random": 1000000}, |
58
|
|
|
replacement: bool = True, |
59
|
|
|
): |
60
|
|
|
super().__init__( |
61
|
|
|
search_space=search_space, |
62
|
|
|
initialize=initialize, |
63
|
|
|
constraints=constraints, |
64
|
|
|
random_state=random_state, |
65
|
|
|
rand_rest_p=rand_rest_p, |
66
|
|
|
nth_process=nth_process, |
67
|
|
|
warm_start_smbo=warm_start_smbo, |
68
|
|
|
max_sample_size=max_sample_size, |
69
|
|
|
sampling=sampling, |
70
|
|
|
replacement=replacement, |
71
|
|
|
) |
72
|
|
|
|