Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- навчання "двійкового" нейрона з корекцією помилки (Example of Error-Correction Learning)
- -- до лекції Igor Aizenberg - Lecture 3. Linear Separability. Threshold Neuron.
- -- https://www.igoraizenberg.com/my-classes/cmpg-765-neural-networks-and-learning-systems
- function sgn(num)
- return num > 0 and 1 or (num < 0 and -1 or 0)
- end
- function sum(k) -- ф-я нейрону
- return sgn(w[1] + k[2]*w[2] + k[3]*w[3])
- end
- w = {1, 1, 1} -- початкові ваги
- -- пакет даних для навчання {бажаний вихід, вхід1, вхід2}, ..
- t = { { 1, 1, 1},
- {-1, 1,-1},
- {-1,-1, 1},
- {-1,-1,-1} }
- itr =1
- repeat
- ext = true
- print('Iteration', itr)
- for _, i in next, t do
- err = i[1] - sum(i)
- ext = ext and err==0
- w[1] = w[1] + err
- w[2] = w[2] + err/i[2]
- w[3] = w[3] + err/i[3]
- print(err..':', unpack(w))
- end
- itr = itr +1
- ext = ext or itr > 5 -- якщо за 5 ітерацій не навчили то "ой, всьо"
- until ext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement