Simulated Annealing

Simulated Annealing

class Simulated_annealing(search_space, f_calls, cooling, max_iter, verbose=True)[source]

Bases: zellij.core.metaheuristic.Metaheuristic

Simulated_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_process best found points to the continuous format

  • best_scores (list[float]) – Returns a list of the n_process best found scores associated to best_sol

Cooling schedules

class Cooling(T0, Tend, peaks=1)[source]

Bases: object

Cooling 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.Cooling

Exponential multiplicative monotonic cooling.

T_k = T_0.\alpha^k

alpha

Decrease factor. 0.8 \leq \alpha \leq 0.9

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 increased peaks times.

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.Cooling

Logarithmic multiplicative monotonic cooling.

T_k = \frac{T_0}{1+\alpha.log(1+k)}

Parameters
  • alpha (float) – Decrease factor. \alpha>1

  • 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 increased peaks times.

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.Cooling

Linear multiplicative monotonic cooling.

T_k = \frac{T_0}{1+\alpha.k}

Parameters
  • alpha (float) – Decrease factor. \alpha>0

  • 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 increased peaks times.

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.Cooling

Quadratic multiplicative monotonic cooling.

T_k = \frac{T_0}{1+\alpha.k^2}

Parameters
  • alpha (float) – Decrease factor. \alpha>0

  • 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 increased peaks times.

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.Cooling

Linear additive monotonic cooling.

T_k = T_{end} + (T_0-T_{end})\left(\frac{cycles-k}{cycles}\right)

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 increased peaks times.

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.Cooling

Quadratic additive monotonic cooling.

T_k = T_{end} + (T_0-T_{end})\left(\frac{cycles-k}{cycles}\right)^2

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 increased peaks times.

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.Cooling

Exponential additive monotonic cooling.

T_k = T_{end} + \frac{T_0-T_{end}}{1+e^{\frac{2ln(T_0-T_{end})}{cycles}}(k-0,5cycles)}

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 increased peaks times.

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.Cooling

Trigonometric additive monotonic cooling.

T_k = T_{end} + 0,5(T_0-T_{end})(1+cos(\frac{k.\pi}{cycles}))

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 increased peaks times.

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]