1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import numpy as np
- from nn import NeuralNetwork
- # _
- # | |
- # _
- # | |
- # _
- # 1
- # 2 3
- # 4
- # 5 6
- # 7
- dataset = [
- [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], #1
- [1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0], #2
- [1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0], #3
- [0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0], #4
- [1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0], #5
- [1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0], #6
- [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0], #7
- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], #8
- [1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0], #9
- ]
- results = [
- [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
- [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
- ]
- nn = NeuralNetwork(input_layer_size=7, hidden_layer_size=16, output_layer_size=10)
- nn.learning(dataset, results, 500, 0.1)
- nn.save('test.npz')
|