-
Notifications
You must be signed in to change notification settings - Fork 25
/
tweak_test.go
258 lines (249 loc) · 5.4 KB
/
tweak_test.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package params
import (
"testing"
"cogentcore.org/core/base/reflectx"
"github.com/stretchr/testify/assert"
)
var tweakSets = Sets{
"Base": {
{Sel: "Path", Desc: "norm and momentum on works better, but wt bal is not better for smaller nets",
Params: Params{
"Path.Learn.LRate": "0.02",
"Path.Learn.Momentum": "0.9",
},
Hypers: Hypers{
"Path.Learn.LRate": {"Tweak": "log"},
"Path.Learn.Momentum": {"Tweak": "incr"},
}},
{Sel: "Layer", Desc: "using default 1.8 inhib for all of network -- can explore",
Params: Params{
"Layer.Inhib.Layer.Gi": "1.8",
},
Hypers: Hypers{
"Layer.Inhib.Layer.Gi": {"Tweak": "[1.75, 1.85]"},
}},
{Sel: "#Hidden", Desc: "output definitely needs lower inhib -- true for smaller layers in general",
Params: Params{
"Layer.Inhib.Layer.Gi": "1.4",
},
Hypers: Hypers{
"Layer.Inhib.Layer.Gi": {"Tweak": "incr"},
}},
{Sel: ".Back", Desc: "top-down back-pathways MUST have lower relative weight scale, otherwise network hallucinates",
Params: Params{
"Path.WtScale.Rel": "0.2",
},
Hypers: Hypers{
"Path.WtScale.Rel": {"Tweak": "log"},
}},
},
}
func TestTweak(t *testing.T) {
logvals := []float32{.1, .2, .5, 1, 1.5, 12, .015}
logtargs := []float32{.05, .2, .1, .5, .2, 1, .5, 2, 1.2, 2, 11, 15, .012, .02}
for i, v := range logvals {
ps := Tweak(v, true, false)
for j, p := range ps {
tp := logtargs[i*2+j]
if p != tp {
t.Errorf("log mismatch for v=%g: got %g != target %g\n", v, p, tp)
}
}
}
incrvals := []float32{.1, .3, 1.5, 25, .008}
incrtargs := []float32{.09, .11, .2, .4, 1.4, 1.6, 24, 26, .007, .009}
for i, v := range incrvals {
ps := Tweak(v, false, true)
for j, p := range ps {
tp := incrtargs[i*2+j]
if p != tp {
t.Errorf("incr mismatch for v=%g: got %g != target %g\n", v, p, tp)
}
}
}
}
var trgSearch = `[
{
"Param": "Layer.Inhib.Layer.Gi",
"Sel": {
"Sel": "#Hidden",
"Desc": "output definitely needs lower inhib -- true for smaller layers in general",
"Params": {
"Layer.Inhib.Layer.Gi": "1.4"
},
"Hypers": {
"Layer.Inhib.Layer.Gi": {
"Tweak": "incr"
}
}
},
"Search": [
{
"Name": "Hidden",
"Type": "Layer",
"Path": "Layer.Inhib.Layer.Gi",
"Start": 1.4,
"Values": [
1.3,
1.5
]
}
]
},
{
"Param": "Path.WtScale.Rel",
"Sel": {
"Sel": ".Back",
"Desc": "top-down back-pathways MUST have lower relative weight scale, otherwise network hallucinates",
"Params": {
"Path.WtScale.Rel": "0.2"
},
"Hypers": {
"Path.WtScale.Rel": {
"Tweak": "log"
}
}
},
"Search": [
{
"Name": "HiddenToInput",
"Type": "Path",
"Path": "Path.WtScale.Rel",
"Start": 0.2,
"Values": [
0.1,
0.5
]
}
]
},
{
"Param": "Layer.Inhib.Layer.Gi",
"Sel": {
"Sel": "Layer",
"Desc": "using default 1.8 inhib for all of network -- can explore",
"Params": {
"Layer.Inhib.Layer.Gi": "1.8"
},
"Hypers": {
"Layer.Inhib.Layer.Gi": {
"Tweak": "[1.75, 1.85]"
}
}
},
"Search": [
{
"Name": "Input",
"Type": "Layer",
"Path": "Layer.Inhib.Layer.Gi",
"Start": 1.8,
"Values": [
1.75,
1.85
]
}
]
},
{
"Param": "Path.Learn.LRate",
"Sel": {
"Sel": "Path",
"Desc": "norm and momentum on works better, but wt bal is not better for smaller nets",
"Params": {
"Path.Learn.LRate": "0.02",
"Path.Learn.Momentum": "0.9"
},
"Hypers": {
"Path.Learn.LRate": {
"Tweak": "log"
},
"Path.Learn.Momentum": {
"Tweak": "incr"
}
}
},
"Search": [
{
"Name": "HiddenToInput",
"Type": "Path",
"Path": "Path.Learn.LRate",
"Start": 0.02,
"Values": [
0.01,
0.05
]
},
{
"Name": "InputToHidden",
"Type": "Path",
"Path": "Path.Learn.LRate",
"Start": 0.02,
"Values": [
0.01,
0.05
]
}
]
},
{
"Param": "Path.Learn.Momentum",
"Sel": {
"Sel": "Path",
"Desc": "norm and momentum on works better, but wt bal is not better for smaller nets",
"Params": {
"Path.Learn.LRate": "0.02",
"Path.Learn.Momentum": "0.9"
},
"Hypers": {
"Path.Learn.LRate": {
"Tweak": "log"
},
"Path.Learn.Momentum": {
"Tweak": "incr"
}
}
},
"Search": [
{
"Name": "HiddenToInput",
"Type": "Path",
"Path": "Path.Learn.Momentum",
"Start": 0.9,
"Values": [
0.8,
1
]
},
{
"Name": "InputToHidden",
"Type": "Path",
"Path": "Path.Learn.Momentum",
"Start": 0.9,
"Values": [
0.8,
1
]
}
]
}
]
`
func TestTweakHypers(t *testing.T) {
hypers := Flex{}
hypers.Init([]FlexVal{
FlexVal{Name: "Input", Type: "Layer", Class: "Input", Object: Hypers{}},
FlexVal{Name: "Hidden", Type: "Layer", Class: "Hidden", Object: Hypers{}},
FlexVal{Name: "InputToHidden", Type: "Path", Class: "Forward", Object: Hypers{}},
FlexVal{Name: "HiddenToInput", Type: "Path", Class: "Back", Object: Hypers{}},
})
basenet := tweakSets["Base"]
hypers.ApplySheet(basenet, false)
// fmt.Println("hypers:", reflectx.StringJSON(hypers))
srch := TweaksFromHypers(hypers)
ss := reflectx.StringJSON(srch)
// fmt.Println("\n\n##########\n", ss)
assert.Equal(t, trgSearch, ss)
}