diff --git a/README.md b/README.md index 642836c..3daa4e3 100644 --- a/README.md +++ b/README.md @@ -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.