From 88f68756ecc8cfec11583075b7b01069919b4411 Mon Sep 17 00:00:00 2001 From: Jakob Richter Date: Fri, 13 Nov 2020 13:49:49 +0100 Subject: [PATCH 1/2] notes on tune tokens --- R/ObjectiveTuning.R | 1 + R/TuningInstanceSingleCrit.R | 16 +++++++++++++++- attic/test_tune_token.R | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 attic/test_tune_token.R diff --git a/R/ObjectiveTuning.R b/R/ObjectiveTuning.R index ccc47aca5..6d8a9b55d 100644 --- a/R/ObjectiveTuning.R +++ b/R/ObjectiveTuning.R @@ -76,6 +76,7 @@ ObjectiveTuning = R6Class("ObjectiveTuning", private = list( .eval_many = function(xss) { + browser() learners = map(xss, function(x) { learner = self$learner$clone(deep = TRUE) learner$param_set$values = insert_named(learner$param_set$values, x) diff --git a/R/TuningInstanceSingleCrit.R b/R/TuningInstanceSingleCrit.R index eef40aeab..ad9579ee5 100644 --- a/R/TuningInstanceSingleCrit.R +++ b/R/TuningInstanceSingleCrit.R @@ -115,10 +115,24 @@ TuningInstanceSingleCrit = R6Class("TuningInstanceSingleCrit", #' This defines the resampled performance of a learner on a task, a #' feasibility region for the parameters the tuner is supposed to optimize, #' and a termination criterion. - initialize = function(task, learner, resampling, measure, search_space, + initialize = function(task, learner, resampling, measure, search_space = NULL, terminator, store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE) { measure = as_measure(measure) + # We might want to have the following in a function bc its used in MultiCrit as well + if (is.null(search_space)) { + # TODO: check if we can construct search space from learner$param_set using tune_tokens + tmp = learner$param_set$get_tune_pair() # return fixed_values (all but tune tokens) and search_space (from tune tokens), + # Question: If we have tune tokens in the learner$param_set the learner is practically "broken". So we have to clean it up in order to use it. Why not + # a) Don't use tune tokens at all (we can pass the info in get_tune_pair(tune_tokens = xxx)) + # b) Use a second slot next to $param_vals, eg. $param_vals_to_tune. (++) + # c) Only use param_set$get_values() which can filter out TuneTokens, maybe param_set$values discards TuneTokens, on the other hand if I put a lot of effort here to always treat TuneTokens and real values I could jut go with solution b) + learner$param_set$values = tmp$fixed_values #ohne tune token / das könnte inplace passieren + search_space = tmp$search_space + # we dont allow a mix of search_space and tune tokens + } else { + # TODO: check that no tune tokens exist in learner$param_set$values + } obj = ObjectiveTuning$new(task = task, learner = learner, resampling = resampling, measures = list(measure), store_benchmark_result = store_benchmark_result, diff --git a/attic/test_tune_token.R b/attic/test_tune_token.R new file mode 100644 index 000000000..2c6234fd6 --- /dev/null +++ b/attic/test_tune_token.R @@ -0,0 +1,32 @@ +library(mlr3learners) + +task = tsk("iris") +learner = lrn("classif.svm", type = "C-classification") +resampling = rsmp("holdout") +measure = msr("classif.ce") +terminator = trm("none") + +learner$param_set$values$kernel = to_tune(c("polynomial", "radial")) +learner$param_set$values$degree = to_tune(1, 3) + +#solution 1 +foo = learner$param_set$get_tune_pair() +learner$param_set = foo$param_set #ohne tune token / das könnte inplace passieren +search_space = foo$search_space #das was mir param_set$tune_ps() geben würde + +#solutin 2 +learner$convert_for_tuning() # param_vals tune tokens löschen und in param_set umwandeln +search_space = learner$param_set$ +# geht das hier schlecht, wenn ich param$vals + +instance = TuningInstanceSingleCrit$new( + task = task, + learner = learner, + resampling = resampling, + measure = measure, + search_space = search_space, + terminator = terminator +) + +tuner = tnr("grid_search", resolution = 1) +tuner$optimize(instance) From 4dceb57fbccd7cf84b1ee066f4ed541dba2c399a Mon Sep 17 00:00:00 2001 From: Jakob Richter Date: Fri, 13 Nov 2020 15:34:51 +0100 Subject: [PATCH 2/2] no browsing here --- R/ObjectiveTuning.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/ObjectiveTuning.R b/R/ObjectiveTuning.R index 6d8a9b55d..ccc47aca5 100644 --- a/R/ObjectiveTuning.R +++ b/R/ObjectiveTuning.R @@ -76,7 +76,6 @@ ObjectiveTuning = R6Class("ObjectiveTuning", private = list( .eval_many = function(xss) { - browser() learners = map(xss, function(x) { learner = self$learner$clone(deep = TRUE) learner$param_set$values = insert_named(learner$param_set$values, x)