SHARE
TWEET

Untitled

a guest Sep 17th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. entrys = [[0, 0], [0, 1], [1, 0], [1, 1]]
  4.  
  5. intended = [0, 0, 0, 1] # Para alterar o tipo de porta, basta alterar a saída esperada
  6.  
  7. alpha = 0.7
  8. w = []
  9.  
  10. for x in range(3):
  11.     w.append(random.uniform(0, 1))
  12.  
  13. epocaMax = 10
  14.  
  15. for epoca in range(epocaMax):
  16.     results = [0, 0, 0, 0]
  17.     erroEpoca = 0
  18.  
  19.     for i in range(4):
  20.         neuron = w[0] + entrys[i][0] * w[1] + entrys[i][1] * w[2]
  21.        
  22.         if (neuron < 0):
  23.             results[i] = 0
  24.         else:
  25.             results[i] = 1
  26.  
  27.         delta = intended[i] - results[i]
  28.         w[0] = w[0] + alpha * delta
  29.         w[1] = w[1] + alpha * entrys[i][0] * delta
  30.         w[2] = w[2] + alpha * entrys[i][1] * delta
  31.  
  32.         erroEpoca = erroEpoca + abs(delta)
  33.  
  34.     if (erroEpoca == 0):
  35.         break
  36.  
  37. if (erroEpoca == 0):
  38.     print("A rede convergiu")
  39. else:
  40.     print("A rede não convergiu")
  41. print("Bias: ", w[0])
  42. print("Pesos: ", w[1], ',', w[2])
  43. print("Valores encontrados: ", results)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top