Skip to main content
formatted
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

I've noticed that for sin()sin() like data, I need to use "decay"decay which is available in nnetnnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02)runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnetnnet not so dependent on the random initialization of the weights?

while(runNN(0.02)>0.1){} #This works but it seems sloppy.

while(runNN(0.02)>0.1){} # This works but it seems sloppy.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.


library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds)
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

library(quantmod)
library(nnet)
print("start")
runNN = function(decayParam) {  
  data = data.frame(h=1:24); 
  data$qty <- sin(data$h/48*2*pi)*1000
  data$v = c(paste("actual",decayParam))
  mynn <- nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) 
  pred = data.frame(h=1:24); 
  ps <- predict(mynn,pred);
  pred$qty = ps[,1];
  pred$v = c(paste("pred",decayParam))
  rsd = sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty)
  rsds = paste("rsd=",rsd)
  print(rsds)  
  alldata <- rbind(data,pred)
  print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + 
          geom_line() + 
          geom_point()+theme_classic()+ggtitle(rsds));
  return(rsd)
}
print(runNN(0))    # with no decay
print(runNN(0.02)) # with decay

runNN(0)     # with no decay - tends to converge to the population mean
runNN(0.02)  # with decay - works better, but if you run this multiple times, 
             #  sometimes it converges badly.

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

while(runNN(0.02)>0.1){} #This works but it seems sloppy.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.


library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds)
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I've noticed that for sin() like data, I need to use decay which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

while(runNN(0.02)>0.1){} # This works but it seems sloppy.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN = function(decayParam) {  
  data = data.frame(h=1:24); 
  data$qty <- sin(data$h/48*2*pi)*1000
  data$v = c(paste("actual",decayParam))
  mynn <- nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) 
  pred = data.frame(h=1:24); 
  ps <- predict(mynn,pred);
  pred$qty = ps[,1];
  pred$v = c(paste("pred",decayParam))
  rsd = sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty)
  rsds = paste("rsd=",rsd)
  print(rsds)  
  alldata <- rbind(data,pred)
  print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + 
          geom_line() + 
          geom_point()+theme_classic()+ggtitle(rsds));
  return(rsd)
}
print(runNN(0))    # with no decay
print(runNN(0.02)) # with decay

runNN(0)     # with no decay - tends to converge to the population mean
runNN(0.02)  # with decay - works better, but if you run this multiple times, 
             #  sometimes it converges badly.
oops
Source Link
Chris
  • 1.3k
  • 10
  • 31

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

I attempted a while loop to run the nnet() function until the rmse happened to be low amount, but strangely the nnet didn't seem to generate different weights. Only when I ran the once again on the command-line did it do so. I suspect it is using the same random seed in the loop?

while(runNN(0.02)<0>0.1){} #When I try this#This works but it only runs onceseems sloppy.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds)
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I tried: while(runNN(0.02)<0.1){} But it only runs once.

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

I attempted a while loop to run the nnet() function until the rmse happened to be low amount, but strangely the nnet didn't seem to generate different weights. Only when I ran the once again on the command-line did it do so. I suspect it is using the same random seed in the loop?

while(runNN(0.02)<0.1){} #When I try this it only runs once.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds)
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I tried: while(runNN(0.02)<0.1){} But it only runs once.

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

while(runNN(0.02)>0.1){} #This works but it seems sloppy.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds)
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

oops added code snippet
Source Link
Chris
  • 1.3k
  • 10
  • 31

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

I attempted a while loop to run the nnet() function until the rmse happened to be low amount, but strangely the nnet didn't seem to generate different weights. Only when I ran the once again on the command-line did it do so. I suspect it is using the same random seed in the loop?

while(runNN(0.02)<0.1){} #When I try this it only runs once.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=paste("rsd=",sqrt(mean((data$$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsdrsds) 
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsdrsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I tried: while(runNN(0.02)<0.1){} But it only runs once.

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

I attempted a while loop to run the nnet() function until the rmse happened to be low amount, but strangely the nnet didn't seem to generate different weights. Only when I ran the once again on the command-line did it do so. I suspect it is using the same random seed in the loop?

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=paste("rsd=",sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty)) print(rsd) alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsd)); }
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I've noticed that for sin() like data, I need to use "decay" which is available in nnet to get the ANN to perform. Why would that be in theory? Also when I run runNN(0.02) over and over, sometimes the model performs beautifully (relative rmse of 0.04) and other times poorly (relative rmse of 0.42). How can one make the training of the nnet not so dependent on the random initialization of the weights?

I attempted a while loop to run the nnet() function until the rmse happened to be low amount, but strangely the nnet didn't seem to generate different weights. Only when I ran the once again on the command-line did it do so. I suspect it is using the same random seed in the loop?

while(runNN(0.02)<0.1){} #When I try this it only runs once.

Is there a way to set the training parameters better in order to always converge on the "best" result?

For the training data: Imagine a restaurant has the most customers at noon and the qty of the tips is highest at noon and we want to make a neural net predict tips gained in an hour.

library(quantmod)
library(nnet)
print("start")
runNN=function(decayParam) {
data=data.frame(h=1:24); data$qty<-sin(data$h/482pi)*1000 data$v=c(paste("actual",decayParam)) mynn<-nnet(qty~h,data,size=2,decay = decayParam,linout = TRUE,maxit=2000) pred=data.frame(h=1:24); ps<-predict(mynn,pred); pred$qty=ps[,1]; pred$v=c(paste("pred",decayParam)) rsd=sqrt(mean((data$qty-pred$qty)^2))/mean(data$qty) rsds=paste("rsd=",rsd) print(rsds) 
alldata <- rbind(data,pred) print(ggplot(data=alldata, aes(x=h, y=qty, group=v, color=v)) + geom_line() + geom_point()+theme_classic()+ggtitle(rsds)); return(rsd) } print(runNN(0)) #with no decay print(runNN(0.02)) #with decay
runNN(0) #with no decay - tends to converge to the population mean

runNN(0.02) #with decay - works better, but if you run this multiple times, sometimes it converges badly.

I tried: while(runNN(0.02)<0.1){} But it only runs once.

Source Link
Chris
  • 1.3k
  • 10
  • 31
Loading