Rsolnp: In cbind (temp, funv): the number of lines of the result is not a multiple of the length of the vector (arg 1)

I am new to stackoverflow and searched a lot, but could not find the answer to my question. I am trying to minimize the problem with the rsolnp optimization package. Although the solver gives me a solution, every time I run the code, the following warning message appears:

Warning messages: 1: In cbind (temp, funv): the number of lines of the result is not a multiple of the vector length (arg 1)

In addition, the solution is completely different from the solutions that I get with ipop and solve. QP. Their solutions are almost the same (0.2480, 0.0000, 0.0121, 0.7400). I tried many different formulations of the problem, but could not understand what I did wrong. I am grateful for all the help and information!

library(Rsolnp)
# Starting Values
x0 <- c(0.25,0,0.01,0.75)


fn <- function(x){
  d <- c(0.0308, 0.0269, 0.0145, 0.0130)
  d <- -d
  D <- cbind(c(0.1486, 0.0778, -0.0240, -0.0154), 
         c(0.0778, 0.1170, 0.0066, 0.0029), 
         c(-0.0240, 0.0066, 0.0444, 0.0193), 
         c(-0.0154, 0.0029, 0.0193, 0.0148))
 out <- t(d) %*% x + 0.5 * (t(x) %*% D %*% x)
 out
}


# Inequality Constraint: 0 =< x 0 =< 1
lx <- rep(0,4)
ux <- rep(1,4)



sol <- solnp(pars = x0, 
         fun = fn, 
         eqfun = sum, 
         eqB = 1, 
         ineqLB = lx, 
         ineqUB = ux)
sol$pars
+4
2

SO.

: a) w.r.t b) , .

ad a) , LaGrange . . d -d ( ) , , .

ad b) . , cbind . R, , , . , , R , , .

, , .

options(warn = 2) # turns warnings to errors and breaks code
debug(solnp)
sol <- solnp(pars = x0, 
     fun = fn, 
     eqfun = sum, 
     eqB = 1, 
     ineqLB = lx, 
     ineqUB = ux)

, tempdf, . solnp. , , , .

+2

, fn, :

fn <- function(x){
  d <- c(0.0308, 0.0269, 0.0145, 0.0130)
  d <- -d
  D <- cbind(c(0.1486, 0.0778, -0.0240, -0.0154), 
             c(0.0778, 0.1170, 0.0066, 0.0029), 
             c(-0.0240, 0.0066, 0.0444, 0.0193), 
             c(-0.0154, 0.0029, 0.0193, 0.0148))
  out <- t(d) %*% x + 0.5 * (t(x) %*% D %*% x)
  as.numeric(out)
}

Iter: 1 fn: -0,01153 : 0,244798607502 0,00000002295 0,01205720515 0.73995669928 : 2 fn: -0.01153 : 0.247984418270 0,000000003318 0,012080555874 0,739935021900 solnp → 2

$ [1] 2.479844e-01 3.317577e-09 1.208056e-02 7.399350e-01

+1

Source: https://habr.com/ru/post/1662608/


All Articles