我试图了解为什么在尝试使用 solnp 解决此问题时会收到警告消息?以下是我收到的消息 -
solnp--> Solution not reliable....Problem Inverting Hessian.
Warning message:
In p0 * vscale[(neq + 2):(nc + np + 1)] :
longer object length is not a multiple of shorter object length
以下是代码
countw <- 100
Dmat = diag(1, 100, 100)
# Equality constraints
eq_A <- rep(1, countw)
eq_b <- 1
# Constraint wts greater than zero
ineq_A <- diag(x = 1, nrow = countw, ncol = countw)
ineq_b <- rep(0, countw)
# Combine constraints
heq <- eq_A
hin <- ineq_A
theta <- c(0.51, 0.49, rep(0, countw-2))
krdsolnp <- solnp(par = theta,
fun = function(x) -c(t(x) %*% Dmat %*% x),
ineqfun = function(x) c(hin %*% x),
ineqLB = rep(0, countw),
ineqUB = rep(1, countw),
eqfun = function(x) c(heq %*% x),
eqB = eq_b)