R神经网络在时间序列中无法在stepmax内收敛

3

我正在使用R语言中的neuralnet包编写神经网络,用于预测时间序列x + sin(x^2)中的元素。以下是生成训练数据的方式,假设窗口大小为4个元素,最后一个元素是需要被预测的:

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))

然后,我将它们转化为数据框:

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

接着,我开始训练神经网络:

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)

有谁能帮我弄清楚为什么它无法收敛?非常感谢。
2个回答

4
警告信息:算法在1次重复中没有收敛,达到了stepmax。这意味着你的算法在达到有限步数之前就停止了。如果你输入“?neuralnet”并查看stepmax的定义,它说:
神经网络训练的最大步骤。达到这个最大步骤会导致神经网络的训练过程停止。
针对您的问题,我建议您将stepmax值增加到1e7,看看会发生什么。
代码如下: net.sinp <- neuralnet(nntr4 ~ nntr0 + nntr1 + nntr2 + nntr3, data=nntr, hidden=10, threshold=0.04, act.fct="tanh", linear.output=TRUE, stepmax=1e7)

3

使用双曲正切函数tanh作为激活函数(因为它是有界的),很难再现信号中的线性趋势。

你可以使用线性激活函数,或者尝试将信号去趋势。

# 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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接