From 9171e9cc52a2707e90ac28dddab0d3ccfa09ba62 Mon Sep 17 00:00:00 2001 From: Mihalis Tsoukalos Date: Sat, 15 Jun 2019 08:57:34 +0300 Subject: [PATCH] Simple Neural Network --- ch14/neural.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ch14/neural.go b/ch14/neural.go index 2fd0fd2..d0d9a45 100644 --- a/ch14/neural.go +++ b/ch14/neural.go @@ -2,8 +2,32 @@ package main import ( "fmt" + "math/rand" + "time" + + "github.com/goml/gobrain" ) func main() { + seed := time.Now().Unix() + rand.Seed(seed) + patterns := [][][]float64{ + {{0, 0, 0, 0}, {0}}, + {{0, 1, 0, 1}, {1}}, + {{1, 0, 1, 0}, {1}}, + {{1, 1, 1, 1}, {1}}, + } + + ff := &gobrain.FeedForward{} + ff.Init(4, 2, 1) + ff.Train(patterns, 1000, 0.6, 0.4, false) + + in := []float64{1, 1, 0, 1} + out := ff.Update(in) + fmt.Println(out) + + in = []float64{0, 0, 0, 0} + out = ff.Update(in) + fmt.Println(out) }