conroylau / lpinfer

lpinfer: An R Package for Inference in Linear Programs
GNU General Public License v3.0
3 stars 5 forks source link

Simple chorussell example does not work #94

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago
library("lpinfer")
source("~/R/x86_64-pc-linux-gnu-library/3.6/lpinfer/example/dgp_mixedlogit.R")

dgp <- mixedlogit_dgp()
set.seed(1)
data <- mixedlogit_draw(dgp, n = 2000)

lpm <- lpmodel(A.obs = mixedlogit_Aobs(dgp),
               beta.obs = function(d) mixedlogit_betaobs(d, dgp),
               A.shp = rep(1, nrow(dgp$vdist)),
               beta.shp = 1,
               A.tgt = mixedlogit_Atgt_dfelast(dgp, w2eval = 1, eeval = -1))

chorussell(data = data, lpmodel = lpm, beta.tgt = .5)

produces

Error in lb.bs[[i]] : subscript out of bounds                                

This type of bug could be caught easily with a unit test!

conroylau commented 4 years ago

Done! I have fixed the part where none of the candidate bounds satisfy the constraints in the minimization problem when alpha = 0. Hence, the list of candidate bounds in the constraints are empty and resulted in the error. Since checking alpha = 0 is not useful and could be problematic, I have dropped that part from the bisection. This did not happen in the unit test with the sample data so I am sorry that it could not catch the error.

Thanks!