Simulated Annealing using tqdm
pip install frigidum==0.3.9
pip install frigidum
import frigidum
import random
def random_start():
return 50 + random.random()
def random_small_step(x):
return x + 0.1 * (random.random() - .5)
def random_big_step(x):
return x + 10 * (random.random() - .5)
def obj(x):
return x**2
local_opt = frigidum.sa(random_start=random_start, random_neighbours=[random_small_step, random_big_step], cost_function=obj, T_start=100, T_stop = 0.001, repeats=10**4, copy_state=frigidum.annealing.naked)
A movement is a when a proposed state is accepted, and the objective function has changed. For each batch of repeats, the proportion of movements are displayed.
In the early phase of annealing, movements should happen >90%.
In the last phase of annealing, movements should happen <5%.
3 most important copy methods are included in the annealing
module,
def copy(state):
return state.copy()
def deepcopy(state):
return state.deepcopy()
def naked(state):
return state
In the example, the argument copy_state=frigidum.annealing.naked
is used.