-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.lua
More file actions
40 lines (36 loc) · 1.25 KB
/
demo.lua
File metadata and controls
40 lines (36 loc) · 1.25 KB
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
require('mininet')
time = os.time()
print(time)
math.randomseed(1)
-- 00:1 1489375471
-- oddity: a seed of 1489372202 and 1489374325 requires learningRate < 5
myNetwork = mininet:new({3,4,1},2)
for iteration = 1,10000 do
myNetwork:backPropagate({{0,0,1},{1,0,1},{0,1,1},{1,1,1}},{{1},{0},{0},{0}})
end
myNetwork:predictOutputs({{0,0,1},{1,0,1},{0,1,1},{1,1,1}})
predictions = myNetwork:predictOutputs({{0,0,1},{1,0,1},{0,1,1},{1,1,1}})
print("00 | " .. predictions[1][1])
print("10 | " .. predictions[2][1])
print("01 | " .. predictions[3][1])
print("11 | " .. predictions[4][1])
print "Saving network and reopening"
myNetwork:save("orig")
myNetwork = nil
loadedNet = mininet:load("orig")
predictions = loadedNet:predictOutputs({{0,0,1},{1,0,1},{0,1,1},{1,1,1}})
-- predictions[batch][node]
print("00 | " .. predictions[1][1])
print("10 | " .. predictions[2][1])
print("01 | " .. predictions[3][1])
print("11 | " .. predictions[4][1])
print 'another test'
loadedNet:save("new")
loadedNet = nil
anotherNet = mininet:load("new")
predictions = anotherNet:predictOutputs({{0,0,1},{1,0,1},{0,1,1},{1,1,1}})
-- predictions[batch][node]
print("00 | " .. predictions[1][1])
print("10 | " .. predictions[2][1])
print("01 | " .. predictions[3][1])
print("11 | " .. predictions[4][1])