2021-12-15 16:15:16 +01:00
|
|
|
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)
|
2021-12-15 16:15:16 +01:00
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
learningRate = 1
|
|
|
|
|
2021-12-17 08:36:45 +01:00
|
|
|
for j in range(10000):
|
2021-12-15 16:15:16 +01:00
|
|
|
inputs = []
|
2021-12-17 08:36:45 +01:00
|
|
|
inputs2 = []
|
2021-12-15 16:15:16 +01:00
|
|
|
desiredOutputs = []
|
2021-12-16 17:06:51 +01:00
|
|
|
|
|
|
|
if (j%50 == 0):
|
|
|
|
print(j)
|
2021-12-15 16:15:16 +01:00
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
for i in range(1000):
|
2021-12-17 08:36:45 +01:00
|
|
|
inputs.append([(random.randrange(10)/10)])
|
2021-12-15 16:15:16 +01:00
|
|
|
inputs = np.array(inputs, dtype=object)
|
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
for i in range(1000):
|
2021-12-15 16:15:16 +01:00
|
|
|
desiredOutputs.append([0]*10)
|
2021-12-17 08:36:45 +01:00
|
|
|
desiredOutputs[i][9 - int(inputs[i][0]*10)] = 1.0
|
2021-12-15 16:15:16 +01:00
|
|
|
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)
|
2021-12-16 23:05:27 +01:00
|
|
|
|
|
|
|
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]))
|