Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

)
6 changes: 6 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
96 changes: 15 additions & 81 deletions R/Tuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,63 +79,13 @@ 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) {
if (!missing(rhs) && !identical(rhs, private$.param_classes)) {
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
}
),

Expand All @@ -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
)
)

3 changes: 1 addition & 2 deletions R/TunerAsyncDesignPoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
11 changes: 6 additions & 5 deletions R/TunerAsyncFromOptimizerAsync.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
},

Expand Down
3 changes: 1 addition & 2 deletions R/TunerAsyncGridSearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/TunerAsyncRandomSearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
4 changes: 1 addition & 3 deletions R/TunerBatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
},

Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchCmaes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchDesignPoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
11 changes: 6 additions & 5 deletions R/TunerBatchFromBatchOptimizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
},

Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchGenSA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchGridSearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
8 changes: 2 additions & 6 deletions R/TunerBatchInternal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
}
),
Expand All @@ -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")
)
}
),
Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchIrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchNLoptr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
3 changes: 1 addition & 2 deletions R/TunerBatchRandomSearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
)
Expand Down
12 changes: 7 additions & 5 deletions man/AutoTuner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading