R 中的 constrOptim - init val 不在可行域内部错误 [英] constrOptim in R - init val is not in the interior of the feasible region error
问题描述
我正在尝试使用 constrOptim
包.这是我的设置:
test_func <- function(x){返回((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")
它产生错误:
<块引用> constrOptim(rep(1/3, 3), f = test_func, grad = NULL, ui = rbind(diag(3), :初始值不在可行域内部
很容易检查我的初始值是否在可行域的内部(来自文档:ui %*% theta - ci >= 0
)constrOptim
ui %*% rep(1/3, 3) - ci
产生:
[,1][1,] 0.3333333[2,] 0.3333333[3,] 0.3333333[4,] 0.0000000[5,] 0.0000000
我错过了什么?
如果您在 Google 上搜索,您会在另一个问题的评论中从@HongOoi 获得答案,其中包含类似的错误消息.Hong Ooi 建议从 ci
参数中减去一个模糊值:
fuzz = - 1e-6constrOptim(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$值[1] 0.3333327$counts[1] 0$收敛[1] 0$消息空值$outer.iterations[1] 1$barrier.value[1] 0.000209865
我认为这可能是一个可能需要向 R-devel 邮件列表发送请求以改进文档的问题,尽管有争议的是,由于约束,您实际上并不处于可行范围的内部tes 不符合严格的不等式:
ui %*% rep(1/3,3) - ci >0[,1][1,] 真[2,] 真[3,] 真[4,] 假[5,] 错误
不等式满足了前三个约束条件,但边界上的后两个约束条件不满足.
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?
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.
这篇关于R 中的 constrOptim - init val 不在可行域内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!