12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package main
- import (
- genetic "./genetic"
- mutagen "./genetic/mutagen"
- remotecontrol "./remotecontrol"
- snakesimulator "./snakesimulator"
- )
- func main() {
- rc := &remotecontrol.RemoteControl{}
- go rc.Run()
- s := snakesimulator.NewSnakeSimulator(300)
- 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})
- for _, net := range p.Networks {
- net.SetStateWatcher(rc)
- }
- 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)
- }
|