Neuron 101

Nature-inspired optimization / Hill climbing

Türkçe

Plate56

Unit 6 · Topic 2 of 11

Hill climbing

Easy, 7 min, 7 steps

highest fitnessfitness by step
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 7 Start

The ball starts at a point

The ball is at x = 3, with fitness 0.17. Hill climbing does not see the whole landscape; it can only look right next to where it stands.

Open in Colab
  1. import random
  2. # f: optimizasyon arazisi konusundaki
  3. def tirman(x, d):
  4. while True:
  5. sol = max(0, x - d)
  6. sag = min(10, x + d)
  7. aday = max(sol, sag, key=f)
  8. if f(aday) <= f(x):
  9. return x
  10. x = aday
  11. x = tirman(3.0, 0.5)
  12. print(x, f(x))
  13. random.seed(1)
  14. sonlar = [tirman(
  15. random.uniform(0, 10), 0.5)
  16. for _ in range(5)]
  17. print(max(sonlar, key=f))
adim
0
x
3
fx
0.17
d
0.50
sol
2.50
sag
3.50
fSol
0.19
fSag
0.33
hareket
3