Neuron 101

Nature-inspired optimization / Simulated annealing

Türkçe

Plate57

Unit 6 · Topic 3 of 11

Simulated annealing

Medium, 9 min, 10 steps

highest fitnesscurrent fitness
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 10 Start

A hot start

The ball is at x = 3, with fitness 0.17. The temperature is T = 0.30. The name comes from metalwork: annealed metal that cools slowly settles into an ordered structure. Here the temperature sets how easily a worse step is accepted.

Open in Colab
  1. import math
  2. import random
  3. # f: optimizasyon arazisi konusundaki
  4. random.seed(11)
  5. x, T = 3.0, 0.3
  6. en_iyi = x
  7. for tur in range(80):
  8. y = x + random.gauss(0, 1.2)
  9. y = min(10, max(0, y))
  10. fark = f(y) - f(x)
  11. if fark >= 0 or (random.random()
  12. < math.exp(fark / T)):
  13. x = y
  14. en_iyi = max(en_iyi, x, key=f)
  15. T *= 0.94
  16. print(en_iyi, f(en_iyi))
tur
1
sicaklik
0.30
once
3
fOnce
0.17
oneri
1.64
fOneri
0.44
fark
0.28
dusus
−0.28
olasilik
1
x
3
fx
0.17