2021-12-15 16:15:16 +01:00
|
|
|
import numpy as np
|
|
|
|
import random
|
|
|
|
from sobek.network import network
|
|
|
|
|
|
|
|
random.seed()
|
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
myNetwork = network(1, 10)
|
2021-12-15 16:15:16 +01:00
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
learningRate = 1
|
|
|
|
|
|
|
|
for j in range(100000):
|
2021-12-15 16:15:16 +01:00
|
|
|
inputs = []
|
|
|
|
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-15 16:15:16 +01:00
|
|
|
inputs.append([random.randrange(10)])
|
|
|
|
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-16 23:05:27 +01:00
|
|
|
desiredOutputs[i][9 - inputs[i][0]] = 1.0
|
2021-12-15 16:15:16 +01:00
|
|
|
desiredOutputs = np.array(desiredOutputs, dtype=object)
|
2021-12-16 23:05:27 +01:00
|
|
|
|
|
|
|
if (j%10000 == 0):
|
|
|
|
learningRate*= 0.1
|
|
|
|
myNetwork.train(inputs, desiredOutputs, learningRate)
|
2021-12-15 16:15:16 +01:00
|
|
|
|
2021-12-16 23:05:27 +01:00
|
|
|
print(myNetwork.process(np.array([0.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([1.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([2.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([3.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([4.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([5.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([6.0], dtype=object)))
|
|
|
|
print(myNetwork.process(np.array([7.0], dtype=object)))
|
2021-12-15 16:15:16 +01:00
|
|
|
print(myNetwork.process(np.array([8.0], dtype=object)))
|
2021-12-16 23:05:27 +01:00
|
|
|
print(myNetwork.process(np.array([9.0], dtype=object)))
|