| @@ 13-78 (lines=66) @@ | ||
| 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"], int | List |
|
| 54 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 55 | constraints: List[callable] = [], |
|
| 56 | random_state: int = None, |
|
| 57 | rand_rest_p: float = 0, |
|
| 58 | nth_process: int = None, |
|
| 59 | epsilon: float = 0.03, |
|
| 60 | distribution: Literal[ |
|
| 61 | "normal", "laplace", "gumbel", "logistic" |
|
| 62 | ] = "normal", |
|
| 63 | n_neighbours: int = 3, |
|
| 64 | annealing_rate: float = 0.97, |
|
| 65 | start_temp: float = 1, |
|
| 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 | annealing_rate=annealing_rate, |
|
| 78 | start_temp=start_temp, |
|
| 79 | ) |
|
| 80 | ||
| @@ 11-76 (lines=66) @@ | ||
| 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 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"], int | List |
|
| 52 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 53 | constraints: List[callable] = [], |
|
| 54 | random_state: int = None, |
|
| 55 | rand_rest_p: float = 0, |
|
| 56 | nth_process: int = None, |
|
| 57 | epsilon: float = 0.03, |
|
| 58 | distribution: Literal[ |
|
| 59 | "normal", "laplace", "gumbel", "logistic" |
|
| 60 | ] = "normal", |
|
| 61 | n_neighbours: int = 3, |
|
| 62 | annealing_rate=0.98, |
|
| 63 | start_temp=10, |
|
| 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 | annealing_rate=annealing_rate, |
|
| 76 | start_temp=start_temp, |
|
| 77 | ) |
|
| 78 | ||
| @@ 13-76 (lines=64) @@ | ||
| 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"], int | List |
|
| 54 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 55 | constraints: List[callable] = [], |
|
| 56 | random_state: int = None, |
|
| 57 | rand_rest_p: float = 0, |
|
| 58 | nth_process: int = None, |
|
| 59 | epsilon: float = 0.03, |
|
| 60 | distribution: Literal[ |
|
| 61 | "normal", "laplace", "gumbel", "logistic" |
|
| 62 | ] = "normal", |
|
| 63 | n_neighbours: int = 3, |
|
| 64 | n_iter_restart: int = 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 | n_iter_restart=n_iter_restart, |
|
| 77 | ) |
|
| 78 | ||
| @@ 13-74 (lines=62) @@ | ||
| 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"], int | List |
|
| 52 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 53 | constraints: List[callable] = [], |
|
| 54 | random_state: int = None, |
|
| 55 | rand_rest_p: float = 0, |
|
| 56 | nth_process: int = None, |
|
| 57 | epsilon: float = 0.03, |
|
| 58 | distribution: Literal[ |
|
| 59 | "normal", "laplace", "gumbel", "logistic" |
|
| 60 | ] = "normal", |
|
| 61 | n_neighbours: int = 3, |
|
| 62 | p_accept: float = 0.5, |
|
| 63 | ): |
|
| 64 | super().__init__( |
|
| 65 | search_space=search_space, |
|
| 66 | initialize=initialize, |
|
| 67 | constraints=constraints, |
|
| 68 | random_state=random_state, |
|
| 69 | rand_rest_p=rand_rest_p, |
|
| 70 | nth_process=nth_process, |
|
| 71 | epsilon=epsilon, |
|
| 72 | distribution=distribution, |
|
| 73 | n_neighbours=n_neighbours, |
|
| 74 | p_accept=p_accept, |
|
| 75 | ) |
|
| 76 | ||
| @@ 13-74 (lines=62) @@ | ||
| 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"], int | List |
|
| 52 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 53 | constraints: List[callable] = [], |
|
| 54 | random_state: int = None, |
|
| 55 | rand_rest_p: float = 0, |
|
| 56 | nth_process: int = None, |
|
| 57 | epsilon: float = 0.03, |
|
| 58 | distribution: Literal[ |
|
| 59 | "normal", "laplace", "gumbel", "logistic" |
|
| 60 | ] = "normal", |
|
| 61 | n_neighbours: int = 3, |
|
| 62 | repulsion_factor: float = 5, |
|
| 63 | ): |
|
| 64 | super().__init__( |
|
| 65 | search_space=search_space, |
|
| 66 | initialize=initialize, |
|
| 67 | constraints=constraints, |
|
| 68 | random_state=random_state, |
|
| 69 | rand_rest_p=rand_rest_p, |
|
| 70 | nth_process=nth_process, |
|
| 71 | epsilon=epsilon, |
|
| 72 | distribution=distribution, |
|
| 73 | n_neighbours=n_neighbours, |
|
| 74 | repulsion_factor=repulsion_factor, |
|
| 75 | ) |
|
| 76 | ||
| @@ 11-68 (lines=58) @@ | ||
| 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"], int | List |
|
| 48 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 49 | constraints: List[callable] = [], |
|
| 50 | random_state: int = None, |
|
| 51 | rand_rest_p: float = 0, |
|
| 52 | nth_process: int = None, |
|
| 53 | epsilon: float = 0.03, |
|
| 54 | distribution: Literal[ |
|
| 55 | "normal", "laplace", "gumbel", "logistic" |
|
| 56 | ] = "normal", |
|
| 57 | n_neighbours: int = 3, |
|
| 58 | ): |
|
| 59 | super().__init__( |
|
| 60 | search_space=search_space, |
|
| 61 | initialize=initialize, |
|
| 62 | constraints=constraints, |
|
| 63 | random_state=random_state, |
|
| 64 | rand_rest_p=rand_rest_p, |
|
| 65 | nth_process=nth_process, |
|
| 66 | epsilon=epsilon, |
|
| 67 | distribution=distribution, |
|
| 68 | n_neighbours=n_neighbours, |
|
| 69 | ) |
|
| 70 | ||