-
Notifications
You must be signed in to change notification settings - Fork 1
/
testdata.go
268 lines (246 loc) · 6.56 KB
/
testdata.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
259
260
261
262
263
264
265
266
267
268
package mep
import (
"fmt"
"math"
"math/rand"
)
type testData struct {
xmin float64
xmax float64
eval func(terms []float64) float64
}
func (t *testData) generate(numTraining, numVariables int) TrainingData {
td := TrainingData{}
td.Labels = make([]string, numVariables)
for i := 0; i < numVariables; i++ {
td.Labels[i] = fmt.Sprintf("x%d", i)
}
td.Train = make([][]float64, numTraining)
td.Target = make([]float64, numTraining)
for i := 0; i < numTraining; i++ {
td.Train[i] = make([]float64, numVariables)
for j := 0; j < numVariables; j++ {
td.Train[i][j] = rand.Float64()*(t.xmax-t.xmin) + t.xmin
}
td.Target[i] = t.eval(td.Train[i])
}
return td
}
// NewAckley -
func NewAckley(numTraining int) TrainingData {
testdata := testData{
xmin: -32,
xmax: 32,
eval: func(terms []float64) float64 {
n := float64(len(terms))
a := 20.0
b := 0.2
c := 2.0 * math.Pi
s1 := 0.0
s2 := 0.0
for i := 0; i < len(terms); i++ {
s1 = math.Pow(s1+terms[i], 2)
s2 = s2 + math.Cos(c*terms[i])
}
return -a*math.Exp(-b*math.Sqrt(1.0/n*s1)) - math.Exp(1.0/n*s2) + a + math.Exp(1.0)
},
}
return testdata.generate(numTraining, 2)
}
// NewRosenbrock -
func NewRosenbrock(numTraining int) TrainingData {
testdata := testData{
xmin: -32,
xmax: 32,
eval: func(terms []float64) float64 {
sum := 0.0
for i := 0; i < len(terms)-1; i++ {
sum = sum + 100*math.Pow((math.Pow(terms[i], 2)-terms[i+1]), 2) + math.Pow(terms[i]-1, 2)
}
return sum
},
}
return testdata.generate(numTraining, 2)
}
// NewPiTest -
func NewPiTest(numTraining int) TrainingData {
testdata := testData{
xmin: 0,
xmax: 0,
eval: func(terms []float64) float64 {
return math.Pi
},
}
return testdata.generate(numTraining, 1)
}
// NewRastigrinF1 -
func NewRastigrinF1(numTraining int) TrainingData {
testdata := testData{
xmin: -5.12,
xmax: 5.12,
eval: func(terms []float64) float64 {
n := float64(len(terms))
s := 0.0
for i := 0; i < len(terms); i++ {
s = s + (math.Pow(terms[i], 2) - 10*math.Cos(2*math.Pi*terms[i]))
}
return 10*n + s
},
}
return testdata.generate(numTraining, 2)
}
// NewQuarticPoly -
func NewQuarticPoly(numTraining int) TrainingData {
testdata := testData{
xmin: -1,
xmax: 1,
eval: func(terms []float64) float64 {
return math.Pow(terms[0], 4) + math.Pow(terms[0], 3) + math.Pow(terms[0], 2) + terms[0]
},
}
return testdata.generate(numTraining, 1)
}
// NewPythagorean -
func NewPythagorean(numTraining int) TrainingData {
testdata := testData{
xmin: 5,
xmax: 50,
eval: func(terms []float64) float64 {
return math.Sqrt((terms[0] * terms[0]) + (terms[1] * terms[1]))
},
}
return testdata.generate(numTraining, 2)
}
// NewDejongF1 -
func NewDejongF1(numTraining int) TrainingData {
testdata := testData{
xmin: -5.12,
xmax: 5.12,
eval: func(terms []float64) float64 {
return math.Pow(terms[0], 2) + math.Pow(terms[1], 2)
},
}
return testdata.generate(numTraining, 2)
}
// NewSchwefel -
func NewSchwefel(numTraining int) TrainingData {
testdata := testData{
xmin: -1,
xmax: 1,
eval: func(terms []float64) float64 {
return -terms[0]*math.Sin(math.Sqrt(math.Abs(terms[0]))) - terms[1]*math.Sin(math.Sqrt(math.Abs(terms[1])))
},
}
return testdata.generate(numTraining, 2)
}
// NewSequenceInduction -
func NewSequenceInduction(numTraining int) TrainingData {
testdata := testData{
xmin: 5,
xmax: 50,
eval: func(terms []float64) float64 {
return ((5.0 * math.Pow(terms[0], 4)) + (4.0 * math.Pow(terms[0], 3)) + (3.0 * math.Pow(terms[0], 2)) + (2.0 * terms[0]) + 1.0)
},
}
return testdata.generate(numTraining, 1)
}
// NewDropwave -
func NewDropwave(numTraining int) TrainingData {
testdata := testData{
xmin: -5.12,
xmax: 5.12,
eval: func(terms []float64) float64 {
return -(1.0 + math.Cos(12*math.Sqrt(terms[0]*terms[0]+terms[1]*terms[1]))) / (0.5*(terms[0]*terms[0]+terms[1]*terms[1]) + 2)
},
}
return testdata.generate(numTraining, 2)
}
// NewMichalewicz -
func NewMichalewicz(numTraining int) TrainingData {
testdata := testData{
xmin: -5.12,
xmax: 5.12,
eval: func(terms []float64) float64 {
return -math.Sin(terms[0])*math.Pow(math.Sin(terms[0]*terms[0]/math.Pi), 2) - math.Sin(terms[1])*math.Pow(math.Sin(terms[1]*terms[1]/math.Pi), 2)
},
}
return testdata.generate(numTraining, 2)
}
// NewSchafferF6 -
func NewSchafferF6(numTraining int) TrainingData {
testdata := testData{
xmin: -5.12,
xmax: 5.12,
eval: func(terms []float64) float64 {
return 0.5 + (math.Pow(math.Sin(math.Sqrt(terms[0]*terms[0]+terms[1]*terms[1])), 2)-0.5)/math.Pow(1+0.001*(terms[0]*terms[0]+terms[1]*terms[1]), 2)
},
}
return testdata.generate(numTraining, 2)
}
// NewSixHump -
func NewSixHump(numTraining int) TrainingData {
testdata := testData{
xmin: -1,
xmax: 1,
eval: func(terms []float64) float64 {
return (4.0-2.1*terms[0]*terms[0]+math.Pow(terms[0], 4)/3)*terms[0]*terms[0] + terms[0]*terms[1] + (-4+4*terms[1]*terms[1])*terms[1]*terms[1]
},
}
return testdata.generate(numTraining, 2)
}
// NewSimpleConstantRegression1 -
func NewSimpleConstantRegression1(numTraining int) TrainingData {
testdata := testData{
xmin: 1,
xmax: 20,
eval: func(terms []float64) float64 {
return (math.Pow(terms[0], 3) - 0.3*math.Pow(terms[0], 2) - 0.4*terms[0] - 0.6)
},
}
return testdata.generate(numTraining, 1)
}
// NewSimpleConstantRegression2 -
func NewSimpleConstantRegression2(numTraining int) TrainingData {
testdata := testData{
xmin: 1,
xmax: 20,
eval: func(terms []float64) float64 {
return terms[0]*terms[0] + math.Pi
},
}
return testdata.generate(numTraining, 1)
}
// NewSimpleConstantRegression3 -
func NewSimpleConstantRegression3(numTraining int) TrainingData {
testdata := testData{
xmin: 1,
xmax: 20,
eval: func(terms []float64) float64 {
return (math.E * terms[0] * terms[0]) + (math.Pi * terms[0])
},
}
return testdata.generate(numTraining, 1)
}
// NewKepler -
func NewKepler(numTraining int) TrainingData {
// period = sqrt(distance^3)
return TrainingData{
// Venus, Earth, Mars, Jupiter, Saturn, Uranus
Train: [][]float64{[]float64{0.72}, []float64{1.0}, []float64{1.52}, []float64{5.2}, []float64{9.53}, []float64{19.6}},
Target: []float64{0.61, 1.0, 1.84, 11.9, 29.4, 83.5},
Labels: []string{"distance", "period"},
}
}
// NewBooth -
func NewBooth(numTraining int) TrainingData {
testdata := testData{
xmin: -10,
xmax: 10,
eval: func(terms []float64) float64 {
term1 := math.Pow(terms[0]+2*terms[1]-7, 2)
term2 := math.Pow(2*terms[0]+terms[1]-5, 2)
return term1 + term2
},
}
return testdata.generate(numTraining, 2)
}