我想在Tensorflow中使用RNN预测一组6个时间序列。我希望输入长度为12个观测值(每个时间序列),输出长度为18个观测值(每个时间序列)。我似乎无法使其正常工作。如果将预测范围设置为等于输入长度,则下面的代码将起作用。 谢谢!
f_horizon = 18 # Forecast horizon
num_periods = 12 # Input length
X = tf.placeholder(tf.float32, [None, num_periods, 6])
Y = tf.placeholder(tf.float32, [None, f_horizon, 6])
layers = [tf.nn.rnn_cell.LSTMCell(num_units=hi, activation=tf.nn.relu) for hi in hidden]
drops = [tf.contrib.rnn.DropoutWrapper(layer, output_keep_prob=dropout_prop) for layer in layers]
drops.append(tf.nn.rnn_cell.LSTMCell(num_units=f_horizon, activation=tf.nn.relu))
multi_layer_cell = tf.contrib.rnn.MultiRNNCell(drops)
rnn_output, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)
stacked_rnn_output = tf.reshape(rnn_output, [-1, f_horizon])
stacked_outputs = tf.layers.dense(stacked_rnn_output, 6)
outputs = tf.reshape(stacked_outputs, [-1, f_horizon, 6])
loss = tf.reduce_mean(tf.square(outputs - Y))