I am trying to develop an encoder-decoder model and perform multi-step ahead forecasting with a look back window also included. My results look weird, and I am not sure about the reshaping steps and also the structure of my model.
First, you can see the structure of my model where I will have two different inputs and I use a single encoder to capture information from both of them. Then I use two different decoders, to predict two different output parameters (time series obtained from different sensors).
visible1 = Input(shape=(num_steps_look_back, 1))
visible2 = Input(shape=(num_steps_look_back, 1))
# Concatenate the input layers
concatenated = Concatenate(axis=2)([visible1, visible2])
# Encoder LSTM with Dropout
encoder = GRU(100, activation='relu')(concatenated)
#encoder = Dropout(0.1)(encoder)
# Decoder1 LSTM with RepeatVector and Dropout
decoder1 = RepeatVector(num_steps_ahead)(encoder)
decoder1 = LSTM(100, activation='relu', return_sequences=True)(decoder1)
decoder1 = Dropout(0.1)(decoder1)
decoder1 = TimeDistributed(Dense(1))(decoder1)
# Decoder2 LSTM with RepeatVector and Dropout
decoder2 = RepeatVector(num_steps_ahead)(encoder)
decoder2 = LSTM(100, activation='relu', return_sequences=True)(decoder2)
decoder2 = Dropout(0.1)(decoder2)
decoder2 = TimeDistributed(Dense(1))(decoder2)
model = Model(inputs=[visible1, visible2], outputs=[decoder1, decoder2])
Below is the code I use to create the sequencies (the example shows for testing but I have used the same for training).
for i in range(0, len(coldtrap_test) - num_steps_look_back - num_steps_ahead + 1,num_steps_ahead):
x_sequence_te_c = coldtrap_test[i:i + num_steps_look_back, 0]
y_sequence_te_c = coldtrap_test[i + num_steps_look_back:i + num_steps_look_back + num_steps_ahead, 0]
final_x_test_coldtrap.append(x_sequence_te_c)
final_y_test_coldtrap.append(y_sequence_te_c)
Before I predict with my model, I use the following code for reshaping:
final_x_test_coldtrap = np.array(final_x_test_coldtrap)
final_x_test_coldtrap = np.reshape(final_x_test_coldtrap, (final_x_test_coldtrap.shape[0], num_steps_look_back, 1))
final_y_test_coldtrap = np.array(final_y_test_coldtrap)
Finally, after predicting:
# Reshape predictions arrays
predictions_coldtrap = np.squeeze(predictions_coldtrap, axis=2)
# Inverse transform the predictions for coldtrap and heatup data
unscaled_predictions_coldtrap = scaler.inverse_transform(predictions_coldtrap)
unscaled_y_test_coldtrap = scaler.inverse_transform(final_y_test_coldtrap)
# Calculate RMSE
rmse_coldtrap = math.sqrt(mean_squared_error(unscaled_y_test_coldtrap.flatten(), unscaled_predictions_coldtrap.flatten()))
# Plot predictions vs real data for coldtrap
plt.figure(figsize=(12, 7))
plt.plot(unscaled_predictions_coldtrap.flatten(), color='#135485', label='Predictions-Coldtrap')
plt.plot(unscaled_y_test_coldtrap.flatten(), color='red', label='Real Data-Coldtrap')
plt.legend()
plt.xlabel('Time (s)')
plt.ylabel('Temperature (°C)')
Is the procedure correct? I don’t want to have overlapping predictions (multiple predictions for a specific timestep that I want to predict). I am concerned because my output for 5 steps ahead for example looks like I have many predictions for each timestep.
enter image description here
I am trying to understand how reshaping and dimensions in multi-step ahead forecasting works.