I have two questions about how to use R's RNN package, specifically the trainr and predictr functions.

Let's suppose I have a time series of 4000 steps for 5 different variables.

  1. How should this be passed on to the RNN, since the input has to be a 3D array? Should it be an array of dim(1, 4000, 5) or dim(4000,1,5) or something completely different?

Moreover, let's suppose I successfully train my RNN and would like to make some predictions using the predictr function.

  1. Which dimension will the output have and how can it be interpreted?

Until now I have tried to input the data as 3D array (4000, 1, 5) with the following code:

RecNN <- trainr(TrainR, TrainI, 
  learningrate = 0.003, momentum = 0.003, hidden_dim = c(100),
  network_type = "rnn", batch_size = 50,
  numepochs = 100, sigmoid = "logistic", use_bias = TRUE)

print("--- DONE LEARNING ---")

And then used the predictr function with the input (250, 1, 5):

results1 <- predictr(RecNN, TestI, hidden = TRUE, real_output = TRUE)

List of 2
 $ : num [1:250, 1, 1:100] 0 0 0 0 0 0 0 0 0 0 ...
 $ : num [1:250, 1, 1:2] 1 1 1 1 1 1 1 1 1 1 ...

Thanks a lot!

  • What code did you try and what error did you get? It will be helpful if you post your attempt here. – rnso Dec 5 at 13:59
  • I have added the code to the question now! – Alex Dec 5 at 14:04
  • If there is no error and output is sensible, this should be the correct approach. – rnso Dec 5 at 14:12
  • Ok, but still 1. How would be the correct way of passing the input during training? An array of dim(1, 4000, 5) or dim(4000,1,5)? And 2. I am not sure how to interpret the output, why are there two lists of different lengths? – Alex Dec 5 at 14:17
  • Check this and other posts on google search: quora.com/… – rnso Dec 5 at 14:23

The manual gives needed dimensions (see help on trainr function):

Dimensions of input X need to be as:

dim 1: samples
dim 2: time
dim 3: variables 

and dimensions of output Y should be:

dim 1: samples (must be equal to dim 1 of X)
dim 2: time (must be equal to dim 2 of X)
dim 3: variables (could be 1 or more, if a matrix, will be coerce to array)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.