Skip to content

Commit 5ae1a35

Browse files
committed
add simulated annealing
1 parent 62e40aa commit 5ae1a35

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/hyperactive/opt/gfo/_simulated_annealing.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,76 @@
22

33

44
class SimulatedAnnealing(_BaseGFOadapter):
5+
"""Simulated annealing optimizer.
6+
7+
Parameters
8+
----------
9+
search_space : dict[str, list]
10+
The search space to explore. A dictionary with parameter
11+
names as keys and a numpy array as values.
12+
initialize : dict[str, int]
13+
The method to generate initial positions. A dictionary with
14+
the following key literals and the corresponding value type:
15+
{"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
16+
constraints : list[callable]
17+
A list of constraints, where each constraint is a callable.
18+
The callable returns `True` or `False` dependend on the input parameters.
19+
random_state : None, int
20+
If None, create a new random state. If int, create a new random state
21+
seeded with the value.
22+
rand_rest_p : float
23+
The probability of a random iteration during the the search process.
24+
epsilon : float
25+
The step-size for the climbing.
26+
distribution : str
27+
The type of distribution to sample from.
28+
n_neighbours : int
29+
The number of neighbours to sample and evaluate before moving to the best
30+
of those neighbours.
31+
annealing_rate : float
32+
The rate at which the temperature is annealed.
33+
start_temp : float
34+
The initial temperature.
35+
n_iter : int, default=100
36+
The number of iterations to run the optimizer.
37+
verbose : bool, default=False
38+
If True, print the progress of the optimization process.
39+
experiment : BaseExperiment, optional
40+
The experiment to optimize parameters for.
41+
Optional, can be passed later via ``set_params``.
42+
"""
43+
44+
def __init__(
45+
self,
46+
search_space=None,
47+
initialize=None,
48+
constraints=None,
49+
random_state=None,
50+
rand_rest_p=0.1,
51+
epsilon=0.01,
52+
distribution="normal",
53+
n_neighbours=10,
54+
annealing_rate=0.97,
55+
start_temp=1,
56+
n_iter=100,
57+
verbose=False,
58+
experiment=None,
59+
):
60+
self.random_state = random_state
61+
self.rand_rest_p = rand_rest_p
62+
self.epsilon = epsilon
63+
self.distribution = distribution
64+
self.n_neighbours = n_neighbours
65+
self.annealing_rate = annealing_rate
66+
self.start_temp = start_temp
67+
self.search_space = search_space
68+
self.initialize = initialize
69+
self.constraints = constraints
70+
self.n_iter = n_iter
71+
self.experiment = experiment
72+
self.verbose = verbose
73+
74+
super().__init__()
575

676
def _get_gfo_class(self):
777
"""Get the GFO class to use.

0 commit comments

Comments
 (0)