diff --git a/NAMESPACE b/NAMESPACE index d3a619368..37876d740 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,7 +11,7 @@ S3method(as_pipeop,Filter) S3method(as_pipeop,Learner) S3method(as_pipeop,PipeOp) S3method(as_pipeop,default) -S3method(disable_inner_tuning,GraphLearner) +S3method(disable_internal_tuning,GraphLearner) S3method(po,"NULL") S3method(po,Filter) S3method(po,Learner) diff --git a/R/GraphLearner.R b/R/GraphLearner.R index ca4b01022..f0c092628 100644 --- a/R/GraphLearner.R +++ b/R/GraphLearner.R @@ -47,13 +47,13 @@ #' contain the model. Use `graph_model` to access the trained [`Graph`] after `$train()`. Read-only. #' * `graph_model` :: [`Learner`][mlr3::Learner]\cr #' [`Graph`] that is being wrapped. This [`Graph`] contains a trained state after `$train()`. Read-only. -#' * `inner_tuned_values` :: named `list()` or `NULL`\cr -#' The inner tuned parameter values. -#' `NULL` is returned if the learner is not trained or none of the wrapped learners supports inner tuning. -#' * `inner_valid_scores` :: named `list()` or `NULL`\cr -#' The inner tuned parameter values. +#' * `internal_tuned_values` :: named `list()` or `NULL`\cr +#' The internal tuned parameter values. +#' `NULL` is returned if the learner is not trained or none of the wrapped learners supports internal tuning. +#' * `internal_valid_scores` :: named `list()` or `NULL`\cr +#' The internal tuned parameter values. #' `NULL` is returned if the learner is not trained or none of the wrapped learners supports internal validation. -#' * `validate` :: `numeric(1)`, `"inner_valid"`, `"test"` or `NULL`\cr +#' * `validate` :: `numeric(1)`, `"predefined"`, `"test"` or `NULL`\cr #' How to construct the validation data. This also has to be configured in the individual learners wrapped by #' `PipeOpLearner`, see [`set_validate.GraphLearner`] on how to configure this. #' @@ -111,10 +111,10 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner, assert_subset(task_type, mlr_reflections$task_types$type) private$.can_validate = some(learner_wrapping_pipeops(graph), function(po) "validation" %in% po$learner$properties) - private$.can_inner_tuning = some(learner_wrapping_pipeops(graph), function(po) "inner_tuning" %in% po$learner$properties) + private$.can_internal_tuning = some(learner_wrapping_pipeops(graph), function(po) "internal_tuning" %in% po$learner$properties) properties = setdiff(mlr_reflections$learner_properties[[task_type]], - c("validation", "inner_tuning")[!c(private$.can_validate, private$.can_inner_tuning)]) + c("validation", "internal_tuning")[!c(private$.can_validate, private$.can_internal_tuning)]) super$initialize(id = id, task_type = task_type, feature_types = mlr_reflections$task_feature_types, @@ -153,13 +153,13 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner, } ), active = list( - inner_valid_scores = function(rhs) { + internal_valid_scores = function(rhs) { assert_ro_binding(rhs) - self$state$inner_valid_scores + self$state$internal_valid_scores }, - inner_tuned_values = function(rhs) { + internal_tuned_values = function(rhs) { assert_ro_binding(rhs) - self$state$inner_tuned_values + self$state$internal_tuned_values }, validate = function(rhs) { if (!missing(rhs)) { @@ -212,25 +212,25 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner, .graph = NULL, .validate = NULL, .can_validate = NULL, - .can_inner_tuning = NULL, - .extract_inner_tuned_values = function() { + .can_internal_tuning = NULL, + .extract_internal_tuned_values = function() { if (!private$.can_validate) return(NULL) itvs = unlist(map( learner_wrapping_pipeops(self$graph_model), function(po) { - if (exists("inner_tuned_values", po$learner)) { - po$learner_model$inner_tuned_values + if (exists("internal_tuned_values", po$learner)) { + po$learner_model$internal_tuned_values } } ), recursive = FALSE) if (is.null(itvs) || !length(itvs)) return(named_list()) itvs }, - .extract_inner_valid_scores = function() { - if (!private$.can_inner_tuning) return(NULL) + .extract_internal_valid_scores = function() { + if (!private$.can_internal_tuning) return(NULL) ivs = unlist(map( learner_wrapping_pipeops(self$graph_model), function(po) { - if (exists("inner_valid_scores", po$learner)) { - po$learner_model$inner_valid_scores + if (exists("internal_valid_scores", po$learner)) { + po$learner_model$internal_valid_scores } } ), recursive = FALSE) @@ -314,11 +314,11 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner, #' 2. On the level of the [`Learner`]s that are wrapped by [`PipeOpLearner`] and [`PipeOpLearnerCV`], which specifies #' which pipeops actually make use of the validation data. #' All learners wrapped by [`PipeOpLearner`] and [`PipeOpLearnerCV`] should in almost all cases either set it -#' to `NULL` (disable) or `"inner_valid"` (enable). +#' to `NULL` (disable) or `"predefined"` (enable). #' #' @param learner ([`GraphLearner`])\cr #' The graph learner to configure. -#' @param validate (`numeric(1)`, `"inner_valid"`, `"test"`, or `NULL`)\cr +#' @param validate (`numeric(1)`, `"predefined"`, `"test"`, or `NULL`)\cr #' How to set the `$validate` field of the learner. #' If set to `NULL` all validation is disabled, both on the graph learner level, but also for all pipeops. #' @param ids (`NULL` or `character()`)\cr @@ -384,7 +384,7 @@ set_validate.GraphLearner = function(learner, validate, ids = NULL, args = list( walk(ids, function(poid) { # learner might be another GraphLearner / AutoTuner so we call into set_validate() again withCallingHandlers({ - invoke(set_validate, learner = learner$graph$pipeops[[poid]]$learner, .args = insert_named(list(validate = "inner_valid"), args[[poid]])) + invoke(set_validate, learner = learner$graph$pipeops[[poid]]$learner, .args = insert_named(list(validate = "predefined"), args[[poid]])) }, error = function(e) { e$message = sprintf("Failed to set validate for PipeOp '%s':\n%s", poid, e$message) stop(e) @@ -401,12 +401,12 @@ set_validate.GraphLearner = function(learner, validate, ids = NULL, args = list( #' @export -disable_inner_tuning.GraphLearner = function(learner, ids, ...) { +disable_internal_tuning.GraphLearner = function(learner, ids, ...) { pvs = learner$param_set$values on.exit({learner$param_set$values = pvs}, add = TRUE) if (length(ids)) { walk(learner_wrapping_pipeops(learner), function(po) { - disable_inner_tuning(po$learner, ids = po$param_set$ids()[sprintf("%s.%s", po$id, po$param_set$ids()) %in% ids]) + disable_internal_tuning(po$learner, ids = po$param_set$ids()[sprintf("%s.%s", po$id, po$param_set$ids()) %in% ids]) }) } on.exit() diff --git a/R/PipeOpImpute.R b/R/PipeOpImpute.R index 546c11b9f..3c10f2d3a 100644 --- a/R/PipeOpImpute.R +++ b/R/PipeOpImpute.R @@ -195,8 +195,8 @@ PipeOpImpute = R6Class("PipeOpImpute", self$state$outtasklayout = copy(intask$feature_types) - if (!is.null(intask$inner_valid_task)) { - intask$inner_valid_task = private$.predict(list(intask$inner_valid_task))[[1L]] + if (!is.null(intask$internal_valid_task)) { + intask$internal_valid_task = private$.predict(list(intask$internal_valid_task))[[1L]] } list(intask) diff --git a/R/PipeOpTaskPreproc.R b/R/PipeOpTaskPreproc.R index da6f55bec..be829e85d 100644 --- a/R/PipeOpTaskPreproc.R +++ b/R/PipeOpTaskPreproc.R @@ -221,10 +221,10 @@ PipeOpTaskPreproc = R6Class("PipeOpTaskPreproc", self$state$outtasklayout = copy(intask$feature_types) self$state$outtaskshell = intask$data(rows = intask$row_ids[0]) - if (!is.null(intask$inner_valid_task)) { + if (!is.null(intask$internal_valid_task)) { # we call into .predict() and not .predict_task() to not put the burden # of subsetting the features etc. on the PipeOp overwriting .predict_task - intask$inner_valid_task = private$.predict(list(intask$inner_valid_task))[[1L]] + intask$internal_valid_task = private$.predict(list(intask$internal_valid_task))[[1L]] } if (do_subset) { diff --git a/inst/testthat/helper_functions.R b/inst/testthat/helper_functions.R index a42710509..9b2fe1a1b 100644 --- a/inst/testthat/helper_functions.R +++ b/inst/testthat/helper_functions.R @@ -441,15 +441,15 @@ expect_datapreproc_pipeop_class = function(poclass, constargs = list(), task, tasktrain$row_roles$use = tasktrain$row_roles$use[seq(1, n_use - 2)] taskpredict = tasktrain$clone(deep = TRUE) - taskpredict$row_roles$use = taskpredict$inner_valid_task$row_roles$use - taskpredict$inner_valid_task = NULL + taskpredict$row_roles$use = taskpredict$internal_valid_task$row_roles$use + taskpredict$internal_valid_task = NULL taskouttrain = po$train(list(tasktrain))[[1L]] taskoutpredict = po$predict(list(taskpredict))[[1L]] # other columns like weights are present during traing but not during predict cols = unname(unlist(taskouttrain$col_roles[c("feature", "target")])) - dtrain = taskouttrain$inner_valid_task$data(cols = cols) + dtrain = taskouttrain$internal_valid_task$data(cols = cols) dpredict = taskoutpredict$data(cols = cols) expect_permutation(colnames(dtrain), colnames(dpredict)) expect_equal(nrow(dtrain), nrow(dpredict)) diff --git a/man/mlr_learners_avg.Rd b/man/mlr_learners_avg.Rd index d139fa18e..afba4e11c 100644 --- a/man/mlr_learners_avg.Rd +++ b/man/mlr_learners_avg.Rd @@ -44,7 +44,7 @@ and \code{"regr.mse"}, i.e. mean squared error for regression. \item \code{optimizer} :: \code{\link[bbotk:Optimizer]{Optimizer}} | \code{character(1)}\cr \code{\link[bbotk:Optimizer]{Optimizer}} used to find optimal thresholds. If \code{character}, converts to \code{\link[bbotk:Optimizer]{Optimizer}} -via \code{\link[bbotk:opt]{opt}}. Initialized to \code{\link[bbotk:mlr_optimizers_nloptr]{OptimizerNLoptr}}. +via \code{\link[bbotk:opt]{opt}}. Initialized to \code{\link[bbotk:OptimizerNLoptr]{OptimizerNLoptr}}. Nloptr hyperparameters are initialized to \code{xtol_rel = 1e-8}, \code{algorithm = "NLOPT_LN_COBYLA"} and equal initial weights for each learner. For more fine-grained control, it is recommended to supply a instantiated \code{\link[bbotk:Optimizer]{Optimizer}}. diff --git a/man/mlr_learners_graph.Rd b/man/mlr_learners_graph.Rd index dd03ea316..33ba86c5b 100644 --- a/man/mlr_learners_graph.Rd +++ b/man/mlr_learners_graph.Rd @@ -56,13 +56,13 @@ Fields inherited from \code{\link{PipeOp}}, as well as: contain the model. Use \code{graph_model} to access the trained \code{\link{Graph}} after \verb{$train()}. Read-only. \item \code{graph_model} :: \code{\link[mlr3:Learner]{Learner}}\cr \code{\link{Graph}} that is being wrapped. This \code{\link{Graph}} contains a trained state after \verb{$train()}. Read-only. -\item \code{inner_tuned_values} :: named \code{list()} or \code{NULL}\cr -The inner tuned parameter values. -\code{NULL} is returned if the learner is not trained or none of the wrapped learners supports inner tuning. -\item \code{inner_valid_scores} :: named \code{list()} or \code{NULL}\cr -The inner tuned parameter values. +\item \code{internal_tuned_values} :: named \code{list()} or \code{NULL}\cr +The internal tuned parameter values. +\code{NULL} is returned if the learner is not trained or none of the wrapped learners supports internal tuning. +\item \code{internal_valid_scores} :: named \code{list()} or \code{NULL}\cr +The internal tuned parameter values. \code{NULL} is returned if the learner is not trained or none of the wrapped learners supports internal validation. -\item \code{validate} :: \code{numeric(1)}, \code{"inner_valid"}, \code{"test"} or \code{NULL}\cr +\item \code{validate} :: \code{numeric(1)}, \code{"predefined"}, \code{"test"} or \code{NULL}\cr How to construct the validation data. This also has to be configured in the individual learners wrapped by \code{PipeOpLearner}, see \code{\link{set_validate.GraphLearner}} on how to configure this. } diff --git a/man/mlr_pipeops_tunethreshold.Rd b/man/mlr_pipeops_tunethreshold.Rd index 683c87f61..3845c8f65 100644 --- a/man/mlr_pipeops_tunethreshold.Rd +++ b/man/mlr_pipeops_tunethreshold.Rd @@ -60,7 +60,7 @@ Initialized to \code{"classif.ce"}, i.e. misclassification error. \item \code{optimizer} :: \code{\link[bbotk:Optimizer]{Optimizer}}|\code{character(1)}\cr \code{\link[bbotk:Optimizer]{Optimizer}} used to find optimal thresholds. If \code{character}, converts to \code{\link[bbotk:Optimizer]{Optimizer}} -via \code{\link[bbotk:opt]{opt}}. Initialized to \code{\link[bbotk:mlr_optimizers_gensa]{OptimizerGenSA}}. +via \code{\link[bbotk:opt]{opt}}. Initialized to \code{\link[bbotk:OptimizerGenSA]{OptimizerGenSA}}. \item \code{log_level} :: \code{character(1)} | \code{integer(1)}\cr Set a temporary log-level for \code{lgr::get_logger("bbotk")}. Initialized to: "warn". } diff --git a/man/set_validate.GraphLearner.Rd b/man/set_validate.GraphLearner.Rd index 5224f2d4e..302710c7d 100644 --- a/man/set_validate.GraphLearner.Rd +++ b/man/set_validate.GraphLearner.Rd @@ -10,7 +10,7 @@ \item{learner}{(\code{\link{GraphLearner}})\cr The graph learner to configure.} -\item{validate}{(\code{numeric(1)}, \code{"inner_valid"}, \code{"test"}, or \code{NULL})\cr +\item{validate}{(\code{numeric(1)}, \code{"predefined"}, \code{"test"}, or \code{NULL})\cr How to set the \verb{$validate} field of the learner. If set to \code{NULL} all validation is disabled, both on the graph learner level, but also for all pipeops.} @@ -36,7 +36,7 @@ In a \code{\link{GraphLearner}}, validation can be configured on two levels: \item On the level of the \code{\link{Learner}}s that are wrapped by \code{\link{PipeOpLearner}} and \code{\link{PipeOpLearnerCV}}, which specifies which pipeops actually make use of the validation data. All learners wrapped by \code{\link{PipeOpLearner}} and \code{\link{PipeOpLearnerCV}} should in almost all cases either set it -to \code{NULL} (disable) or \code{"inner_valid"} (enable). +to \code{NULL} (disable) or \code{"predefined"} (enable). } } \examples{ diff --git a/tests/testthat/test_GraphLearner.R b/tests/testthat/test_GraphLearner.R index b552d1e69..bd82f360c 100644 --- a/tests/testthat/test_GraphLearner.R +++ b/tests/testthat/test_GraphLearner.R @@ -578,78 +578,78 @@ test_that("GraphLearner hashes", { }) -test_that("validation, inner_valid_scores", { +test_that("validation, internal_valid_scores", { # None of the Learners can do validation -> NULL glrn1 = as_learner(as_graph(lrn("classif.rpart")))$train(tsk("iris")) expect_false("validation" %in% glrn1$properties) - expect_equal(glrn1$inner_valid_scores, NULL) + expect_equal(glrn1$internal_valid_scores, NULL) glrn2 = as_learner(as_graph(lrn("classif.debug"))) expect_true("validation" %in% glrn2$properties) set_validate(glrn2, 0.2) expect_equal(glrn2$validate, 0.2) - expect_equal(glrn2$graph$pipeops$classif.debug$learner$validate, "inner_valid") + expect_equal(glrn2$graph$pipeops$classif.debug$learner$validate, "predefined") glrn2$train(tsk("iris")) - expect_list(glrn2$inner_valid_scores, types = "numeric") - expect_equal(names(glrn2$inner_valid_scores), "classif.debug.acc") + expect_list(glrn2$internal_valid_scores, types = "numeric") + expect_equal(names(glrn2$internal_valid_scores), "classif.debug.acc") set_validate(glrn2, NULL) glrn2$train(tsk("iris")) - expect_true(is.null(glrn2$inner_valid_scores)) + expect_true(is.null(glrn2$internal_valid_scores)) - # No validation set specified --> No inner_valid_scores + # No validation set specified --> No internal_valid_scores expect_equal( - as_learner(as_graph(lrn("classif.debug")))$train(tsk("iris"))$inner_valid_scores, + as_learner(as_graph(lrn("classif.debug")))$train(tsk("iris"))$internal_valid_scores, NULL ) glrn2 = as_learner(as_graph(lrn("classif.debug"))) }) -test_that("inner_tuned_values", { - # no inner tuning support -> NULL +test_that("internal_tuned_values", { + # no internal tuning support -> NULL task = tsk("iris") glrn1 = as_learner(as_graph(lrn("classif.rpart")))$train(task) - expect_false("inner_tuning" %in% glrn1$properties) - expect_equal(glrn1$inner_tuned_values, NULL) + expect_false("internal_tuning" %in% glrn1$properties) + expect_equal(glrn1$internal_tuned_values, NULL) - # learner with inner tuning + # learner with internal tuning glrn2 = as_learner(as_graph(lrn("classif.debug"))) - expect_true("inner_tuning" %in% glrn2$properties) - expect_equal(glrn2$inner_tuned_values, NULL) + expect_true("internal_tuning" %in% glrn2$properties) + expect_equal(glrn2$internal_tuned_values, NULL) glrn2$train(task) - expect_equal(glrn2$inner_tuned_values, named_list()) + expect_equal(glrn2$internal_tuned_values, named_list()) glrn2$param_set$set_values(classif.debug.early_stopping = TRUE, classif.debug.iter = 1000) set_validate(glrn2, 0.2) glrn2$train(task) - expect_equal(names(glrn2$inner_tuned_values), "classif.debug.iter") + expect_equal(names(glrn2$internal_tuned_values), "classif.debug.iter") }) -test_that("disable_inner_tuning", { +test_that("disable_internal_tuning", { glrn = as_learner(as_pipeop(lrn("classif.debug", iter = 100, early_stopping = TRUE))) - disable_inner_tuning(glrn, "classif.debug.iter") + disable_internal_tuning(glrn, "classif.debug.iter") expect_false(glrn$graph$pipeops$classif.debug$param_set$values$early_stopping) - expect_error(disable_inner_tuning(glrn, "classif.debug.abc"), "subset of") + expect_error(disable_internal_tuning(glrn, "classif.debug.abc"), "subset of") }) test_that("set_validate", { glrn = as_learner(as_pipeop(lrn("classif.debug", validate = 0.3))) set_validate(glrn, "test") expect_equal(glrn$validate, "test") - expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "inner_valid") + expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "predefined") set_validate(glrn, NULL) expect_equal(glrn$validate, NULL) expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, NULL) set_validate(glrn, 0.2, ids = "classif.debug") expect_equal(glrn$validate, 0.2) - expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "inner_valid") + expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "predefined") glrn = as_learner(ppl("stacking", list(lrn("classif.debug"), lrn("classif.featureless")), lrn("classif.debug", id = "final"))) set_validate(glrn, 0.3, ids = c("classif.debug", "final")) expect_equal(glrn$validate, 0.3) - expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "inner_valid") - expect_equal(glrn$graph$pipeops$final$learner$validate, "inner_valid") + expect_equal(glrn$graph$pipeops$classif.debug$learner$validate, "predefined") + expect_equal(glrn$graph$pipeops$final$learner$validate, "predefined") glrn = as_learner(ppl("stacking", list(lrn("classif.debug"), lrn("classif.featureless")), @@ -657,7 +657,7 @@ test_that("set_validate", { glrn2 = as_learner(po("learner", glrn, id = "polearner")) set_validate(glrn2, validate = 0.25, ids = "polearner", args = list(polearner = list(ids = "final"))) expect_equal(glrn2$validate, 0.25) - expect_equal(glrn2$graph$pipeops$polearner$learner$validate, "inner_valid") - expect_equal(glrn2$graph$pipeops$polearner$learner$graph$pipeops$final$learner$validate, "inner_valid") + expect_equal(glrn2$graph$pipeops$polearner$learner$validate, "predefined") + expect_equal(glrn2$graph$pipeops$polearner$learner$graph$pipeops$final$learner$validate, "predefined") expect_equal(glrn2$graph$pipeops$polearner$learner$graph$pipeops$classif.debug$learner$validate, NULL) }) diff --git a/tests/testthat/test_pipeop_impute.R b/tests/testthat/test_pipeop_impute.R index d795ed3ea..5168346ab 100644 --- a/tests/testthat/test_pipeop_impute.R +++ b/tests/testthat/test_pipeop_impute.R @@ -55,9 +55,9 @@ test_that("PipeOpImpute", { private = list( .get_state = function(task) { graph = self$build_graph() - inner_valid_task = task$inner_valid_task - on.exit({task$inner_valid_task = inner_valid_task}) - task$inner_valid_task = NULL + internal_valid_task = task$internal_valid_task + on.exit({task$internal_valid_task = internal_valid_task}) + task$internal_valid_task = NULL graph$train(task) list(gs = graph) }, @@ -409,6 +409,6 @@ test_that("impute, test rows and affect_columns", { task = tsk("pima") task$divide(1:30) outtrain = po_impute$train(list(task))[[1L]] - outpredict = po_impute$predict(list(task$inner_valid_task))[[1L]] - expect_true(isTRUE(all.equal(outtrain$inner_valid_task$data(), outpredict$data()))) + outpredict = po_impute$predict(list(task$internal_valid_task))[[1L]] + expect_true(isTRUE(all.equal(outtrain$internal_valid_task$data(), outpredict$data()))) })