PT21-22-Reseau-Neurones/testLearning.py

45 lines
1019 B
Python
Raw Normal View History

import numpy as np
import random
from sobek.network import network
random.seed()
2021-12-17 08:36:45 +01:00
myNetwork = network(10, 10)
learningRate = 1
2021-12-17 08:36:45 +01:00
for j in range(10000):
inputs = []
2021-12-17 08:36:45 +01:00
inputs2 = []
desiredOutputs = []
2021-12-16 17:06:51 +01:00
if (j%50 == 0):
print(j)
for i in range(1000):
2021-12-17 08:36:45 +01:00
inputs.append([(random.randrange(10)/10)])
inputs = np.array(inputs, dtype=object)
for i in range(1000):
desiredOutputs.append([0]*10)
2021-12-17 08:36:45 +01:00
desiredOutputs[i][9 - int(inputs[i][0]*10)] = 1.0
desiredOutputs = np.array(desiredOutputs, dtype=object)
2021-12-17 08:36:45 +01:00
for i in range(1000):
inputs2.append([0]*10)
inputs2[i][int(inputs[i][0]*10)] = 1.0
inputs2 = np.array(inputs2, dtype=object)
if (j%10000 == 0):
learningRate*= 0.1
2021-12-17 08:36:45 +01:00
myNetwork.train(inputs2, desiredOutputs, learningRate)
test = []
test.append([0]*10)
test.append([0]*10)
test[0][1] = 1.0
test[1][8] = 1.0
test = np.array(test, dtype=object)
print(myNetwork.process(test[0]))
print(myNetwork.process(test[1]))