train.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import numpy as np
  2. from nn import NeuralNetwork
  3. # _
  4. # | |
  5. # _
  6. # | |
  7. # _
  8. # 1
  9. # 2 3
  10. # 4
  11. # 5 6
  12. # 7
  13. dataset = [
  14. [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], #1
  15. [1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0], #2
  16. [1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0], #3
  17. [0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0], #4
  18. [1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0], #5
  19. [1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0], #6
  20. [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], #7
  21. [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], #8
  22. [1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0], #9
  23. ]
  24. results = [
  25. [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  26. [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  27. [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  28. [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  29. [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  30. [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
  31. [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
  32. [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
  33. [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
  34. [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
  35. ]
  36. nn = NeuralNetwork(input_layer_size=7, hidden_layer_size=16, output_layer_size=10)
  37. nn.learning(dataset, results, 500, 0.1)
  38. nn.save('test.npz')