# simple LSTM model from keras.models import Sequential from keras.layers import Activation, Dense, LSTM model = Sequential() model.add(LSTM(128, input_shape=(32, 1))) # 32 timespan 1 value unit model.add(Dense(1)) model.add(Activation("linear")) model.compile(optimizer="rmsprop", loss="mse") # several sin curve data for train import numpy as np for cycle in range(4, 36): data = np.sin(np.arange(360) * (np.pi / cycle)) # chunk to 32-timespan and its 1-next value x_train = np.reshape( [data[i:i+32] for i in range(len(data) - 32 - 1)], (-1, 32, 1)) y_train = np.reshape( [data[i+32] for i in range(len(data) - 32 - 1)], (-1, 1)) model.fit(x_train, y_train, verbose = False) pass # make initial curve data x = np.sin(np.arange(32) * np.pi / 18 + 3 * np.pi / 4) # generate subsequent curve for i in range(300): y = model.predict(x[-32:].reshape(1, 32, 1)) x = np.append(x, y) pass # plot curve import matplotlib.pyplot as plt fig = plt.figure() sub = fig.add_subplot(1, 1, 1) sub.plot(x[32:]) fig.show() input("quit to enter> ")