R神经网络未在时间序列的stepmax内收敛 [英] R neuralnet does not converge within stepmax for time series

查看:1499
本文介绍了R神经网络未在时间序列的stepmax内收敛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用neuralnet包编写一个神经网络,用于预测R中时间序列x + sin(x^2)中的元素.假设有4个元素的窗口,并且最后一个是必须预测的窗口,这就是生成训练数据的方式:

I'm writing a neural network for prediction of elements in a time series x + sin(x^2) in R, using the neuralnet package. This is how training data is being generated, assuming a window of 4 elements, and that the last one is the one that has to be predicted:

nntr0 <- ((1:25) + sin((1:25)^2))
nntr1 <- ((2:26) + sin((2:26)^2))
nntr2 <- ((3:27) + sin((3:27)^2))
nntr3 <- ((4:28) + sin((4:28)^2))
nntr4 <- ((5:29) + sin((5:29)^2))

然后,将它们转换为data.frame:

Then, I turn these into a data.frame:

nntr <- data.frame(nntr0, nntr1, nntr2, nntr3, nntr4)

然后,我继续训练NN:

Then, I proceed to train the NN:

net.sinp <- neuralnet(nntr4 ~ nntr0 + nntr1 + nntr2 + nntr3, data=nntr, hidden=10, threshold=0.04, act.fct="tanh", linear.output=TRUE, stepmax=100000)

过一会儿,给我消息

Warning message:
algorithm did not converge in 1 of 1 repetition(s) within the stepmax 
Call: neuralnet(formula = nntr4 ~ nntr0 + nntr1 + nntr2 + nntr3, data = nntr,     hidden = 10, threshold = 0.04, stepmax = 100000, act.fct = "tanh", linear.output = TRUE)

有人可以帮助我弄清楚为什么它没有收敛吗?非常感谢

Can anyone help me figure out why it is not converging? Many thanks

推荐答案

使用tanh作为激活函数(有界), 要在信号中再现线性趋势非常困难.

With tanh as an activation function (it is bounded), it is very difficult to reproduce the linear trend in your signal.

您可以改用线性激活函数, 或尝试使信号下降趋势.

You can use linear activation functions instead, or try to detrend the signal.

# Data
dx <- 1
n <- 25
x <- seq(0,by=dx,length=n+4)
y <- x + sin(x^2)
y0 <- y[1:n]
y1 <- y[1 + 1:n]
y2 <- y[2 + 1:n]
y3 <- y[3 + 1:n]
y4 <- y[4 + 1:n]
d <- data.frame(y0, y1, y2, y3, y4)
library(neuralnet)

# Linear activation functions
r <- neuralnet(y4 ~ y0 + y1 + y2 + y3, data=d, hidden=10)
plot(y4, compute(r, d[,-5])$net.result)

# No trend
d2 <- data.frame(
  y0 = y0 - x[1:n], 
  y1 = y1 - x[1 + 1:n], 
  y2 = y2 - x[2 + 1:n], 
  y3 = y3 - x[3 + 1:n], 
  y4 = y4 - x[4 + 1:n]
)
r <- neuralnet(y4 ~ y0 + y1 + y2 + y3, data=d2, hidden=10, act.fct="tanh" )
plot(d2$y4, compute(r, d2[,-5])$net.result)

这篇关于R神经网络未在时间序列的stepmax内收敛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆