You are on page 1of 1

input_actout = [[0,0,0],[0,1,1],[1,0,1],[1,1,1]]

initial_weights = [0.3, -0.1]


th = 0.2 #threshould
learning_rate = 0.1
iteration = 5

print('Epoch X1 X2 label1 old_w1 old_w2 actual error new_w1


new_w2')

def step(input,weight,th):
sum = input[0]*weight[0] + input[1]*weight[1]
y = sum - th
if y>= 0:
return 1
else:
return 0

for i in range(0,iteration):

print('----------------------------------------------------------------------------
-----------')
for j in range(0,len(input_actout)):
inputt = input_actout[j]
label = inputt[2]
act = step(inputt,initial_weights,th)
err = label - act
new_weight1 = round(initial_weights[0] + (learning_rate*err*inputt[0]),1)
new_weight2 = round(initial_weights[1] + (learning_rate * err *
inputt[1]),1)
print((i+1),' ',inputt[0],' ',inputt[1],' ',inputt[2],'
',initial_weights[0],' ',initial_weights[1],' ',act,' ',err,'
',new_weight1,' ',new_weight2)
initial_weights[0]= new_weight1
initial_weights[1]= new_weight2

You might also like