2

I am trying to understand why do I get warning messages while trying to solve this using solnp? Following is the message I get -

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

Following is the code

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)
Amir
  • 10,600
  • 9
  • 48
  • 75

1 Answers1

1

This code amounts to asking: how can I maximize sum(x^2), while keeping the coefficients of x between 0 and 1, and keeping sum(x) equal to 1?

The library tries to solve this using the Hessian of the target function, i.e. the matrix of partial derivatives of sum(x^2) with respect to any pair of coefficients of x. That Hessian would ordinarily be 2 times the identity matrix, which is invertible.

However, something about the constraints throws this off. You can avoid the error by changing the 0's in the initial condition theta to 0.01's.

Matt F.
  • 145
  • 7