|
@@ -0,0 +1,67 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ genetic "../neuralnetwork/genetic"
|
|
|
|
+ mutagen "../neuralnetwork/genetic/mutagen"
|
|
|
|
+ snakesimulator "./snakesimulator"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ s := snakesimulator.NewSnakeSimulator(400)
|
|
|
|
+ s.StartServer()
|
|
|
|
+ p := genetic.NewPopulation(s, mutagen.NewDummyMutagen(1.0, 1), genetic.PopulationConfig{PopulationSize: 2000, SelectionSize: 0.01, CrossbreedPart: 0.5}, []int{24, 18, 18, 4})
|
|
|
|
+ p.NaturalSelection(5000)
|
|
|
|
+ // s.Run()
|
|
|
|
+
|
|
|
|
+ // sizes := []int{13, 8, 12, 3}
|
|
|
|
+ // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewRPropInitializer(neuralnetwork.RPropConfig{
|
|
|
|
+ // NuPlus: 1.2,
|
|
|
|
+ // NuMinus: 0.5,
|
|
|
|
+ // DeltaMax: 50.0,
|
|
|
|
+ // DeltaMin: 0.000001,
|
|
|
|
+ // }))
|
|
|
|
+
|
|
|
|
+ // nn.SetStateWatcher(rc)
|
|
|
|
+ // rc.Run()
|
|
|
|
+
|
|
|
|
+ // inFile, err := os.Open("./networkstate")
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // log.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // defer inFile.Close()
|
|
|
|
+ // nn.LoadState(inFile)
|
|
|
|
+
|
|
|
|
+ // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewBackPropInitializer(0.1))
|
|
|
|
+
|
|
|
|
+ // for i := 0; i < nn.Count; i++ {
|
|
|
|
+ // if i > 0 {
|
|
|
|
+ // fmt.Printf("Weights before:\n%v\n\n", mat.Formatted(nn.Weights[i], mat.Prefix(""), mat.Excerpt(0)))
|
|
|
|
+ // fmt.Printf("Biases before:\n%v\n\n", mat.Formatted(nn.Biases[i], mat.Prefix(""), mat.Excerpt(0)))
|
|
|
|
+ // fmt.Printf("Z before:\n%v\n\n", mat.Formatted(nn.Z[i], mat.Prefix(""), mat.Excerpt(0)))
|
|
|
|
+ // }
|
|
|
|
+ // fmt.Printf("A before:\n%v\n\n", mat.Formatted(nn.A[i], mat.Prefix(""), mat.Excerpt(0)))
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // nn = &neuralnetwork.NeuralNetwork{}
|
|
|
|
+ // inFile, err := os.Open("./data")
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // log.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // defer inFile.Close()
|
|
|
|
+ // nn.LoadState(inFile)
|
|
|
|
+ // inFile.Close()
|
|
|
|
+
|
|
|
|
+ // failCount = 0
|
|
|
|
+ // training.Reset()
|
|
|
|
+ // for training.NextValidator() {
|
|
|
|
+ // dataSet, expect := training.GetValidator()
|
|
|
|
+ // index, _ := nn.Predict(dataSet)
|
|
|
|
+ // if expect.At(index, 0) != 1.0 {
|
|
|
|
+ // failCount++
|
|
|
|
+ // // fmt.Printf("Fail: %v, %v\n\n", training.ValidationIndex(), expect.At(index, 0))
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // fmt.Printf("Fail count: %v\n\n", failCount)
|
|
|
|
+
|
|
|
|
+}
|