def T12(): ''' Tests saving a model to file ''' 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') return True
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') #Learn the data mlpr.fit(A[0:(n - nDays)], y[0:(n - nDays)]) #save the model mlpr.SaveModel('model/' + mlpr.name) #Begin prediction yHat = mlpr.predict(A) #Plot the results mpl.plot(A[-20:], y[-20:], c='#b0403f') mpl.plot(A[-20:], yHat[-20:], c='#5aa9ab') mpl.show() mpl.plot(A, y, c='#b0403f') mpl.plot(A, yHat, c='#5aa9ab') mpl.show()