Neuron 101

Nature-inspired optimization / Grey wolf optimizer

Türkçe

Plate65

Unit 6 · Topic 11 of 11

Grey wolf optimizer

Medium, 9 min, 9 steps

Height01Alpha's height
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 9 Pack

Wolves spread over the surface

The map shows a surface from above: darker tones are higher. 10 wolves were spread over the surface at random. The prey is the highest point, marked by the triangle. The wolves do not know where the prey is; they can only measure the height where they stand.

Open in Colab
  1. import random
  2. # f(p): p noktasının yüksekliği
  3. # k(v): v'yi −5 ile 5 arasına çeker
  4. random.seed(1)
  5. a0 = 2.0
  6. X = [[random.uniform(-5, 5)
  7. for _ in range(2)]
  8. for _ in range(10)]
  9. def liderler(noktalar):
  10. s = sorted(noktalar, key=f,
  11. reverse=True)
  12. return [p[:] for p in s[:3]]
  13. def tahmin(l, x):
  14. A = 2 * a * random.random() - a
  15. C = 2 * random.random()
  16. return l - A * abs(C * l - x)
  17. L = liderler(X)
  18. for tur in range(40):
  19. a = a0 * (1 - tur / 40)
  20. for x in X:
  21. for d in range(2):
  22. t = [tahmin(l[d], x[d])
  23. for l in L]
  24. x[d] = k(sum(t) / 3)
  25. L = liderler(X + L)
  26. print(L[0], f(L[0]))
tur
0
a
2
enIyiDeger
0.57