@@ 13-79 (lines=67) @@ | ||
10 | ) |
|
11 | ||
12 | ||
13 | class SimulatedAnnealingOptimizer(_SimulatedAnnealingOptimizer, Search): |
|
14 | """ |
|
15 | A class implementing **simulated annealing** for the public API. |
|
16 | Inheriting from the `Search`-class to get the `search`-method and from |
|
17 | the `SimulatedAnnealingOptimizer`-backend to get the underlying algorithm. |
|
18 | ||
19 | Parameters |
|
20 | ---------- |
|
21 | search_space : dict[str, list] |
|
22 | The search space to explore. A dictionary with parameter |
|
23 | names as keys and a numpy array as values. |
|
24 | initialize : dict[str, int] |
|
25 | The method to generate initial positions. A dictionary with |
|
26 | the following key literals and the corresponding value type: |
|
27 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
28 | constraints : list[callable] |
|
29 | A list of constraints, where each constraint is a callable. |
|
30 | The callable returns `True` or `False` dependend on the input parameters. |
|
31 | random_state : None, int |
|
32 | If None, create a new random state. If int, create a new random state |
|
33 | seeded with the value. |
|
34 | rand_rest_p : float |
|
35 | The probability of a random iteration during the the search process. |
|
36 | epsilon : float |
|
37 | The step-size for the climbing. |
|
38 | distribution : str |
|
39 | The type of distribution to sample from. |
|
40 | n_neighbours : int |
|
41 | The number of neighbours to sample and evaluate before moving to the best |
|
42 | of those neighbours. |
|
43 | annealing_rate : float |
|
44 | The rate at which the temperature is annealed. |
|
45 | start_temp : float |
|
46 | The initial temperature. |
|
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 | epsilon: float = 0.03, |
|
61 | distribution: Literal[ |
|
62 | "normal", "laplace", "gumbel", "logistic" |
|
63 | ] = "normal", |
|
64 | n_neighbours: int = 3, |
|
65 | annealing_rate: float = 0.97, |
|
66 | start_temp: float = 1, |
|
67 | ): |
|
68 | super().__init__( |
|
69 | search_space=search_space, |
|
70 | initialize=initialize, |
|
71 | constraints=constraints, |
|
72 | random_state=random_state, |
|
73 | rand_rest_p=rand_rest_p, |
|
74 | nth_process=nth_process, |
|
75 | epsilon=epsilon, |
|
76 | distribution=distribution, |
|
77 | n_neighbours=n_neighbours, |
|
78 | annealing_rate=annealing_rate, |
|
79 | start_temp=start_temp, |
|
80 | ) |
|
81 |
@@ 11-77 (lines=67) @@ | ||
8 | from ..optimizers import RandomAnnealingOptimizer as _RandomAnnealingOptimizer |
|
9 | ||
10 | ||
11 | class RandomAnnealingOptimizer(_RandomAnnealingOptimizer, Search): |
|
12 | """ |
|
13 | A class implementing **random annealing** for the public API. |
|
14 | Inheriting from the `Search`-class to get the `search`-method and from |
|
15 | the `RandomAnnealingOptimizer`-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 search process. |
|
34 | epsilon : float |
|
35 | The step-size for the climbing. |
|
36 | distribution : str |
|
37 | The type of distribution to sample from. |
|
38 | n_neighbours : int |
|
39 | The number of neighbours to sample and evaluate before moving to the best |
|
40 | of those neighbours. |
|
41 | annealing_rate : float |
|
42 | The annealing rate for the temperature. |
|
43 | start_temp : float |
|
44 | The initial temperature. |
|
45 | """ |
|
46 | ||
47 | def __init__( |
|
48 | self, |
|
49 | search_space: Dict[str, list], |
|
50 | initialize: Dict[ |
|
51 | Literal["grid", "vertices", "random", "warm_start"], |
|
52 | Union[int, list[dict]], |
|
53 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
54 | constraints: List[callable] = [], |
|
55 | random_state: int = None, |
|
56 | rand_rest_p: float = 0, |
|
57 | nth_process: int = None, |
|
58 | epsilon: float = 0.03, |
|
59 | distribution: Literal[ |
|
60 | "normal", "laplace", "gumbel", "logistic" |
|
61 | ] = "normal", |
|
62 | n_neighbours: int = 3, |
|
63 | annealing_rate=0.98, |
|
64 | start_temp=10, |
|
65 | ): |
|
66 | super().__init__( |
|
67 | search_space=search_space, |
|
68 | initialize=initialize, |
|
69 | constraints=constraints, |
|
70 | random_state=random_state, |
|
71 | rand_rest_p=rand_rest_p, |
|
72 | nth_process=nth_process, |
|
73 | epsilon=epsilon, |
|
74 | distribution=distribution, |
|
75 | n_neighbours=n_neighbours, |
|
76 | annealing_rate=annealing_rate, |
|
77 | start_temp=start_temp, |
|
78 | ) |
|
79 |
@@ 13-77 (lines=65) @@ | ||
10 | ) |
|
11 | ||
12 | ||
13 | class RandomRestartHillClimbingOptimizer( |
|
14 | _RandomRestartHillClimbingOptimizer, Search |
|
15 | ): |
|
16 | """ |
|
17 | A class implementing the **random restart hill climbing optimizer** for the public API. |
|
18 | Inheriting from the `Search`-class to get the `search`-method and from |
|
19 | the `RandomRestartHillClimbingOptimizer`-backend to get the underlying algorithm. |
|
20 | ||
21 | Parameters |
|
22 | ---------- |
|
23 | search_space : dict[str, list] |
|
24 | The search space to explore. A dictionary with parameter |
|
25 | names as keys and a numpy array as values. |
|
26 | initialize : dict[str, int] |
|
27 | The method to generate initial positions. A dictionary with |
|
28 | the following key literals and the corresponding value type: |
|
29 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
30 | constraints : list[callable] |
|
31 | A list of constraints, where each constraint is a callable. |
|
32 | The callable returns `True` or `False` dependend on the input parameters. |
|
33 | random_state : None, int |
|
34 | If None, create a new random state. If int, create a new random state |
|
35 | seeded with the value. |
|
36 | rand_rest_p : float |
|
37 | The probability of a random iteration during the the search process. |
|
38 | epsilon : float |
|
39 | The step-size for the climbing. |
|
40 | distribution : str |
|
41 | The type of distribution to sample from. |
|
42 | n_neighbours : int |
|
43 | The number of neighbours to sample and evaluate before moving to the best |
|
44 | of those neighbours. |
|
45 | n_iter_restart : int |
|
46 | The number of iterations after which to restart at a random position. |
|
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 | epsilon: float = 0.03, |
|
61 | distribution: Literal[ |
|
62 | "normal", "laplace", "gumbel", "logistic" |
|
63 | ] = "normal", |
|
64 | n_neighbours: int = 3, |
|
65 | n_iter_restart: int = 10, |
|
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 | epsilon=epsilon, |
|
75 | distribution=distribution, |
|
76 | n_neighbours=n_neighbours, |
|
77 | n_iter_restart=n_iter_restart, |
|
78 | ) |
|
79 |
@@ 13-75 (lines=63) @@ | ||
10 | ) |
|
11 | ||
12 | ||
13 | class RepulsingHillClimbingOptimizer(_RepulsingHillClimbingOptimizer, Search): |
|
14 | """ |
|
15 | A class implementing the **repulsing hill climbing optimizer** for the public API. |
|
16 | Inheriting from the `Search`-class to get the `search`-method and from |
|
17 | the `RepulsingHillClimbingOptimizer`-backend to get the underlying algorithm. |
|
18 | ||
19 | Parameters |
|
20 | ---------- |
|
21 | search_space : dict[str, list] |
|
22 | The search space to explore. A dictionary with parameter |
|
23 | names as keys and a numpy array as values. |
|
24 | initialize : dict[str, int] |
|
25 | The method to generate initial positions. A dictionary with |
|
26 | the following key literals and the corresponding value type: |
|
27 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
28 | constraints : list[callable] |
|
29 | A list of constraints, where each constraint is a callable. |
|
30 | The callable returns `True` or `False` dependend on the input parameters. |
|
31 | random_state : None, int |
|
32 | If None, create a new random state. If int, create a new random state |
|
33 | seeded with the value. |
|
34 | rand_rest_p : float |
|
35 | The probability of a random iteration during the the search process. |
|
36 | epsilon : float |
|
37 | The step-size for the climbing. |
|
38 | distribution : str |
|
39 | The type of distribution to sample from. |
|
40 | n_neighbours : int |
|
41 | The number of neighbours to sample and evaluate before moving to the best |
|
42 | of those neighbours. |
|
43 | repulsion_factor : float |
|
44 | The factor to increate epsilon when no better position is found |
|
45 | """ |
|
46 | ||
47 | def __init__( |
|
48 | self, |
|
49 | search_space: Dict[str, list], |
|
50 | initialize: Dict[ |
|
51 | Literal["grid", "vertices", "random", "warm_start"], |
|
52 | Union[int, list[dict]], |
|
53 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
54 | constraints: List[callable] = [], |
|
55 | random_state: int = None, |
|
56 | rand_rest_p: float = 0, |
|
57 | nth_process: int = None, |
|
58 | epsilon: float = 0.03, |
|
59 | distribution: Literal[ |
|
60 | "normal", "laplace", "gumbel", "logistic" |
|
61 | ] = "normal", |
|
62 | n_neighbours: int = 3, |
|
63 | repulsion_factor: float = 5, |
|
64 | ): |
|
65 | super().__init__( |
|
66 | search_space=search_space, |
|
67 | initialize=initialize, |
|
68 | constraints=constraints, |
|
69 | random_state=random_state, |
|
70 | rand_rest_p=rand_rest_p, |
|
71 | nth_process=nth_process, |
|
72 | epsilon=epsilon, |
|
73 | distribution=distribution, |
|
74 | n_neighbours=n_neighbours, |
|
75 | repulsion_factor=repulsion_factor, |
|
76 | ) |
|
77 |
@@ 13-75 (lines=63) @@ | ||
10 | ) |
|
11 | ||
12 | ||
13 | class StochasticHillClimbingOptimizer(_StochasticHillClimbingOptimizer, Search): |
|
14 | """ |
|
15 | A class implementing the **stochastic hill climbing optimizer** for the public API. |
|
16 | Inheriting from the `Search`-class to get the `search`-method and from |
|
17 | the `StochasticHillClimbingOptimizer`-backend to get the underlying algorithm. |
|
18 | ||
19 | Parameters |
|
20 | ---------- |
|
21 | search_space : dict[str, list] |
|
22 | The search space to explore. A dictionary with parameter |
|
23 | names as keys and a numpy array as values. |
|
24 | initialize : dict[str, int] |
|
25 | The method to generate initial positions. A dictionary with |
|
26 | the following key literals and the corresponding value type: |
|
27 | {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]} |
|
28 | constraints : list[callable] |
|
29 | A list of constraints, where each constraint is a callable. |
|
30 | The callable returns `True` or `False` dependend on the input parameters. |
|
31 | random_state : None, int |
|
32 | If None, create a new random state. If int, create a new random state |
|
33 | seeded with the value. |
|
34 | rand_rest_p : float |
|
35 | The probability of a random iteration during the the search process. |
|
36 | epsilon : float |
|
37 | The step-size for the climbing. |
|
38 | distribution : str |
|
39 | The type of distribution to sample from. |
|
40 | n_neighbours : int |
|
41 | The number of neighbours to sample and evaluate before moving to the best |
|
42 | of those neighbours. |
|
43 | p_accept : float, default=0.5 |
|
44 | probability to accept a worse solution |
|
45 | """ |
|
46 | ||
47 | def __init__( |
|
48 | self, |
|
49 | search_space: Dict[str, list], |
|
50 | initialize: Dict[ |
|
51 | Literal["grid", "vertices", "random", "warm_start"], |
|
52 | Union[int, list[dict]], |
|
53 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
54 | constraints: List[callable] = [], |
|
55 | random_state: int = None, |
|
56 | rand_rest_p: float = 0, |
|
57 | nth_process: int = None, |
|
58 | epsilon: float = 0.03, |
|
59 | distribution: Literal[ |
|
60 | "normal", "laplace", "gumbel", "logistic" |
|
61 | ] = "normal", |
|
62 | n_neighbours: int = 3, |
|
63 | p_accept: float = 0.5, |
|
64 | ): |
|
65 | super().__init__( |
|
66 | search_space=search_space, |
|
67 | initialize=initialize, |
|
68 | constraints=constraints, |
|
69 | random_state=random_state, |
|
70 | rand_rest_p=rand_rest_p, |
|
71 | nth_process=nth_process, |
|
72 | epsilon=epsilon, |
|
73 | distribution=distribution, |
|
74 | n_neighbours=n_neighbours, |
|
75 | p_accept=p_accept, |
|
76 | ) |
|
77 |
@@ 11-69 (lines=59) @@ | ||
8 | from ..optimizers import HillClimbingOptimizer as _HillClimbingOptimizer |
|
9 | ||
10 | ||
11 | class HillClimbingOptimizer(_HillClimbingOptimizer, Search): |
|
12 | """ |
|
13 | A class implementing the **hill climbing optimizer** for the public API. |
|
14 | Inheriting from the `Search`-class to get the `search`-method and from |
|
15 | the `HillClimbingOptimizer`-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 | epsilon : float |
|
35 | The step-size for the climbing. |
|
36 | distribution : str |
|
37 | The type of distribution to sample from. |
|
38 | n_neighbours : int |
|
39 | The number of neighbours to sample and evaluate before moving to the best |
|
40 | of those neighbours. |
|
41 | """ |
|
42 | ||
43 | def __init__( |
|
44 | self, |
|
45 | search_space: Dict[str, list], |
|
46 | initialize: Dict[ |
|
47 | Literal["grid", "vertices", "random", "warm_start"], |
|
48 | Union[int, list[dict]], |
|
49 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
50 | constraints: List[callable] = [], |
|
51 | random_state: int = None, |
|
52 | rand_rest_p: float = 0, |
|
53 | nth_process: int = None, |
|
54 | epsilon: float = 0.03, |
|
55 | distribution: Literal[ |
|
56 | "normal", "laplace", "gumbel", "logistic" |
|
57 | ] = "normal", |
|
58 | n_neighbours: int = 3, |
|
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 | epsilon=epsilon, |
|
68 | distribution=distribution, |
|
69 | n_neighbours=n_neighbours, |
|
70 | ) |
|
71 |