forked from goml/gobrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedforward_test.go
46 lines (37 loc) · 1.14 KB
/
feedforward_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
package gobrain
import (
// "testing"
"math/rand"
)
func ExampleSimpleFeedForward() {
// set the random seed to 0
rand.Seed(0)
// create the XOR representation patter to train the network
patterns := [][][]float64{
{{0, 0}, {0}},
{{0, 1}, {1}},
{{1, 0}, {1}},
{{1, 1}, {0}},
}
// instantiate the Feed Forward
ff := &FeedForward{}
// initialize the Neural Network;
// the networks structure will contain:
// 2 inputs, 2 hidden nodes and 1 output.
ff.Init(2, 2, 1)
// train the network using the XOR patterns
// the training will run for 1000 epochs
// the learning rate is set to 0.6 and the momentum factor to 0.4
// use true in the last parameter to receive reports about the learning error
ff.Train(patterns, 1000, 0.6, 0.4, false)
// testing the network
ff.Test(patterns)
// predicting a value
inputs := []float64{1, 1}
ff.Update(inputs)
// Output:
// [0 0] -> [0.057503945708445206] : [0]
// [0 1] -> [0.9301006350712101] : [1]
// [1 0] -> [0.9278099662272838] : [1]
// [1 1] -> [0.09740879532462123] : [0]
}