View seq3b.py
from keras.models import Sequential
from keras.layers import LSTM, TimeDistributed, Dense, Activation
from keras.models import load_model
import numpy as np
# same as 3a, but allow values between 0 and 10.
num_samples = 5000
num_steps = 10
max_distance = 10.0 #this needs to be 10.0 not 10...otherwise divide rounds to 0.
View seq3a
from keras.models import Sequential
from keras.layers import LSTM, TimeDistributed, Dense, Activation
from keras.models import load_model
import numpy as np
# predict (i.e., calculate, not predict based on a pattern) difference between consecutive numbers in sequence
# here i train using a batch size of 10, save the weights and then load into a model with batch size of 1 and num_steps = 1,
# i.e., something suitable for real-time continuous prediction.
View seq2d.py
from keras.models import Sequential
from keras.layers import LSTM, TimeDistributed, Dense, Activation
from keras.models import load_model
import numpy as np
# same as 2c except it saves model to file.
def train_model():
train_input = [np.random.randint(0,2) for r in xrange(1000)]
View seq2c.py
from keras.models import Sequential
from keras.layers import LSTM, TimeDistributed, Dense, Activation
import numpy as np
# predict whether two numbers in sequence are same or not.
# the only difference between this an seq2a is that it has 5 time steps.
# this works, except for first number in sequence (should output 0)...effectively there is only a single training example for the model to learn this
# since step 1 from all batches other than the first are initialized with state from last step of previous batch.
View seq2b.py
from keras.models import Sequential
from keras.layers import LSTM, Dense, Activation
import numpy as np
# predict whether two numbers in sequence are same or not.
# same as previous seq2a, but try to batch training.
#
# this doesn't work.
View seq2a
from keras.models import Sequential
from keras.layers import LSTM, Dense, Activation
import numpy as np
# predict whether two numbers in sequence are same or not.
# use a stateful LSTM
# this requires that i train with a batch size of 1 and a sequence size of 1
View seq1b.py
from keras.models import Sequential
from keras.layers import LSTM, TimeDistributed, Dense, Activation
import numpy as np
from random import shuffle
# counts number of 1's in a sequence of 10 steps, but outputs a runnint total at each step.
NUM_EXAMPLES = 1000
View seq1a.py
from keras.models import Sequential
from keras.layers import LSTM, Dense, Activation
import numpy as np
from random import shuffle
#based on: https://gist.github.com/monikkinom/e97d518fe02a79177b081c028a83ec1c
#train model to count number of 1's in a sequence of 20 time steps
NUM_EXAMPLES = 10000