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.