在 R 的 RSNNS 包中获取迭代次数直到收敛
Get number of iterations until convergence in R's RSNNS package
我想通过使用 RSNNS
包在 R
中拟合循环神经网络。该包提供了设置最大迭代次数的选项,如 maxit = 1000
在下面的示例代码中所做的那样。是否可以看到算法使用了多少次迭代直到收敛?
library(RSNNS)
library(xts)
#Load Lynx data
data(lynx)
#Scale data and convert to xts
data <- as.xts((lynx - min(lynx)) / (max(lynx) - min(lynx)))
#Build xts object with 5 lags to analyze
lags <- 5
for(i in 1:lags){
feat <- lag(lynx, i)
data <- merge(data, feat, all = FALSE)
}
#Get features and target
features <- data[,-1]
target <- data[,1]
#Fit network
rnn <- elman(features, target, maxit = 1000)
我认为它 运行 是默认的最大迭代次数。当您 运行 下面的内容时,即使在图表中达到稳定后迭代仍在继续。
rnn <- elman(features, target, maxit = 1000)
plotIterativeError(rnn)
#then run this
rnn <- elman(features, target, maxit = 10000)
plotIterativeError(rnn)
您可能可以使用 head(which(abs(diff(rnn$IterativeFitError)) < 1e-20), 1)
找到收敛时的迭代步骤。
我想通过使用 RSNNS
包在 R
中拟合循环神经网络。该包提供了设置最大迭代次数的选项,如 maxit = 1000
在下面的示例代码中所做的那样。是否可以看到算法使用了多少次迭代直到收敛?
library(RSNNS)
library(xts)
#Load Lynx data
data(lynx)
#Scale data and convert to xts
data <- as.xts((lynx - min(lynx)) / (max(lynx) - min(lynx)))
#Build xts object with 5 lags to analyze
lags <- 5
for(i in 1:lags){
feat <- lag(lynx, i)
data <- merge(data, feat, all = FALSE)
}
#Get features and target
features <- data[,-1]
target <- data[,1]
#Fit network
rnn <- elman(features, target, maxit = 1000)
我认为它 运行 是默认的最大迭代次数。当您 运行 下面的内容时,即使在图表中达到稳定后迭代仍在继续。
rnn <- elman(features, target, maxit = 1000)
plotIterativeError(rnn)
#then run this
rnn <- elman(features, target, maxit = 10000)
plotIterativeError(rnn)
您可能可以使用 head(which(abs(diff(rnn$IterativeFitError)) < 1e-20), 1)
找到收敛时的迭代步骤。