diff --git a/.lintr b/.lintr index b8e47eb5..b85c3081 100644 --- a/.lintr +++ b/.lintr @@ -3,8 +3,6 @@ linters: linters_with_defaults( # the following setup changes/removes certain linters assignment_linter = NULL, # do not force using <- for assignments object_name_linter = object_name_linter(c("snake_case", "CamelCase")), # only allow snake case and camel case object names - cyclocomp_linter = NULL, # do not check function complexity commented_code_linter = NULL, # allow code in comments line_length_linter = NULL -) - + ) diff --git a/DESCRIPTION b/DESCRIPTION index 4f1be86d..935e953c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,6 +54,12 @@ Suggests: xgboost VignetteBuilder: knitr +Remotes: + mlr-org/mlr3misc@common_baseclass, + mlr-org/mlr3@common_baseclass, + mlr-org/mlr3pipelines@common_baseclass, + mlr-org/mlr3learners@common_baseclass, + mlr-org/bbotk@common_baseclass Config/testthat/edition: 3 Config/testthat/parallel: false Encoding: UTF-8 diff --git a/R/Tuner.R b/R/Tuner.R index 1bd1dd97..0e54f747 100644 --- a/R/Tuner.R +++ b/R/Tuner.R @@ -29,40 +29,29 @@ #' #' @export Tuner = R6Class("Tuner", + inherit = Mlr3Component, public = list( - - id = NULL, - #' @description #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function( - id = "tuner", + id, param_set, param_classes, properties, - packages = character(), - label = NA_character_, - man = NA_character_ - ) { - self$id = assert_string(id, min.chars = 1L) - private$.param_set = assert_param_set(param_set) + packages = character(0), + label, + man + ) { + if (!missing(label) || !missing(man)) { + mlr3component_deprecation_msg("label and man are deprecated for Tuner construction and will be removed in the future.") + } + + super$initialize(dict_entry = id, dict_shortaccess = "tnr", + param_set = param_set, packages = packages, properties = properties + ) private$.param_classes = assert_subset(param_classes, c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct", "ParamUty")) # has to have at least multi-crit or single-crit property - private$.properties = assert_subset(properties, bbotk_reflections$optimizer_properties, empty.ok = FALSE) - private$.packages = union("mlr3tuning", assert_character(packages, any.missing = FALSE, min.chars = 1L)) - private$.label = assert_string(label, na.ok = TRUE) - private$.man = assert_string(man, na.ok = TRUE) - - check_packages_installed(self$packages, msg = sprintf("Package '%%s' required but not installed for Tuner '%s'", format(self))) - }, - - #' @description - #' Helper for print outputs. - #' - #' @return (`character()`). - #' @param ... (ignored). - format = function(...) { - sprintf("<%s>", class(self)[1L]) + assert_subset(properties, bbotk_reflections$optimizer_properties, empty.ok = FALSE) }, #' @description @@ -90,16 +79,6 @@ Tuner = R6Class("Tuner", ), active = list( - - #' @field param_set ([paradox::ParamSet])\cr - #' Set of control parameters. - param_set = function(rhs) { - if (!missing(rhs) && !identical(rhs, private$.param_set)) { - stop("$param_set is read-only.") - } - private$.param_set - }, - #' @field param_classes (`character()`)\cr #' Supported parameter classes for learner hyperparameters that the tuner can optimize, as given in the [paradox::ParamSet] `$class` field. param_classes = function(rhs) { @@ -107,46 +86,6 @@ Tuner = R6Class("Tuner", stop("$param_classes is read-only.") } private$.param_classes - }, - - #' @field properties (`character()`)\cr - #' Set of properties of the tuner. - #' Must be a subset of [`mlr_reflections$tuner_properties`][mlr3::mlr_reflections]. - properties = function(rhs) { - if (!missing(rhs) && !identical(rhs, private$.properties)) { - stop("$properties is read-only.") - } - private$.properties - }, - - #' @field packages (`character()`)\cr - #' Set of required packages. - #' Note that these packages will be loaded via [requireNamespace()], and are not attached. - packages = function(rhs) { - if (!missing(rhs) && !identical(rhs, private$.packages)) { - stop("$packages is read-only.") - } - private$.packages - }, - - #' @field label (`character(1)`)\cr - #' Label for this object. - #' Can be used in tables, plot and text output instead of the ID. - label = function(rhs) { - if (!missing(rhs) && !identical(rhs, private$.param_set)) { - stop("$label is read-only.") - } - private$.label - }, - - #' @field man (`character(1)`)\cr - #' String in the format `[pkg]::[topic]` pointing to a manual page for this object. - #' The referenced help package can be opened via method `$help()`. - man = function(rhs) { - if (!missing(rhs) && !identical(rhs, private$.man)) { - stop("$man is read-only.") - } - private$.man } ), @@ -158,12 +97,7 @@ Tuner = R6Class("Tuner", assign_result_default(inst) }, - .param_set = NULL, - .param_classes = NULL, - .properties = NULL, - .packages = NULL, - .label = NULL, - .man = NULL + .param_classes = NULL ) ) diff --git a/R/TunerAsyncDesignPoints.R b/R/TunerAsyncDesignPoints.R index bb3d491e..1e63d93b 100644 --- a/R/TunerAsyncDesignPoints.R +++ b/R/TunerAsyncDesignPoints.R @@ -20,8 +20,7 @@ TunerAsyncDesignPoints = R6Class("TunerAsyncDesignPoints", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerAsyncDesignPoints$new(), - man = "mlr3tuning::mlr_tuners_async_design_points" + optimizer = OptimizerAsyncDesignPoints$new() ) } ) diff --git a/R/TunerAsyncFromOptimizerAsync.R b/R/TunerAsyncFromOptimizerAsync.R index 28f8bc99..7279aa4b 100644 --- a/R/TunerAsyncFromOptimizerAsync.R +++ b/R/TunerAsyncFromOptimizerAsync.R @@ -16,19 +16,20 @@ TunerAsyncFromOptimizerAsync = R6Class("TunerAsyncFromOptimizerAsync", #' #' @param optimizer [bbotk::Optimizer]\cr #' Optimizer that is called. - initialize = function(optimizer, man = NA_character_) { + initialize = function(optimizer, man) { private$.optimizer = assert_optimizer_async(optimizer) packages = union("mlr3tuning", optimizer$packages) - assert_string(man, na.ok = TRUE) + + if (!missing(man)) { + mlr3component_deprecation_msg("man is deprecated for Tuner construction and will be removed in the future.") + } super$initialize( id = if ("id" %in% names(optimizer)) optimizer$id else "tuner", param_set = optimizer$param_set, param_classes = optimizer$param_classes, properties = optimizer$properties, - packages = packages, - label = optimizer$label, - man = man + packages = packages ) }, diff --git a/R/TunerAsyncGridSearch.R b/R/TunerAsyncGridSearch.R index 8b16d9b0..0e496a6c 100644 --- a/R/TunerAsyncGridSearch.R +++ b/R/TunerAsyncGridSearch.R @@ -20,8 +20,7 @@ TunerAsyncGridSearch = R6Class("TunerAsyncGridSearch", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = bbotk::OptimizerAsyncGridSearch$new(), - man = "mlr3tuning::mlr_tuners_async_grid_search" + optimizer = bbotk::OptimizerAsyncGridSearch$new() ) } ) diff --git a/R/TunerAsyncRandomSearch.R b/R/TunerAsyncRandomSearch.R index 0c849574..b286c58b 100644 --- a/R/TunerAsyncRandomSearch.R +++ b/R/TunerAsyncRandomSearch.R @@ -24,8 +24,7 @@ TunerAsyncRandomSearch = R6Class("TunerAsyncRandomSearch", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = bbotk::OptimizerAsyncRandomSearch$new(), - man = "mlr3tuning::mlr_tuners_async_random_search" + optimizer = bbotk::OptimizerAsyncRandomSearch$new() ) } ) diff --git a/R/TunerBatch.R b/R/TunerBatch.R index 0ca97ee2..aa964b9f 100644 --- a/R/TunerBatch.R +++ b/R/TunerBatch.R @@ -59,9 +59,7 @@ TunerBatch = R6Class("TunerBatch", param_set = param_set, param_classes = param_classes, properties = properties, - packages = packages, - label = label, - man = man + packages = packages ) }, diff --git a/R/TunerBatchCmaes.R b/R/TunerBatchCmaes.R index 99f69fad..10df411d 100644 --- a/R/TunerBatchCmaes.R +++ b/R/TunerBatchCmaes.R @@ -66,8 +66,7 @@ TunerBatchCmaes = R6Class("TunerBatchCmaes", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerBatchCmaes$new(), - man = "mlr3tuning::mlr_tuners_cmaes" + optimizer = OptimizerBatchCmaes$new() ) } ) diff --git a/R/TunerBatchDesignPoints.R b/R/TunerBatchDesignPoints.R index 45c555c9..898d1c46 100644 --- a/R/TunerBatchDesignPoints.R +++ b/R/TunerBatchDesignPoints.R @@ -66,8 +66,7 @@ TunerBatchDesignPoints = R6Class("TunerBatchDesignPoints", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerBatchDesignPoints$new(), - man = "mlr3tuning::mlr_tuners_design_points" + optimizer = OptimizerBatchDesignPoints$new() ) } ) diff --git a/R/TunerBatchFromBatchOptimizer.R b/R/TunerBatchFromBatchOptimizer.R index 3548bce2..cfc1ea6b 100644 --- a/R/TunerBatchFromBatchOptimizer.R +++ b/R/TunerBatchFromBatchOptimizer.R @@ -16,19 +16,20 @@ TunerBatchFromOptimizerBatch = R6Class("TunerBatchFromOptimizerBatch", #' #' @param optimizer [bbotk::Optimizer]\cr #' Optimizer that is called. - initialize = function(optimizer, man = NA_character_) { + initialize = function(optimizer, man) { private$.optimizer = assert_optimizer(optimizer) packages = union("mlr3tuning", optimizer$packages) - assert_string(man, na.ok = TRUE) + + if (!missing(man)) { + mlr3component_deprecation_msg("man is deprecated for Tuner construction and will be removed in the future.") + } super$initialize( id = if ("id" %in% names(optimizer)) optimizer$id else "tuner", param_set = optimizer$param_set, param_classes = optimizer$param_classes, properties = optimizer$properties, - packages = packages, - label = optimizer$label, - man = man + packages = packages ) }, diff --git a/R/TunerBatchGenSA.R b/R/TunerBatchGenSA.R index 1ccc141e..ca93fe30 100644 --- a/R/TunerBatchGenSA.R +++ b/R/TunerBatchGenSA.R @@ -36,8 +36,7 @@ TunerBatchGenSA = R6Class("TunerBatchGenSA", optimizer = OptimizerBatchGenSA$new() optimizer$param_set$values$smooth = FALSE super$initialize( - optimizer = optimizer, - man = "mlr3tuning::mlr_tuners_gensa" + optimizer = optimizer ) } ) diff --git a/R/TunerBatchGridSearch.R b/R/TunerBatchGridSearch.R index 6a6fb789..15e636e8 100644 --- a/R/TunerBatchGridSearch.R +++ b/R/TunerBatchGridSearch.R @@ -41,8 +41,7 @@ TunerBatchGridSearch = R6Class("TunerBatchGridSearch", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerBatchGridSearch$new(), - man = "mlr3tuning::mlr_tuners_grid_search" + optimizer = OptimizerBatchGridSearch$new() ) } ) diff --git a/R/TunerBatchInternal.R b/R/TunerBatchInternal.R index 73990211..f0273487 100644 --- a/R/TunerBatchInternal.R +++ b/R/TunerBatchInternal.R @@ -56,9 +56,7 @@ TunerBatchInternal = R6Class("TunerBatchInternal", id = "internal", param_set = ps(), param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct"), - properties = c("dependencies", "single-crit"), - label = "Internal Optimizer", - man = "mlr3tuning::mlr_tuners_internal" + properties = c("dependencies", "single-crit") ) } ), @@ -80,9 +78,7 @@ OptimizerBatchInternal = R6Class("OptimizerBatchInternal", id = "internal", param_set = ps(), param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct"), - properties = c("dependencies", "single-crit"), - label = "Internal Optimizer", - man = "bbotk::mlr_optimizers_internal" + properties = c("dependencies", "single-crit") ) } ), diff --git a/R/TunerBatchIrace.R b/R/TunerBatchIrace.R index 8b3fab88..1be74d52 100644 --- a/R/TunerBatchIrace.R +++ b/R/TunerBatchIrace.R @@ -92,8 +92,7 @@ TunerBatchIrace = R6Class("TunerBatchIrace", ) super$initialize( - optimizer = optimizer, - man = "mlr3tuning::mlr_tuners_irace" + optimizer = optimizer ) private$.optimizer$.__enclos_env__$private$.param_set = ParamSetCollection$new(list( diff --git a/R/TunerBatchNLoptr.R b/R/TunerBatchNLoptr.R index a5db91e2..37686f9c 100644 --- a/R/TunerBatchNLoptr.R +++ b/R/TunerBatchNLoptr.R @@ -63,8 +63,7 @@ TunerBatchNLoptr = R6Class("TunerBatchNLoptr", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerBatchNLoptr$new(), - man = "mlr3tuning::mlr_tuners_nloptr" + optimizer = OptimizerBatchNLoptr$new() ) } ) diff --git a/R/TunerBatchRandomSearch.R b/R/TunerBatchRandomSearch.R index da4f803e..24ae6fe8 100644 --- a/R/TunerBatchRandomSearch.R +++ b/R/TunerBatchRandomSearch.R @@ -35,8 +35,7 @@ TunerBatchRandomSearch = R6Class("TunerBatchRandomSearch", #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerBatchRandomSearch$new(), - man = "mlr3tuning::mlr_tuners_random_search" + optimizer = OptimizerBatchRandomSearch$new() ) } ) diff --git a/man/AutoTuner.Rd b/man/AutoTuner.Rd index 53fa236c..cad3a64a 100644 --- a/man/AutoTuner.Rd +++ b/man/AutoTuner.Rd @@ -137,8 +137,8 @@ rr$score() # unbiased performance of the final model trained on the full data set rr$aggregate() } -\section{Super class}{ -\code{\link[mlr3:Learner]{mlr3::Learner}} -> \code{AutoTuner} +\section{Super classes}{ +\code{\link[mlr3misc:Mlr3Component]{mlr3misc::Mlr3Component}} -> \code{\link[mlr3:Learner]{mlr3::Learner}} -> \code{AutoTuner} } \section{Public fields}{ \if{html}{\out{
mlr3::Learner$configure()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$help()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3::Learner$encapsulate()mlr3::Learner$format()mlr3::Learner$help()mlr3::Learner$predict()mlr3::Learner$predict_newdata()mlr3::Learner$reset()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$initialize()mlr3tuning::Tuner$print()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerAsyncFromOptimizerAsync$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerAsyncFromOptimizerAsync$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerAsyncFromOptimizerAsync$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()mlr3tuning::Tuner$format()mlr3misc::Mlr3Component$configure()mlr3misc::Mlr3Component$format()mlr3misc::Mlr3Component$override_info()mlr3misc::Mlr3Component$require_namespaces()mlr3tuning::Tuner$help()mlr3tuning::Tuner$print()mlr3tuning::TunerBatchFromOptimizerBatch$optimize()