mb706 / autoxgboost3

autoxgboost emulation for mlr3
Other
4 stars 0 forks source link

using trafo forces breaking asserts #4

Closed SebGGruber closed 4 years ago

SebGGruber commented 4 years ago

When adding a trafo to the parameter set, somehow undesired asserts make unnecessary checks which lead to an assert error. This makes log sampling currently not possible for random search. Steps to reproduce:

While removing the trafo gives us no assert error:

library(autoxgboost)
library(mlr3tuning)
library(checkmate)
data="data/gisette"
task = readRDS(file.path(data, "task.rds"))
axgb_settings = autoxgboost_space(task, tune.threshold = FALSE)
rsmp_inner = axgb_settings$resampling
learner = axgb_settings$learner
ps = axgb_settings$searchspace
ps$add(
  ParamInt$new(
    id = "xgboost.nrounds",
    lower = as.integer(log(10, 3)),
    upper = as.integer(log(2430, 3)),
    tags = "budget"
  )
)
ti = TuningInstance$new(task = task, learner = learner, resampling = rsmp_inner, param_set = ps, measures = msr("classif.ce"), terminator = term("evals", n_evals = 1))
tuner = tnr("random_search")
tuner$tune(ti)
mb706 commented 4 years ago

The problem here is that ps already contains a $trafo that exp-transforms a few of the other parameters. Replacing this $trafo with a new function suddenly does not exp-transform these other parameters any more and they are sampled on the wrong scale (giving negative values to parameters that should be positive).

(This is an unfortunate design decision of the $trafo in paradox that I'm not entirely happy with myself, but we are stuck with that for now. I already complained about this here: https://github.com/mlr-org/paradox/issues/248)

The best solution I can see here is to "append" the new trafo somehow:

 # need to save ps$trafo in an extra variable
old_trafo = ps$trafo
ps$trafo = function(x, param_set) {
  x$xgboost.nrounds = 3^x$xgboost.nrounds
  old_trafo(x, param_set)
}

Check ti$archive(unnest = "params") to see that the parameter values as seen by the Learner are what is desired.

Note the xgboost learner has xgboost.early_stopping_rounds set to 10; you probably want to unset this if you don't want xgboost to stop early and instead influence the number of nrounds directly:

learner$param_set$values$xgboost.early_stopping_rounds = NULL