You are on page 1of 1

import random

ORGate=[[0,0,0],[0,1,1],[1,0,1],[1,1,1]]
w1= round(random.random()-0.5 , 1)
w2= round(random.random()-0.5 , 1)
#w1=round(0.3,1)
#w2=round(-0.1,1)
alpha=0.1
theta=round(0.2,1)
print ("epoch x1 x2 Theo Act old_w1 old_w2 error new_w1
new_w2")

counter=1
epoch=0
while counter !=0:
counter=0
epoch=epoch+1
for i in range(4):
x1 = ORGate[i][0]
x2 = ORGate[i][1]
ytheo = ORGate[i][2]

wb1 = round(w1,1)
wb2 = round(w2,1)

Xfi = round(((w1 * x1) + (w2 * x2)), 1) - theta

if Xfi >= 0:
y = 1
else:
y = 0

error = round(ytheo - y,1)

if error != 0:
counter=counter+1
w1 = round(w1 + (alpha * x1 * error) ,1)
w2 = round(w2 + (alpha * x2 * error),1)
print(epoch, " ", x1, " ", x2, " ", ytheo, " ", y, " ",
wb1, " ", wb2, " ", error, " ", w1," ", w2)

print("----------------------------------------------------------------------------
--------------")

You might also like