对于时间序列,R神经网络在最大步长内不收敛

对于时间序列,R神经网络在最大步长内不收敛,r,neural-network,time-series,convergence,R,Neural Network,Time Series,Convergence,我正在用neuralnet软件包编写一个神经网络,用于预测R中时间序列x+sinx^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)

我正在用neuralnet软件包编写一个神经网络,用于预测R中时间序列x+sinx^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))
有谁能帮我弄清楚为什么它不汇合?非常感谢

以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)
以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)
警告信息: 算法在步长内1次重复中1次未收敛MaxMeans您的算法在收敛之前已达到有限的步长。如果您键入?neuralnet,并查看其中所述stepmax的定义

神经网络训练的最大步长。达到这个最大值会导致神经网络的训练过程停止

对于您的问题,我建议您将stepmax值增加到1e7,然后看看会发生什么

代码将是

net.sinp警告消息: 算法在步长内1次重复中1次未收敛MaxMeans您的算法在收敛之前已达到有限的步长。如果您键入?neuralnet,并查看其中所述stepmax的定义

神经网络训练的最大步长。达到这个最大值会导致神经网络的训练过程停止

对于您的问题,我建议您将stepmax值增加到1e7,然后看看会发生什么

代码将是

net.sinp
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)
# 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)