R:如何将Neuronet进度输出定向到特定文件?

时间:2018-12-07 10:26:20

标签: r neural-network artificial-intelligence

neuralnet R 中进行时,它会在控制台中生成steps/ min thresh,如下所示

hidden: 1    thresh: 1    rep: 1/1    steps:     1000   min thresh: 5506.086127
                                                 2000   min thresh: 131.2950623
                                                 2831   error: 1595263.315  time: 3.11 secs

我的问题……是如何将此类输出定向到特定文件?

1 个答案:

答案 0 :(得分:0)

我想出了一个转机...可能有效...!

使用 sink 命令围绕 neuralnet 块……如下所示。

fileName <- file(paste0('neuralnet.log'), "w")

  a <- seq(1:1000)
  b <- a*2
  tds <- cbind(a, b)
  colnames(tds) <- c('a', 'b')

  sink(summary(fileName)$description, append = TRUE) # Direct all output to file
  net.sqrt <- neuralnet(b ~ a, tds, hidden=1, threshold=1, stepmax=1e5, rep = 3, startweights = NULL,
                        learningrate.limit = NULL,
                        learningrate.factor = list(minus = 0.5, plus = 1.2),
                        learningrate=NULL, lifesign = "full",
                        lifesign.step = 1000, 
                        algorithm = c("rprop+"),
                        err.fct = "sse", act.fct = "logistic",
                        linear.output = TRUE, exclude = NULL,
                        constant.weights = NULL, likelihood = FALSE)
  sink() # Turn off buffing to file
  close(fileName)

如果您有更好的解决方案...感谢您的反馈...