-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneNeuron.py
81 lines (71 loc) · 1.7 KB
/
OneNeuron.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
77
78
79
80
81
import random
#SetUp
ORlist = [0,1,1,1]
#ANDlist = [0,0,0,1]
input1list = [0,1,0,1]
input2list = [0,0,1,1]
#startlist = [0,0,0.7]
LR = 0.7
weight1 = 0
weight1new = 0
weight2 = 0
weight2new = 0
bias = 0.7
biasnew = 0
error =0
count = random.randint(0,3)
input1 = input1list[count]
input2 = input2list[count]
Wanted = ORlist[count]
Output = 0
Correct = 0
Total = 0
Loop = 1
errorFreeRunLength = 0
print('')
print('Program Name: ONE Neuron')
print('Start')
print('')
while errorFreeRunLength is not 20:
count = random.randint(0,3)
input1 = input1list[count]
input2 = input2list[count]
Wanted = ORlist[count]
#Neuron Result (Kernal Of Learning)
NeuronResult = ((input1 * weight1)+(input2 * weight2) + bias)
# The TEST
if NeuronResult < 0:
Output = 0
else:
Output = 1
error = Wanted - Output
# LOOP Control
if Output is Wanted:
errorFreeRunLength = (errorFreeRunLength + 1)
Correct = 1
Total = (Total + 1)
else:
errorFreeRunLength = 0
Correct = 0
Total = (Total - 1)
# Applying The Whip (Changing The Weights)
weight1new = (weight1 + (input1 * LR) * error)
weight1 = weight1new
weight2new = (weight2 + (input2 * LR) * error)
weight2 = weight2new
biasnew = (bias + ( 1 * LR) * error)
bias = biasnew
print('Loop: ', Loop)
Loop = (Loop + 1)
print('Total',Total)
print('Correct', Correct)
print('errorFreeRunLength: ', errorFreeRunLength)
print('input1:',input1 ,' input2:', input2)
print('Wanted: ',Wanted ,'Output: ', (Output))
print('NeuronResult: ', NeuronResult)
print('error: ' , (error))
print(weight1)
print(weight2)
print(bias)
print('')
print('The End')