对于stats::nlminb()
,lower
和upper
界限是否包含在内?我阅读了帮助页面和示例以及我发现的所有内容
lower, upper: vectors of lower and upper bounds, replicated to be as long as start.
If unspecified, all parameters are assumed to be unconstrained.
和示例:
## 25-dimensional box constrained
## par[24] is *not* at boundary
nlminb(rep(3, 25), flb, lower = rep(2, 25), upper = rep(4, 25))
## trying to use a too small tolerance:
r <- nlminb(rep(3, 25), flb, control = list(rel.tol = 1e-16))
stopifnot(grepl("rel.tol", r$message))
我需要知道,因为我的参数不能为0 - 也就是说它可以在(0, Inf)
NOT [0, Inf)
范围内。
答案 0 :(得分:0)
我相信它们是,看看这个示例,我们将下限lower
设置为-1,这是返回的值$par
。
> nlminb(start=-0.5,objective=dnorm, lower=-1, upper=0)
$par
[1] -1
$objective
[1] 0.2419707
$convergence
[1] 0
$iterations
[1] 3
$evaluations
function gradient
3 3
$message
[1] "X-convergence (3)"
类似地,上限upper
设置为1,并且返回的值为$par
。
> nlminb(start=0.5,objective=dnorm, lower=0, upper=1)
$par
[1] 1
$objective
[1] 0.2419707
$convergence
[1] 0
$iterations
[1] 3
$evaluations
function gradient
3 3
$message
[1] "X-convergence (3)"
更多说明可能会关注log()
> nlminb(start=0.5,objective=log, lower=0, upper=1)
$par
[1] 0
$objective
[1] -Inf
$convergence
[1] 0
$iterations
[1] 2
$evaluations
function gradient
2 3
$message
[1] "both X-convergence and relative convergence (5)"
如果您需要$objective
有限,可能需要手动为lower
添加一个软糖因素:
> nlminb(start=0.5,objective=log, lower=0+1e-50, upper=1)
$par
[1] 1e-50
$objective
[1] -115.1293
$convergence
[1] 0
$iterations
[1] 2
$evaluations
function gradient
2 2
$message
[1] "both X-convergence and relative convergence (5)"