def T13(): ''' Tests restoring a model from file ''' m1 = ANNR([4], [('F', 4), ('AF', 'tanh'), ('F', 1)], maxIter = 16, name = 't12ann1') rv = m1.RestoreModel('./', 't12ann1') return rv
def T14(): ''' Tests saving and restore a model ''' A = np.random.rand(32, 4) Y = (A.sum(axis = 1) ** 2).reshape(-1, 1) m1 = ANNR([4], [('F', 4), ('AF', 'tanh'), ('F', 1)], maxIter = 16, name = 't12ann1') m1.fit(A, Y) m1.SaveModel('./t12ann1') R1 = m1.GetWeightMatrix(0) ANN.Reset() m1 = ANNR([4], [('F', 4), ('AF', 'tanh'), ('F', 1)], maxIter = 16, name = 't12ann2') m1.RestoreModel('./', 't12ann1') R2 = m1.GetWeightMatrix(0) if (R1 != R2).any(): return False return True
layers = [('F', int(h)), ('AF', 'tanh'), ('F', int(h / 2)), ('AF', 'tanh'), ('F', int(h / 4)), ('AF', 'tanh'), ('F', int(h / 8)), ('AF', 'tanh'), ('F', int(h / 16)), ('AF', 'tanh'), ('F', int(h / 16)), ('AF', 'tanh'), ('F', int(h / 32)), ('AF', 'tanh'), ('F', int(h / 64)), ('AF', 'tanh'), ('F', o)] # """ mlpr = ANNR([i], layers, batchSize=256, maxIter=100000, tol=0.05, reg=1e-4, verbose=True, name='Stocker') mlpr.RestoreModel('model/', mlpr.name) #Begin prediction yHat = mlpr.predict(A) y = scaler.inverse_transform(y) A = scaler.inverse_transform(A) yHat = scaler.inverse_transform(yHat) #Plot the results mpl.plot(A[-20:-future_n], y[-(20 - future_n):], c='#b0403f', label='Stock value') mpl.plot(A[-20:], yHat[-20:], c='#5aa9ab', label='Stock Estimate') mpl.xlabel('Days (20 days) scaled') mpl.ylabel('Value') mpl.title('Apple Stocks vs Estimates') mpl.legend()