from MLLibrary.Models.LSTMNet import LSTMNet from random import choice import numpy import matplotlib.pyplot as plt from datetime import datetime S = 1 LSTM = LSTMNet(S, S, S + 1) Iterations = 20000 learning_rate = 0.5 start_time = datetime.now() inputs = [] error = [] accuracy = [] in_ = [] label = [] prediction = [] expected = [] input = [[]] for j in range(S): input[0].append(choice([0.0, 1.0])) #-1.0, inputs.append(input) for i in range(Iterations): input = [[]] for j in range(S): input[0].append(choice([0.0, 1.0])) #-1.0, inputs.append(input)
import sys from MLLibrary.Models.LSTMNet import LSTMNet import numpy I = 1 O = 4 D = 4 LSTM = LSTMNet(I, O, D) MAX_ITER = 1000000 BATCH = 100 LEARNING_RATIO = 3.0 def get_X(): index = 1 while True: index += 1 numpy.random.seed(index) yield [[numpy.random.choice([0.0, 1.0])]] def get_Y(): index = 1 while True: numpy.random.seed(index) b1 = numpy.random.choice([0.0, 1.0]) index += 1 numpy.random.seed(index) b2 = numpy.random.choice([0.0, 1.0]) yield [[(b1 == 1.0 and b2 == 1.0), None, None, None]]
from MLLibrary.Models.LSTMNet import LSTMNet from random import choice import numpy import matplotlib.pyplot as plt I = 2 O = 1 D = 2 LSTM = LSTMNet(I, O, D) inputs = [] error = [] accuracy = [] in_ = [] label = [] for i in range(10000): input = [[]] for j in range(I): input[0].append(choice([0.0, 1.0])) #-1.0, inputs.append(input) if len(inputs) > 2: inputs = inputs[-2:] X = numpy.array(input) Y = numpy.array(1.0 if (input[0][0] == 1.0 and input[0][0] == 1.0) else 0.0) #inputs[0] LSTM.set_in(X) P = LSTM.get_out() d = numpy.zeros((1, 3)) d = (Y - P)/2.0 error.append(numpy.sum((Y - P)**2.0)) accuracy.append(numpy.sum((Y - numpy.round(P))**2.0))
from MLLibrary.Models.LSTMNet import LSTMNet from random import choice import numpy import matplotlib.pyplot as plt S = 1 LSTM = LSTMNet(S, S, S + 1) inputs = [] error = [] accuracy = [] in_ = [] label = [] for i in range(10000): input = [[]] for j in range(S): input[0].append(choice([0.0, 1.0])) #-1.0, inputs.append(input) if len(inputs) > 2: inputs = inputs[-2:] X = numpy.array(input) Y = numpy.array(input) #inputs[0] LSTM.set_in(X) P = LSTM.get_out() d = numpy.zeros((1, 3)) d = (Y - P) / 2.0 error.append(numpy.sum((Y - P)**2.0)) accuracy.append(numpy.sum((Y - numpy.round(P))**2.0)) in_.append(input[0][0]) label.append("One" if (input[0][0] == 1.0) else "Zero")
import sys from MLLibrary.Models.LSTMNet import LSTMNet import matplotlib.pyplot as plt from MLLibrary.StatsHandler import StatsHandler I = 2 O = 1 D = 2 statsHandler = StatsHandler() LSTM = LSTMNet(I, O, D, statsHandler=statsHandler) MAX_ITER = 1000 BATCH = 10 LEARNING_RATIO = 0.01 def get_X(): while True: for b1 in [0.0, 1.0]: for b2 in [0.0, 1.0]: yield [[b1, b2]] def get_Y(): while True: for b1 in [False, True]: for b2 in [False, True]: yield 1.0 if (b1 and b2) else 0.0