Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

optimization - constrOptim in R - init val is not in the interior of the feasible region error

I am trying to use constrOptim package. Here is my set up:

test_func <- function(x){
  return((x%*%x)[1,1])
}
constrOptim(rep(1/3,3), f=test_func,grad = NULL,
            ui = rbind(diag(3),rep(1, 3), rep(-1,3)),
            ci = c(rep(0,3),1,-1), method = "Nelder-Mead")

it generates error:

   Error in constrOptim(rep(1/3, 3), f = test_func, grad = NULL, ui = rbind(diag(3),  : 
      initial value is not in the interior of the feasible region

it is easy to check that my initial value is in the interior of the feasible region (which is from docs: ui %*% theta - ci >= 0) constrOptim

ui %*% rep(1/3, 3) - ci

produces:

          [,1]
[1,] 0.3333333
[2,] 0.3333333
[3,] 0.3333333
[4,] 0.0000000
[5,] 0.0000000

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you search Google you get an answer from @HongOoi in the comments of another question with a similar error message. Hong Ooi suggested subtracting a fuzz value from the ci argument:

  fuzz = - 1e-6


 constrOptim(rep(1/3,3), f=test_func,grad = NULL,
             ui = rbind(diag(3),rep(1, 3), rep(-1,3)),
             ci = c(rep(0,3),1,-1)- 1e-6, method = "Nelder-Mead")
#---------------------
$par
[1] 0.3333317 0.3333327 0.3333346

$value
[1] 0.3333327

$counts
[1] 0

$convergence
[1] 0

$message
NULL

$outer.iterations
[1] 1

$barrier.value
[1] 0.000209865

I think this is probably an issue that might warrant sending a request to the R-devel mailing list for documentation improvement, although arguable you are not actually in the interior of the feasible range since the constraint tes fails a strict inequality:

 ui %*% rep(1/3,3) - ci > 0
      [,1]
[1,]  TRUE
[2,]  TRUE
[3,]  TRUE
[4,] FALSE
[5,] FALSE

Your first three constraints were satisfied by the inequality but not the last two which were on the boundary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...