我最初的问题可以在这里找到:任意约束的 R 优化
它导致了另一个问题,如何将参数传递到nloptr
.
我需要最小化一个函数F(x,y,A)
,其中x
和 y 是向量并且A
是矩阵,同时约束sum(x * y) >= sum(y/3)
和sum(x)=1
。我试过使用nloptr
:
F <- function(x,y,A){
...
}
Gc <- function(x,y){
return(sum(y/3) - sum(x*y))
}
Hc <- function(x){
retunr(1-sum(x))
}
nloptr(x0=rep(1/3,3), eval_f=F, lb = 0.05, ub = 1, eval_g_ineq = Gc, eval_g_eq = Hc, opts = list(), y=y, A=A)
我收到一个错误:
'A' passed to (...) in 'nloptr' but this is not required in the eval_g_ineq function.
如果我说nloptr( ... , y, A)
我得到:eval_f requires argument 'cov.mat' but this has not been passed to the 'nloptr' function.
任何建议都会很棒。谢谢