-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.go
More file actions
133 lines (124 loc) · 3.14 KB
/
Test.go
File metadata and controls
133 lines (124 loc) · 3.14 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// NNTest
package main
import (
"fmt"
"github.com/mistree/GoDeep"
"runtime"
"time"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
//RBMTest()
//NNTest()
DBNTest()
//SpeedTest()
}
func RBMTest() {
m := GoDeep.NewRBM(10, 3)
var Trainer GoDeep.Train
Trainer.Dropout = 0.1
Trainer.LearnRate = 1
Trainer.Momentum = 0.1
Trainer.Epoch = 20000
Trainer.ErrorAllowed = 0.1
start := time.Now()
Error := m.Train(&[][]float64{[]float64{0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
[]float64{1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
[]float64{1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
[]float64{0, 0, 0, 0, 0, 1, 1, 1, 1, 1}}, Trainer)
fmt.Printf("RBM Finished training in: %s\r\n", time.Since(start))
fmt.Printf("Error %f\r\n", Error)
fmt.Println(*m.Feedback(m.Forward(&[]float64{0, 1, 0, 1, 0, 1, 0, 1, 0, 1})))
fmt.Println(*m.Feedback(m.Forward(&[]float64{1, 0, 1, 0, 1, 0, 1, 0, 1, 0})))
fmt.Println(*m.Feedback(m.Forward(&[]float64{1, 1, 1, 1, 1, 0, 0, 0, 0, 0})))
fmt.Println(*m.Feedback(m.Forward(&[]float64{0, 0, 0, 0, 0, 1, 1, 1, 1, 1})))
}
func NNTest() {
nn := GoDeep.NewNN([]int{2, 10, 10, 1})
inputs := [][]float64{
[]float64{0, 0},
[]float64{0, 1},
[]float64{1, 0},
[]float64{1, 1},
}
targets := [][]float64{
[]float64{0},
[]float64{1},
[]float64{1},
[]float64{0},
}
var Trainer GoDeep.Train
Trainer.Dropout = 0
Trainer.Epoch = 5000
Trainer.LearnRate = 0.1
Trainer.Momentum = 0.1
Trainer.ErrorAllowed = 0.1
start := time.Now()
Error, Succeed := nn.Train(&inputs, &targets, Trainer)
fmt.Printf("NN Finished training in: %s\r\n", time.Since(start))
if Succeed {
fmt.Printf("Succeed, Error %f\r\n", Error)
} else {
fmt.Printf("Failed, Error %f\r\n", Error)
}
fmt.Print(*nn.RoundForward(&inputs[0]))
fmt.Print(*nn.RoundForward(&inputs[1]))
fmt.Print(*nn.RoundForward(&inputs[2]))
fmt.Print(*nn.RoundForward(&inputs[3]))
fmt.Println("")
}
func DBNTest() {
d := GoDeep.NewDBN([]int{2, 10, 10, 1})
var Trainer GoDeep.Train
Trainer.Dropout = 0.1
Trainer.LearnRate = 1
Trainer.Momentum = 0.1
Trainer.Epoch = 10000
Trainer.ErrorAllowed = 0.1
start := time.Now()
d.Train(&[][]float64{
[]float64{0, 0},
[]float64{0, 1},
[]float64{1, 0},
[]float64{1, 1}}, Trainer)
///*
n := d.ToNN()
Trainer.Epoch = 2000
Trainer.Dropout = 0.01
Error, Succeed := n.Train(&[][]float64{
[]float64{0, 0},
[]float64{0, 1},
[]float64{1, 0},
[]float64{1, 1}},
&[][]float64{
[]float64{0},
[]float64{1},
[]float64{1},
[]float64{0}}, Trainer)
fmt.Printf("DBN Finished training in: %s\r\n", time.Since(start))
if Succeed {
fmt.Printf("Succeed, Error %f\r\n", Error)
} else {
fmt.Printf("Failed, Error %f\r\n", Error)
}
fmt.Print(*n.RoundForward(&[]float64{0, 0}))
fmt.Print(*n.RoundForward(&[]float64{0, 1}))
fmt.Print(*n.RoundForward(&[]float64{1, 0}))
fmt.Print(*n.RoundForward(&[]float64{1, 1}))
fmt.Println("")
//*/
}
func SpeedTest() {
start1 := time.Now()
for i := 0; i < 100; i++ {
NNTest()
}
end1 := time.Now()
start2 := time.Now()
for i := 0; i < 100; i++ {
DBNTest()
}
end2 := time.Now()
fmt.Printf("NN Finished training in: %s\r\n", end1.Sub(start1))
fmt.Printf("DBN Finished training in: %s\r\n", end2.Sub(start2))
}