tlverse / sl3

💪 🤔 Modern Super Learning with Machine Learning Pipelines
https://tlverse.org/sl3/
GNU General Public License v3.0
99 stars 40 forks source link

Error: stack failed when calling `Lrnr_condensier` with message: Lrnr_condensier_equal.len_25_TRUE_NA_FALSE_NULL. #101

Closed wilsoncai1992 closed 6 years ago

wilsoncai1992 commented 6 years ago

When I try to call Lrnr_condensier and train function, SL3 gives the following error (reproduced on both mac and linux):

Error in private$.train(subsetted_task, trained_sublearners) :
  All learners in stack have failed
In addition: Warning messages:
1: In private$.train(subsetted_task, trained_sublearners) :
  the stack failed with message: Lrnr_condensier_equal.len_25_TRUE_NA_FALSE_NULL. It will be removed from
2: In private$.train(subsetted_task, trained_sublearners) :
  the stack failed with message: Lrnr_condensier_equal.mass_20_TRUE_NA_FALSE_NULL. It will be removed from
3: In private$.train(subsetted_task, trained_sublearners) :
  the stack failed with message: Lrnr_condensier_equal.len_35_TRUE_NA_FALSE_NULL. It will be removed from
Failed on Stack
Error in self$compute_step() :
  Error in private$.train(subsetted_task, trained_sublearners) :
  All learners in stack have failed

You can reproduce the error with the following code:

library("simcausal")
D <- DAG.empty()
D <-
  D + node("W1", distr = "rbern", prob = 0.5) +
  node("W2", distr = "rbern", prob = 0.3) +
  node("W3", distr = "rbern", prob = 0.3) +
  node("sA.mu", distr = "rconst", const = (0.98 * W1 + 0.58 * W2 + 0.33 * W3)) +
  node("sA", distr = "rnorm", mean = sA.mu, sd = 1)
D <- set.DAG(D, n.test = 10)
datO <- sim(D, n = 10000, rndseed = 12345)

library("condensier")
library("sl3")
# ================================================================================
task <- sl3_Task$new(datO, covariates=c("W1", "W2", "W3"),outcome="sA")

lrn <- Lrnr_condensier$new(task, nbins = 35, bin_method = "equal.len", pool = TRUE, bin_estimator =
                             Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))
lrn1 <- Lrnr_condensier$new(task, nbins = 25, bin_method = "equal.len", pool = TRUE,
                            bin_estimator = Lrnr_glm_fast$new(family = "binomial"))
lrn2 <- Lrnr_condensier$new(task, nbins = 20, bin_method = "equal.mass", pool = TRUE,
                            bin_estimator = Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))
lrn3 <- Lrnr_condensier$new(task, nbins = 35, bin_method = "equal.len", pool = TRUE,
                            bin_estimator = Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))

sl <- Lrnr_sl$new(learners = list(lrn1, lrn2, lrn3),
                  metalearner = Lrnr_solnp_density$new())
sl_fit <- sl$train(task)
wilsoncai1992 commented 6 years ago

@jeremyrcoyle any idea on this?

nhejazi commented 6 years ago

I encountered this problem just yesterday as well and considered opening an issue with the condensier package. It appears that the minimal reproducing example is from the condensier README so, perhaps, @osofr you could comment?

osofr commented 6 years ago

@nhejazi I would love to comment, but stuck on a weird sl3 bug #100 that doesn't allow me to test anything with sl3 on my system. This bug appears to be more sl3 related, since the minimal condensier-only examples are running just fine. I'll look into it once I have sl3 running again.

nhejazi commented 6 years ago

@osofr - thanks for offering to look into this when you can. Indeed, I can also confirm that the examples related only to condensier appear to run fine for me as well; it's only the examples related to combining sl3 and condensier that fail. That said, I also cannot reproduce #100 with a fully updated setup (R 3.4.3, etc.), which echoes the Travis and appveyor builds.

osofr commented 6 years ago

It appears that this wasn't even a bug after all. Just incorrect syntax for conditional density bin learners. Note that each learner in the above example is being provided task. This is wrong, the task is not part of the condensier learner arguments. The above provided task was being used for an integer valued argument, which caused a downstream error in condensier::fit_density. Unfortunately, no error message was returned from condensier::fit_density by sl$train, which made the debugging that much harder (I am looking at you @jeremyrcoyle 😉). The correct code example is provided below and will soon be replaced in condensier example page.

options(sl3.verbose = FALSE)
library("condensier")
library("sl3")

library("simcausal")
D <- DAG.empty()
D <-
  D + node("W1", distr = "rbern", prob = 0.5) +
  node("W2", distr = "rbern", prob = 0.3) +
  node("W3", distr = "rbern", prob = 0.3) +
  node("sA.mu", distr = "rconst", const = (0.98 * W1 + 0.58 * W2 + 0.33 * W3)) +
  node("sA", distr = "rnorm", mean = sA.mu, sd = 1)
D <- set.DAG(D, n.test = 10)
datO <- sim(D, n = 10000, rndseed = 12345)

# ================================================================================
task <- sl3_Task$new(datO, covariates=c("W1", "W2", "W3"),outcome="sA")

lrn1 <- Lrnr_condensier$new(nbins = 35, bin_method = "equal.len", pool = TRUE, bin_estimator =
                             Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))
lrn2 <- Lrnr_condensier$new(nbins = 25, bin_method = "equal.len", pool = TRUE,
                            bin_estimator = Lrnr_glm_fast$new(family = binomial()))
lrn3 <- Lrnr_condensier$new(nbins = 20, bin_method = "equal.mass", pool = TRUE,
                            bin_estimator = Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))
lrn4 <- Lrnr_condensier$new(nbins = 35, bin_method = "equal.len", pool = TRUE,
                            bin_estimator = Lrnr_xgboost$new(nrounds = 50, objective = "reg:logistic"))

sl <- Lrnr_sl$new(learners = list(lrn1, lrn2, lrn3, lrn4), metalearner = Lrnr_solnp_density$new())
sl_fit <- sl$train(task)
osofr commented 6 years ago

@wilsoncai1992, please see the updated examples (along with proper Rmd file containing the examples) in https://github.com/osofr/condensier/pull/13

wilsoncai1992 commented 6 years ago

Thank you @osofr for looking into this! I can confirm that the new code will work.