-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
138 lines (121 loc) · 2.08 KB
/
main.go
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
134
135
136
137
138
package main
import (
"fmt"
"math/rand"
"time"
"github.com/phoebetron/getlin"
"github.com/phoebetron/getlin/module/multic"
"github.com/phoebetron/getlin/module/single"
"github.com/phoebetron/getlin/stat32"
"github.com/phoebetron/proofs/mnist/loader"
)
const (
// bas is usually only used for debugging purposes and should be set to the
// absolute working directory of the executing process.
//
// /Users/xh3b4sd/project/phoebetron/proofs/
//
bas = ""
tes = "mnist_test.csv"
tra = "mnist_train.csv"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
var ldr getlin.Loader
{
ldr = loader.New(loader.Config{
Bas: bas,
Fil: tra,
Git: true,
Org: "phoebetron",
Rep: "mnist",
})
}
{
ldr.Create()
}
var con single.Config
{
con = single.Config{
Cla: 1000,
Fre: 0.10,
Inp: 784,
}
}
var mod getlin.Module
{
mod = multic.New(multic.Config{
Sin: []getlin.Module{
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
single.New(con),
},
})
}
var met getlin.Metric
for i := 1; i <= 100; i++ {
var bat [][2]getlin.Vector
{
bat = ldr.Search()
}
for _, x := range bat {
mod.Update(x[0])
mod.Update(x[1])
}
{
met = mod.Verify(bat)
}
fmt.Printf(
"epo %4d mae %4.3f cla %4d prd %4d\n",
i,
met.Get().Err().Mae(),
bat[0][1].Cla(),
stat32.Argmax(mod.Search(bat[0][1]).Out()),
)
}
{
prints(mod, ldr)
}
}
func prints(mod getlin.Module, ldr getlin.Loader) {
var bat [][2]getlin.Vector
{
bat = ldr.Search()[:10]
}
for _, x := range bat {
var p []float32
{
p = mod.Search(x[1]).Out()
}
var c int
var r []float32
{
c = x[1].Cla()
r = x[1].Inp()
}
for i := 0; i < 784; i++ {
if r[i] <= 0.5 {
fmt.Printf(" ")
}
if r[i] > 0.5 {
fmt.Printf("#")
}
if i%28 == 0 {
fmt.Printf("\n")
}
}
fmt.Printf("\n")
fmt.Printf("cla %v\n", c)
fmt.Printf("prd %v\n", p)
fmt.Printf("\n")
}
}