how to define the input array for RNA training in the rnn package?

2

In the rnn package there is an example of how to do network training, which is described in this link (example 1). In the approach of this package the entries are given in the format of a array 3D, where the dim 1: samples; dim 2: time; dim 3: variables, however not making explicit the division of inputs and targets and targets, which is a common approach in RNA packets. Moreover, in the package description both the entries and the targets must have the same dimension. So, how can I define my dataset for the recurring neural network in the rnn package?

These would be examples of my training data in a < in> data frame inputs:

Thistargets(targets):

    
asked by anonymous 08.08.2017 / 07:38

1 answer

0

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))
    
24.09.2017 / 20:41