This is a toy version of what I'm actually trying to do. I have very large dimensional input data (sizes from 2e05 to 5e06) on a large number of time steps (150,000 steps). I understand that I may need some nesting / state compression at the end (see this question ). But let's put it aside for now.
Take this input of a toy with 11 sizes, for example
t Pattern
0 0,0,0,0,0,0,0,0,0,2,1
1 0,0,0,0,0,0,0,0,2,1,0
2 0,0,0,0,0,0,0,2,1,0,0
n ...
I want RNN to learn to associate the current time step with the next time step in such a way that if input (x) is t0, then the desired output (y) is t1.
The idea of using RNN is that I can only provide the network one step at a time (due to the large dimensionality of my real data). Since the number of inputs and outputs is the same, I'm not sure if the basic RNN is suitable. I looked at the seq2seq tutorial a bit, but I'm not sure if an encoder / decoder is needed for this application, and I could not use my game data anywhere.
The following is all that I managed to come up with, but it does not converge at all. What am I missing?
import numpy as np
import tensorflow as tf
from tensorflow.python.platform import gfile
import csv
wholeSequence = [[0,0,0,0,0,0,0,0,0,2,1],
[0,0,0,0,0,0,0,0,2,1,0],
[0,0,0,0,0,0,0,2,1,0,0],
[0,0,0,0,0,0,2,1,0,0,0],
[0,0,0,0,0,2,1,0,0,0,0],
[0,0,0,0,2,1,0,0,0,0,0],
[0,0,0,2,1,0,0,0,0,0,0],
[0,0,2,1,0,0,0,0,0,0,0],
[0,2,1,0,0,0,0,0,0,0,0],
[2,1,0,0,0,0,0,0,0,0,0]]
data = np.array(wholeSequence[:-1], dtype=int)
target = np.array(wholeSequence[1:], dtype=int)
trainingSet = tf.contrib.learn.datasets.base.Dataset(data=data, target=target)
trainingSetDims = trainingSet.data.shape[1]
EPOCHS = 10000
PRINT_STEP = 1000
x_ = tf.placeholder(tf.float32, [None, trainingSetDims])
y_ = tf.placeholder(tf.float32, [None, trainingSetDims])
cell = tf.nn.rnn_cell.BasicRNNCell(num_units=trainingSetDims)
outputs, states = tf.nn.rnn(cell, [x_], dtype=tf.float32)
outputs = outputs[-1]
W = tf.Variable(tf.random_normal([trainingSetDims, 1]))
b = tf.Variable(tf.random_normal([trainingSetDims]))
y = tf.matmul(outputs, W) + b
cost = tf.reduce_mean(tf.square(y - y_))
train_op = tf.train.RMSPropOptimizer(0.005, 0.2).minimize(cost)
with tf.Session() as sess:
tf.initialize_all_variables().run()
for i in range(EPOCHS):
sess.run(train_op, feed_dict={x_:trainingSet.data, y_:trainingSet.target})
if i % PRINT_STEP == 0:
c = sess.run(cost, feed_dict={x_:trainingSet.data, y_:trainingSet.target})
print('training cost:', c)
response = sess.run(y, feed_dict={x_:trainingSet.data})
print(response)
If the approach comes from this thread .
In the end, I would like to use LSTM, and the point is to simulate the sequence so that the approximation of the entire sequence can be restored by initiating a network with t0 and then feeding the prediction back as the next input.
EDIT1
, , :
wholeSequence = np.array(wholeSequence, dtype=float)
pdfSequence = wholeSequence*(1./np.sum(wholeSequence))
data = pdfSequence[:-1]
target = pdfSequence[1:]
- , , , - :
('training cost:', 0.49993864)
('training cost:', 0.0012213766)
('training cost:', 0.0010471855)
('training cost:', 0.00094231067)
('training cost:', 0.0008385859)
('training cost:', 0.00077578216)
('training cost:', 0.00071381911)
('training cost:', 0.00063783216)
('training cost:', 0.00061271922)
('training cost:', 0.00059178629)
[[ 0.02012676 0.02383044 0.02383044 0.02383044 0.02383044 0.02383044
0.02383044 0.02383044 0.02383044 0.01642305 0.01271933]
[ 0.02024871 0.02395239 0.02395239 0.02395239 0.02395239 0.02395239
0.02395239 0.02395239 0.02395239 0.016545 0.01284128]
[ 0.02013803 0.02384171 0.02384171 0.02384171 0.02384171 0.02384171
0.02384171 0.02384171 0.02384171 0.01643431 0.0127306 ]
[ 0.020188 0.02389169 0.02389169 0.02389169 0.02389169 0.02389169
0.02389169 0.02389169 0.02389169 0.01648429 0.01278058]
[ 0.02020025 0.02390394 0.02390394 0.02390394 0.02390394 0.02390394
0.02390394 0.02390394 0.02390394 0.01649654 0.01279283]
[ 0.02005926 0.02376294 0.02376294 0.02376294 0.02376294 0.02376294
0.02376294 0.02376294 0.02376294 0.01635554 0.01265183]
[ 0.02034193 0.02404562 0.02404562 0.02404562 0.02404562 0.02404562
0.02404562 0.02404562 0.02404562 0.01663822 0.01293451]
[ 0.02057907 0.02428275 0.02428275 0.02428275 0.02428275 0.02428275
0.02428275 0.02428275 0.02428275 0.01687536 0.01317164]
[ 0.02042386 0.02412754 0.02412754 0.02412754 0.02412754 0.02412754
0.02412754 0.02412754 0.02412754 0.01672015 0.01301643]]