As it seemed to me that your data is organized as follows, each row you have the record of a single variable in 4 time sequences, Q_t is the value you want to predict based on sequence of the last 3 values of Q_t_1, Q_t_2, Q_t_3 .
So you have such a setup:
n_samples <- nrow(data)
timesteps <- 3
n_variables <- 1
To fit the data appropriately for training, you have to create a three-dimensional array. Then you can iterate over the original dataset and allocate the values inside the sample array by sample.
data_X <- array(NA, dim=c(n_samples, timesteps, n_variables))
data_Y <- array(NA, dim=c(n_samples, 1, 1))
for(i in 1:n_samples){
data_X[i,,1] <- unlist(data[i, c("Q_t_1", "Q_t_2", "Q_t_3")])
data_Y[i,,1] <- unlist(data[i, "Q_t"])
}
If you had one more variable, say R_t _ * , it would stay in 'data_X [i , 2], and so on.
To perform the training, it is the same as the tutorial you mentioned, except now seq_to_seq_unsync
must be TRUE
, because the model must return a single value from the input sequence. Unlike the tutorial in which the model returns a sequence of the same size as the input.
model <- trainr(Y=data_Y, X=data_X, hidden_dim=100,
learningrate=0.1, batch_size=1, numepochs=100,
seq_to_seq_unsync=T)
plot(colMeans(model$error), type="l")
# predita sobre o conjunto de treinamento
data_H <- predictr(model, data_X)
# compara o valor com real com a hipótese
head(cbind(data_Y, data_H))