main.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. package main
  26. import (
  27. "git.semlanik.org/semlanik/NeuralNetwork/neuralnetwork"
  28. "git.semlanik.org/semlanik/NeuralNetwork/neuralnetwork/gradients"
  29. )
  30. func main() {
  31. rc := NewRemoteControl()
  32. sizes := []int{13, 8, 12, 3}
  33. nn, _ := neuralnetwork.NewNeuralNetwork(sizes, gradients.NewRPropInitializer(gradients.RPropConfig{
  34. NuPlus: 1.2,
  35. NuMinus: 0.5,
  36. DeltaMax: 50.0,
  37. DeltaMin: 0.000001,
  38. }))
  39. nn.SetStateWatcher(rc)
  40. rc.RunServices()
  41. // inFile, err := os.Open("./networkstate")
  42. // if err != nil {
  43. // log.Fatal(err)
  44. // }
  45. // defer inFile.Close()
  46. // nn.LoadState(inFile)
  47. // nn, _ := neuralnetwork.NewNeuralNetwork(sizes, neuralnetwork.NewBackPropInitializer(0.1))
  48. // for i := 0; i < nn.Count; i++ {
  49. // if i > 0 {
  50. // fmt.Printf("Weights before:\n%v\n\n", mat.Formatted(nn.Weights[i], mat.Prefix(""), mat.Excerpt(0)))
  51. // fmt.Printf("Biases before:\n%v\n\n", mat.Formatted(nn.Biases[i], mat.Prefix(""), mat.Excerpt(0)))
  52. // fmt.Printf("Z before:\n%v\n\n", mat.Formatted(nn.Z[i], mat.Prefix(""), mat.Excerpt(0)))
  53. // }
  54. // fmt.Printf("A before:\n%v\n\n", mat.Formatted(nn.A[i], mat.Prefix(""), mat.Excerpt(0)))
  55. // }
  56. // nn = &neuralnetwork.NeuralNetwork{}
  57. // inFile, err := os.Open("./data")
  58. // if err != nil {
  59. // log.Fatal(err)
  60. // }
  61. // defer inFile.Close()
  62. // nn.LoadState(inFile)
  63. // inFile.Close()
  64. // failCount = 0
  65. // training.Reset()
  66. // for training.NextValidator() {
  67. // dataSet, expect := training.GetValidator()
  68. // index, _ := nn.Predict(dataSet)
  69. // if expect.At(index, 0) != 1.0 {
  70. // failCount++
  71. // // fmt.Printf("Fail: %v, %v\n\n", training.ValidationIndex(), expect.At(index, 0))
  72. // }
  73. // }
  74. // fmt.Printf("Fail count: %v\n\n", failCount)
  75. }