-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrainExample.Lua
More file actions
43 lines (38 loc) · 1.05 KB
/
BrainExample.Lua
File metadata and controls
43 lines (38 loc) · 1.05 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
41
42
43
local Slnn = require("network.Slnn")
math.randomseed(os.time())
local network = Slnn.New(2,1,1,3,0.05)
local result = {}
function Train(i1,i2,o)
local inputs = {}
local outputs = {}
table.insert(inputs, i1)
table.insert(inputs, i2)
table.insert(outputs, o)
return (network.Train(inputs,outputs))
end
function Calc(i1,i2)
local inputs = {}
table.insert(inputs, i1)
table.insert(inputs, i2)
return (network.CalcOutput(inputs))
end
for i=1,10000 do
sumSquareError = 0
result = Train(1, 1, 0)
sumSquareError = sumSquareError + math.pow(result[1] - 0,2)
result = Train(1, 0, 1)
sumSquareError = sumSquareError + math.pow(result[1] - 1,2)
result = Train(0, 1, 1)
sumSquareError = sumSquareError + math.pow(result[1] - 1,2)
result = Train(0, 0, 0)
sumSquareError = sumSquareError + math.pow(result[1] - 0,2)
end
print("SSE: " .. sumSquareError)
result = Calc(1, 1)
print(" 1 1 " .. result[1])
result = Calc(1, 0)
print(" 1 0 " .. result[1])
result = Calc(0, 1)
print(" 0 1 " .. result[1])
result = Calc(0, 0)
print(" 0 0 " .. result[1])