jkcshea / ivmte

An R package for implementing the method in Mogstad, Santos, and Torgovitsky (2018, Econometrica).
GNU General Public License v3.0
18 stars 2 forks source link

Compare lpsolveAPI with some quadratic programming solvers #163

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago

Completely didn't think of this at the time we were considering whether to change the outdated lpsolve to something else or keep it in. But quadratic solvers are also going to nest linear programs as a special case. And there are many open-source quadratic solvers in R. For example quadprog and osqp The latter in particular looks promising and easy to use: https://rwalk.xyz/sparse-quadratic-programming-with-osqp/

It might be worth checking whether one of these is a more reliable open alternative.

jkcshea commented 4 years ago

This turned out to be quite disappointing... Neither package seems to allow for simple LP problems. Here is an example:

## Example taken from:
## https://www.gurobi.com/documentation/6.5/refman/solving_models_with_the_gu.html
model <- list()
model$A          <- matrix(c(1, 1, 0,
                             0, 1, 1),
                           nrow = 2, byrow = T)
model$obj        <- c(1,1,2)
model$modelsense <- "max"
model$rhs        <- c(1,1)
model$sense      <- c('<=', '<=')

The solution is simply c(1, 0, 1), and the objective value is 3.

quantprog explicitly complains that a matrix of 0s defining the quadratic terms is not acceptable/positive definite. This was expected after reading some of the manual.

But unlike quantprog, osqp says it can handle positive semidefinite matrices when defining the quadratic component, so I would think a matrix of 0s defining the quadratic terms is okay. However, when trying to solve the LP problem, osqp states that the problem is dual infeasible, and provides a certificate for this. I don't know much about quadratic programming, but does it make sense for a LP problem to be dual-infeasible in a QP setup?

(both packages work if I declare an arbitrary PD matrix to define the quadratic components of the objective)

a-torgovitsky commented 4 years ago

Strange! No it doesn't make sense to me...but I haven't read the methodology behind either paper. Maybe they are doing something fancy. Anyway, it was worth a shot. Thanks for looking into it.