-
Notifications
You must be signed in to change notification settings - Fork 1
/
xor.py
47 lines (36 loc) · 947 Bytes
/
xor.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
from nn import NerualNetwork
import random
from utils import printProgressBar
training_data = [
{
"inputs": [0, 1],
"targets": [1],
},
{
"inputs": [1, 0],
"targets": [1],
},
{
"inputs": [0, 0],
"targets": [0],
},
{
"inputs": [1, 1],
"targets": [0],
}
]
ITERATIONS = 50000
LEARNING_RATE = 0.1
def testXOR():
nn = NerualNetwork(2,3,1, LEARNING_RATE)
# show a progress bar
printProgressBar(0, ITERATIONS, prefix = 'Progress:', suffix = 'Complete | 0 Iterations', length = 50)
for i in range(ITERATIONS):
printProgressBar(i + 1, ITERATIONS, prefix = 'Progress:', suffix = 'Complete | ' + str(i + 1) + ' Iterations', length = 50)
data = random.choice(training_data)
nn.train(data['inputs'], data['targets'])
print(nn.feedforward([0,0]))
print(nn.feedforward([0,1]))
print(nn.feedforward([1,0]))
print(nn.feedforward([1,1]))
testXOR()