0

I want to train the neural network using a sliding window.

I tried to check on the Internet, I found that it is possible if I use the rollapply function.

However, even looking at the example sentences, I could not understand how to use the rollapply function well.

For example, I use the window size as 120 and shift width as 10.

I wrote the code such as the following. But, Error returened!

library(AMORE)
#P is the input vector
P <- matrix(sample(seq(-1,1,length=1000), 1000, replace=FALSE), ncol=1) 
# The network will try to approximate the target P^2
target <- P^2 
data <- data.frame(P,target)
# We create a feedforward network, with two hidden layers.
# The first hidden layer has three neurons and the second has two neurons.
# The hidden layers have got Tansig activation functions and the output layer is Purelin.
net <- newff(n.neurons=c(1,3,2,1), learning.rate.global=1e-2, momentum.global=0.5,
        error.criterium="LMS", Stao=NA, hidden.layer="tansig", 
        output.layer="purelin", method="ADAPTgdwm")

b <- function(mydata){
    dd <- as.data.frame(mydata)
    result <- train(dd[,1],dd[,2], error.criterium="LMS", report=TRUE, show.step=100, n.shows=5 )
    y <- sim(result$net, dd[,1])
    return(y)
    }

a <- rollapply(data, width=128, by=10, FUN= b)

Please tell me how to train the neural network by using the rollapply function anyone.

Or, please tell me if there are another way to train the neural network using a sliding window.

Dai Koga
  • 41
  • 1
  • 2
  • Why don't you post the error ? Was it something about not being able to `rollapply` a `data.frame`? Or requiring a `vector` or `zoo` time-series object? If so maybe have a look at this: http://stackoverflow.com/questions/13771385/is-there-a-function-like-rollapply-for-data-frame – Stephen Henderson Dec 15 '13 at 23:28
  • The first argument to `train` (or the named "net"-argument) is _supposed_ to be the ff-object. The error message I got specifically pointed to a problem with the value of "net" being incorrect. – IRTFM Dec 16 '13 at 00:54
  • Thank you very much for a quick reply! And, I'm sorry... I had forgot to write the error message. In addition, because I had read in advance zoo library, I had forgotten to append to so. It is really embarrassing. The error is as follows. train (dd [, 1], dd [, 2], error.criterium = "LMS", report = TRUE,: Your net parameter does not belong to the MLPnet class. Are you aware that the result from the train function is now a list instead of a net? Check parameters and try again – Dai Koga Dec 16 '13 at 15:03

0 Answers0