main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. genetic "./genetic"
  4. mutagen "./genetic/mutagen"
  5. remotecontrol "./remotecontrol"
  6. snakesimulator "./snakesimulator"
  7. )
  8. func main() {
  9. rc := &remotecontrol.RemoteControl{}
  10. go rc.Run()
  11. s := snakesimulator.NewSnakeSimulator()
  12. s.StartServer()
  13. p := genetic.NewPopulation(s, mutagen.NewDummyMutagen(50), genetic.PopulationConfig{PopulationSize: 2000, SelectionSize: 0.01, CrossbreedPart: 0.5}, []int{24, 18, 18, 4})
  14. for _, net := range p.Networks {
  15. net.SetStateWatcher(rc)
  16. }
  17. p.NaturalSelection(5000)
  18. // s.Run()
  19. // sizes := []int{13, 8, 12, 3}
  20. // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewRPropInitializer(neuralnetwork.RPropConfig{
  21. // NuPlus: 1.2,
  22. // NuMinus: 0.5,
  23. // DeltaMax: 50.0,
  24. // DeltaMin: 0.000001,
  25. // }))
  26. // nn.SetStateWatcher(rc)
  27. // rc.Run()
  28. // inFile, err := os.Open("./networkstate")
  29. // if err != nil {
  30. // log.Fatal(err)
  31. // }
  32. // defer inFile.Close()
  33. // nn.LoadState(inFile)
  34. // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewBackPropInitializer(0.1))
  35. // for i := 0; i < nn.Count; i++ {
  36. // if i > 0 {
  37. // fmt.Printf("Weights before:\n%v\n\n", mat.Formatted(nn.Weights[i], mat.Prefix(""), mat.Excerpt(0)))
  38. // fmt.Printf("Biases before:\n%v\n\n", mat.Formatted(nn.Biases[i], mat.Prefix(""), mat.Excerpt(0)))
  39. // fmt.Printf("Z before:\n%v\n\n", mat.Formatted(nn.Z[i], mat.Prefix(""), mat.Excerpt(0)))
  40. // }
  41. // fmt.Printf("A before:\n%v\n\n", mat.Formatted(nn.A[i], mat.Prefix(""), mat.Excerpt(0)))
  42. // }
  43. // nn = &neuralnetwork.NeuralNetwork{}
  44. // inFile, err := os.Open("./data")
  45. // if err != nil {
  46. // log.Fatal(err)
  47. // }
  48. // defer inFile.Close()
  49. // nn.LoadState(inFile)
  50. // inFile.Close()
  51. // failCount = 0
  52. // training.Reset()
  53. // for training.NextValidator() {
  54. // dataSet, expect := training.GetValidator()
  55. // index, _ := nn.Predict(dataSet)
  56. // if expect.At(index, 0) != 1.0 {
  57. // failCount++
  58. // // fmt.Printf("Fail: %v, %v\n\n", training.ValidationIndex(), expect.At(index, 0))
  59. // }
  60. // }
  61. // fmt.Printf("Fail count: %v\n\n", failCount)
  62. }