-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (47 loc) · 1.27 KB
/
main.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
from network import *
import pandas as pd
import random
from datetime import datetime
or_train_set={(1,1):1,
(1,0):1,
(0,1):1,
(0,0):0}
xor_train_set={(1,1):0,
(1,0):1,
(0,1):1,
(0,0):0}
and_train_set={(1,1):1,
(1,0):0,
(0,1):0,
(0,0):0}
xand_train_set={(1,1):1,
(1,0):0,
(0,1):0,
(0,0):1}
train_set={}
for key in or_train_set:
train_set[(*key,1,0,0,0)]=or_train_set[key]
for key in xor_train_set:
train_set[(*key,0,1,0,0)]=xor_train_set[key]
for key in and_train_set:
train_set[(*key,0,0,1,0)]=and_train_set[key]
for key in xand_train_set:
train_set[(*key,0,0,0,1)]=xand_train_set[key]
print(train_set)
nn=Network(6, 0.3)
nn.add_layer(8)
nn.add_layer(8)
nn.add_layer(8)
nn.add_layer(1)
start=datetime.now()
for i in range(4000):
if i%100==0:
print("generation", i, ":", (datetime.now()-start).seconds+(datetime.now()-start).microseconds/10**6,"seconds elapsed")
print("error", nn.evaluate(train_set))
nn.train(train_set)
"""for key in random.sample(list(xor_train_set), 10):
print(nn(key), train_set[key])
"""
for key in train_set:
print(nn(key), train_set[key])
#print(nn.layers[2].neurons[0].weights)