【发布时间】:2019-05-07 12:15:35
【问题描述】:
在对optim() 的以下调用中,我希望对fn() 进行一次评估,对gr() 进行一次评估,因为maxit=1。但是,fn() 和 gr() 分别被评估 7 次。
optim(par=1000, fn=function(x) x^2, gr=function(x) 2*x,
method="L-BFGS-B", control=list(maxit=1))$counts
function gradient
7 7
这是为什么呢?这是一个错误吗?或者为什么optim() 一次迭代做 7 次评估?
更详细的输出:
optim(par=1000,
fn=function(x) { cat("f(", x, ")", sep="", fill=TRUE); x^2 },
gr=function(x) { cat("g(", x, ")", sep="", fill=TRUE); 2*x },
method="L-BFGS-B", control=list(maxit=1))$counts
f(1000)
g(1000)
f(999)
g(999)
f(995)
g(995)
f(979)
g(979)
f(915)
g(915)
f(659)
g(659)
f(1.136868e-13)
g(1.136868e-13)
function gradient
7 7
(使用 R 版本 3.5.0 测试。)
【问题讨论】:
-
可以在 R 邮件列表中找到类似的注释。没有回复。 r.789695.n4.nabble.com/…
-
用
method的其他值测试得到不同的计数。
标签: r optimization mathematical-optimization