Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wildneuro authored Jan 10, 2018
1 parent 735a9ae commit 8c38aea
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,40 @@ The version `1.0.0` includes just basic Neural Network functions such as Feed Fo
A simple Feed Forward Neural Network can be constructed and trained as follows:

```go
// 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}},
package main

import (
"github.com/goml/gobrain"
"math/rand"
)

func main() {
// 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 := &gobrain.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, true)
}

// instantiate the Feed Forward
ff := &gobrain.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, true)
```

After running this code the network will be trained and ready to be used.
Expand Down

0 comments on commit 8c38aea

Please sign in to comment.