nlminb严格或包含的界限

时间:2017-10-31 14:54:07

标签: r optimization

对于stats::nlminb()lowerupper界限是否包含在内?我阅读了帮助页面和示例以及我发现的所有内容

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)范围内。

1 个答案:

答案 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)"