Advertisement
drabont

Example of Error-Correction Learning

Mar 16th, 2025
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. -- навчання "двійкового" нейрона з корекцією помилки (Example of Error-Correction Learning)
  2. -- до лекції Igor Aizenberg - Lecture 3. Linear Separability. Threshold Neuron.
  3. -- https://www.igoraizenberg.com/my-classes/cmpg-765-neural-networks-and-learning-systems
  4.  
  5. function sgn(num)
  6.     return num > 0 and 1 or (num < 0 and -1 or 0)
  7. end
  8.  
  9. function sum(k) -- ф-я нейрону
  10.   return sgn(w[1] + k[2]*w[2] + k[3]*w[3])
  11. end
  12. w = {1, 1, 1} -- початкові ваги
  13.  
  14. -- пакет даних для навчання {бажаний вихід, вхід1, вхід2}, ..
  15. t = { { 1, 1, 1},
  16.       {-1, 1,-1},
  17.       {-1,-1, 1},
  18.       {-1,-1,-1} }
  19.  
  20. itr =1
  21. repeat
  22.   ext = true
  23.   print('Iteration', itr)
  24.   for _, i in next, t do
  25.     err = i[1] - sum(i)
  26.     ext = ext and err==0
  27.     w[1] = w[1] + err
  28.     w[2] = w[2] + err/i[2]
  29.     w[3] = w[3] + err/i[3]
  30.     print(err..':', unpack(w))
  31.   end
  32.   itr = itr +1
  33.   ext = ext or itr > 5 -- якщо за 5 ітерацій не навчили то "ой, всьо"
  34. until ext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement