Simulated Annealing
Contents
Simulated Annealing
Simulated Annealing
- class Simulated_annealing(search_space, f_calls, cooling, max_iter, verbose=True)[source]
Bases:
zellij.core.metaheuristic.MetaheuristicSimulated_annealing (SA) is a hill climbing exploitation algorithm.
It uses a Cooling schedules which partially drives the acceptance probability.
- search_space
Search space object containing bounds of the search space.
- Type
Searchspace
- f_calls
Maximum number of Loss Function calls
- Type
int
- cooling
Cooling schedules used to determine the probability of acceptance.
- Type
Cooling
- max_iter
Maximum iterations of the inner loop. Determines how long the algorithm should sample neighbors of a solution, before decreasing the temperature.
- Type
int
- save
if True save results into a file
- Type
boolean, optional
- verbose
Algorithm verbosity
- Type
boolean, default=True
See also
- Metaheuristic
Parent class defining what a Metaheuristic is
- Loss Function
Describes what a loss function is in Zellij
- Search space
Describes what a loss function is in Zellij
Examples
>>> from zellij.core import Loss >>> from zellij.core import ContinuousSearchspace >>> from zellij.core import FloatVar, ArrayVar >>> from zellij.utils.neighborhoods import FloatInterval, ArrayInterval, Intervals >>> from zellij.strategies import Simulated_annealing >>> from zellij.strategies.tools import MulExponential >>> from zellij.utils.benchmark import himmelblau ... >>> lf = Loss()(himmelblau) >>> sp = ContinuousSearchspace(ArrayVar( ... FloatVar("a",-5,5, neighbor=FloatInterval(0.5)), ... FloatVar("b",-5,5,neighbor=FloatInterval(0.5)), ... neighbor=ArrayInterval()) ... ,lf, neighbor=Intervals()) ... >>> cooling = MulExponential(0.85,100,2,3) >>> sa = Simulated_annealing(sp, 100, cooling, 1) ... >>> point = sp.random_point() >>> sa.run(point, lf([point])[0])
- run(X0=None, Y0=None, H=None, n_process=1)[source]
Runs SA
- Parameters
X0 (list[float], optional) – Initial solution. If None, a Fractal must be given (H!=None)
Y0 ({int, float}, optional) – Score of the initial solution Determine the starting point of the chaotic map.
H (Fractal, optional) – When used by Decomposition Based Algorithm, a fractal corresponding to the current subspace is given
n_process (int, default=1) – Determine the number of best solution found to return.
- Returns
best_sol (list[float]) – Returns a list of the
n_processbest found points to the continuous formatbest_scores (list[float]) – Returns a list of the
n_processbest found scores associated to best_sol
Cooling schedules
- class Cooling(T0, Tend, peaks=1)[source]
Bases:
objectCooling is a base object which defines what a cooling Schedule is.
- Tcurrent
Current temperature
- Type
float
- cross
Count the number of times Tend is crossed.
- Type
int
- T0
Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
- Type
float
- Tend
Temperature threshold. When reached the temperature is violently increased proportionally to <T0>. It allows to periodically easily escape from local optima.
- Type
float
- peaks
Maximum number of crossed threshold according to
Tend. The temperature will be increased <peaks> times.- Type
int, default=1
- cool()[source]
Decrease temperature and return the current temperature.
- reset()[source]
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- abstract cool()[source]
- abstract iterations()[source]
- reset()[source]
Multiplicative
- class MulExponential(alpha, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingExponential multiplicative monotonic cooling.

- alpha
Decrease factor.

- Type
float
- T0
Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
- Type
float
- Tend
Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.- Type
float
- peaks
Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.- Type
int, default=1
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class MulLogarithmic(alpha, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingLogarithmic multiplicative monotonic cooling.

- Parameters
alpha (float) – Decrease factor.

T0 (float) – Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
Tend (float) – Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.peaks (int, default=1) – Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class MulLinear(alpha, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingLinear multiplicative monotonic cooling.

- Parameters
alpha (float) – Decrease factor.

T0 (float) – Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
Tend (float) – Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.peaks (int, default=1) – Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class MulQuadratic(alpha, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingQuadratic multiplicative monotonic cooling.

- Parameters
alpha (float) – Decrease factor.

T0 (float) – Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
Tend (float) – Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.peaks (int, default=1) – Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
Additive
- class AddLinear(cycles, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingLinear additive monotonic cooling.

- Parameters
cycles (int) – Number of cooling cycles.
T0 (float) – Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
Tend (float) – Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.peaks (int, default=1) – Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class AddQuadratic(cycles, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingQuadratic additive monotonic cooling.

- cycles
Number of cooling cycles.
- Type
int
- T0
Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
- Type
float
- Tend
Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.- Type
float
- peaks
Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.- Type
int, default=1
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class AddExponential(cycles, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingExponential additive monotonic cooling.

- cycles
Number of cooling cycles.
- Type
int
- T0
Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
- Type
float
- Tend
Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.- Type
float
- peaks
Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.- Type
int, default=1
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]
- class AddTrigonometric(cycles, T0, Tend, peaks=1)[source]
Bases:
zellij.strategies.tools.cooling.CoolingTrigonometric additive monotonic cooling.

- cycles
Number of cooling cycles.
- Type
int
- T0
Initial temperature of the cooling schedule. Higher temperature leads to higher acceptance of a worse solution. (more exploration)
- Type
float
- Tend
Temperature threshold. When reached the temperature is violently increased proportionally to
T0. It allows to periodically easily escape from local optima.- Type
float
- peaks
Maximum number of crossed threshold according to
Tend. The temperature will be increasedpeakstimes.- Type
int, default=1
- cool()[source]
Decrease temperature and return the current temperature.
- reset()
Reset cooling schedule
- iterations()[source]
Get the theoretical number of iterations to end the schedule.
- cool()[source]
- iterations()[source]