-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOR_implementation_Hebbian_Learning.py
76 lines (67 loc) · 1.6 KB
/
OR_implementation_Hebbian_Learning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# OR gate implementation using Hebbian learning
# Truth tabla of OR, format [x1, x2, bias, output ]
data = [[1, 1, 1, 1],[1, -1, 1, 1],[-1, 1, 1, 1],[-1, -1, 1, -1]]
# initilize weights
w1=0
w2=0
b=0
for i in range(len(data)):
print("Iteration-"+str(i)+"########")
print(data[i])
print("w1_new = w1_old + x1 * t ")
print(" = "+str(w1)+"+"+str(data[i][0])+"*"+str(data[i][3]))
w1 = w1+data[i][0]*data[i][3]
print(" = "+str(w1))
print("w2_new = w2_old + x2 * t ")
print(" = "+str(w2)+"+"+str(data[i][1])+"*"+str(data[i][3]))
w2 = w2+data[i][1]*data[i][3]
print(" ="+str(w2))
print("b_new = b_old + 1 * t ")
print(" = "+str(b)+"+ 1 * "+str(data[i][3]))
b = b+1*data[i][3] # bias is 1 for all inputs
print(" = "+str(b))
# OUTPUT
# Iteration-0########
# [1, 1, 1, 1]
# w1_new = w1_old + x1 * t
# = 0+1*1
# = 1
# w2_new = w2_old + x2 * t
# = 0+1*1
# =1
# b_new = b_old + 1 * t
# = 0+ 1 * 1
# = 1
# Iteration-1########
# [1, -1, 1, 1]
# w1_new = w1_old + x1 * t
# = 1+1*1
# = 2
# w2_new = w2_old + x2 * t
# = 1+-1*1
# =0
# b_new = b_old + 1 * t
# = 1+ 1 * 1
# = 2
# Iteration-2########
# [-1, 1, 1, 1]
# w1_new = w1_old + x1 * t
# = 2+-1*1
# = 1
# w2_new = w2_old + x2 * t
# = 0+1*1
# =1
# b_new = b_old + 1 * t
# = 2+ 1 * 1
# = 3
# Iteration-3########
# [-1, -1, 1, -1]
# w1_new = w1_old + x1 * t
# = 1+-1*-1
# = 2
# w2_new = w2_old + x2 * t
# = 1+-1*-1
# =2
# b_new = b_old + 1 * t
# = 3+ 1 * -1
# = 2