| @@ 13-66 (lines=54) @@ | ||
| 10 | ) |
|
| 11 | ||
| 12 | ||
| 13 | class ParallelTemperingOptimizer(_ParallelTemperingOptimizer, Search): |
|
| 14 | """ |
|
| 15 | A class implementing **parallel tempering** for the public API. |
|
| 16 | Inheriting from the `Search`-class to get the `search`-method and from |
|
| 17 | the `ParallelTemperingOptimizer`-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 | """ |
|
| 44 | ||
| 45 | def __init__( |
|
| 46 | self, |
|
| 47 | search_space: Dict[str, list], |
|
| 48 | initialize: Dict[ |
|
| 49 | Literal["grid", "vertices", "random", "warm_start"], int | List |
|
| 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 | population: int = 5, |
|
| 56 | n_iter_swap: int = 5, |
|
| 57 | ): |
|
| 58 | super().__init__( |
|
| 59 | search_space=search_space, |
|
| 60 | initialize=initialize, |
|
| 61 | constraints=constraints, |
|
| 62 | random_state=random_state, |
|
| 63 | rand_rest_p=rand_rest_p, |
|
| 64 | nth_process=nth_process, |
|
| 65 | population=population, |
|
| 66 | n_iter_swap=n_iter_swap, |
|
| 67 | ) |
|
| 68 | ||
| @@ 11-62 (lines=52) @@ | ||
| 8 | from ..optimizers import SpiralOptimization as _SpiralOptimization |
|
| 9 | ||
| 10 | ||
| 11 | class SpiralOptimization(_SpiralOptimization, Search): |
|
| 12 | """ |
|
| 13 | A class implementing the **spiral optimizer** for the public API. |
|
| 14 | Inheriting from the `Search`-class to get the `search`-method and from |
|
| 15 | the `SpiralOptimization`-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 | population : int |
|
| 35 | The number of particles in the swarm. |
|
| 36 | decay_rate : float |
|
| 37 | This parameter is a factor, that influences the radius of the particles during their spiral movement. |
|
| 38 | Lower values accelerates the convergence of the particles to the best known position, while values above 1 eventually lead to a movement where the particles spiral away from each other. |
|
| 39 | """ |
|
| 40 | ||
| 41 | def __init__( |
|
| 42 | self, |
|
| 43 | search_space: Dict[str, list], |
|
| 44 | initialize: Dict[ |
|
| 45 | Literal["grid", "vertices", "random", "warm_start"], int | List |
|
| 46 | ] = {"grid": 4, "random": 2, "vertices": 4}, |
|
| 47 | constraints: List[callable] = [], |
|
| 48 | random_state: int = None, |
|
| 49 | rand_rest_p: float = 0, |
|
| 50 | nth_process: int = None, |
|
| 51 | population: int = 10, |
|
| 52 | decay_rate: float = 0.99, |
|
| 53 | ): |
|
| 54 | super().__init__( |
|
| 55 | search_space=search_space, |
|
| 56 | initialize=initialize, |
|
| 57 | constraints=constraints, |
|
| 58 | random_state=random_state, |
|
| 59 | rand_rest_p=rand_rest_p, |
|
| 60 | nth_process=nth_process, |
|
| 61 | population=population, |
|
| 62 | decay_rate=decay_rate, |
|
| 63 | ) |
|
| 64 | ||