From a613c58c82c51f6b65fa87364bcfbf543649cd69 Mon Sep 17 00:00:00 2001 From: be-marc Date: Fri, 10 May 2024 09:57:54 +0200 Subject: [PATCH 1/2] refactor: prepare for bbotk 0.9.0 --- DESCRIPTION | 40 +++-- NAMESPACE | 38 +++-- NEWS.md | 32 ++-- R/{ArchiveFSelect.R => ArchiveBatchFSelect.R} | 16 +- R/AutoFSelector.R | 14 +- ...llbackFSelect.R => CallbackBatchFSelect.R} | 81 +++++---- R/{ContextEval.R => ContextBatchFSelect.R} | 24 +-- ...Crit.R => FSelectInstanceBatchMultiCrit.R} | 40 +++-- ...rit.R => FSelectInstanceBatchSingleCrit.R} | 42 ++--- R/FSelector.R | 91 +++------- R/FSelectorBatch.R | 79 +++++++++ ...nPoints.R => FSelectorBatchDesignPoints.R} | 10 +- ...rch.R => FSelectorBatchExhaustiveSearch.R} | 6 +- ...r.R => FSelectorBatchFromOptimizerBatch.R} | 14 +- ...Search.R => FSelectorBatchGeneticSearch.R} | 6 +- R/{FSelectorRFE.R => FSelectorBatchRFE.R} | 10 +- R/{FSelectorRFECV.R => FSelectorBatchRFECV.R} | 14 +- ...mSearch.R => FSelectorBatchRandomSearch.R} | 6 +- ...equential.R => FSelectorBatchSequential.R} | 10 +- ...R => FSelectorBatchShadowVariableSearch.R} | 10 +- R/ObjectiveFSelect.R | 76 ++------- R/ObjectiveFSelectBatch.R | 101 ++++++++++++ R/assertions.R | 60 +++++++ R/auto_fselector.R | 2 +- R/fselect.R | 24 +-- R/fselect_nested.R | 2 +- R/mlr_callbacks.R | 17 +- R/mlr_fselectors.R | 2 +- R/sugar.R | 18 +- README.md | 34 ++-- inst/WORDLIST | 20 +-- inst/testthat/helper_misc.R | 4 +- man-roxygen/field_id.R | 3 + man-roxygen/param_callbacks.R | 2 +- man-roxygen/param_id.R | 2 + man-roxygen/param_label.R | 3 + man-roxygen/param_packages.R | 3 + man-roxygen/param_param_set.R | 2 + man-roxygen/param_properties.R | 3 + man-roxygen/param_store_fselect_instance.R | 2 +- man-roxygen/param_xdt.R | 2 +- ...chiveFSelect.Rd => ArchiveBatchFSelect.Rd} | 90 +++++----- man/AutoFSelector.Rd | 17 +- ...backFSelect.Rd => CallbackBatchFSelect.Rd} | 30 ++-- ...{ContextEval.Rd => ContextBatchFSelect.Rd} | 51 ++---- ...it.Rd => FSelectInstanceBatchMultiCrit.Rd} | 54 +++--- ...t.Rd => FSelectInstanceBatchSingleCrit.Rd} | 58 +++---- man/FSelector.Rd | 68 ++------ man/FSelectorBatch.Rd | 155 ++++++++++++++++++ ...Rd => FSelectorBatchFromOptimizerBatch.Rd} | 42 ++--- man/ObjectiveFSelect.Rd | 15 +- man/ObjectiveFSelectBatch.Rd | 112 +++++++++++++ man/auto_fselector.Rd | 6 +- ...k_fselect.Rd => callback_batch_fselect.Rd} | 46 +++--- man/fs.Rd | 2 +- man/fselect.Rd | 16 +- man/fselect_nested.Rd | 6 +- man/fsi.Rd | 8 +- man/mlr3fselect.backup.Rd | 2 +- man/mlr3fselect_assertions.Rd | 35 ++++ man/mlr_fselectors.Rd | 1 + man/mlr_fselectors_design_points.Rd | 25 +-- man/mlr_fselectors_exhaustive_search.Rd | 27 +-- man/mlr_fselectors_genetic_search.Rd | 27 +-- man/mlr_fselectors_random_search.Rd | 27 +-- man/mlr_fselectors_rfe.Rd | 29 ++-- man/mlr_fselectors_rfecv.Rd | 31 ++-- man/mlr_fselectors_sequential.Rd | 39 ++--- man/mlr_fselectors_shadow_variable_search.Rd | 39 ++--- tests/testthat/test_ArchiveFSelect.R | 8 +- tests/testthat/test_AutoFSelector.R | 10 +- .../testthat/test_FSelectInstanceMultiCrit.R | 2 +- .../testthat/test_FSelectInstanceSingleCrit.R | 2 +- tests/testthat/test_ObjectiveFSelect.R | 18 +- tests/testthat/test_fselect.R | 14 +- tests/testthat/test_fsi.R | 20 +-- 76 files changed, 1258 insertions(+), 839 deletions(-) rename R/{ArchiveFSelect.R => ArchiveBatchFSelect.R} (94%) rename R/{CallbackFSelect.R => CallbackBatchFSelect.R} (65%) rename R/{ContextEval.R => ContextBatchFSelect.R} (72%) rename R/{FSelectInstanceMultiCrit.R => FSelectInstanceBatchMultiCrit.R} (79%) rename R/{FSelectInstanceSingleCrit.R => FSelectInstanceBatchSingleCrit.R} (85%) create mode 100644 R/FSelectorBatch.R rename R/{FSelectorDesignPoints.R => FSelectorBatchDesignPoints.R} (86%) rename R/{FSelectorExhaustiveSearch.R => FSelectorBatchExhaustiveSearch.R} (91%) rename R/{FSelectorFromOptimizer.R => FSelectorBatchFromOptimizerBatch.R} (74%) rename R/{FSelectorGeneticSearch.R => FSelectorBatchGeneticSearch.R} (91%) rename R/{FSelectorRFE.R => FSelectorBatchRFE.R} (97%) rename R/{FSelectorRFECV.R => FSelectorBatchRFECV.R} (94%) rename R/{FSelectorRandomSearch.R => FSelectorBatchRandomSearch.R} (94%) rename R/{FSelectorSequential.R => FSelectorBatchSequential.R} (93%) rename R/{FSelectorShadowVariableSearch.R => FSelectorBatchShadowVariableSearch.R} (93%) create mode 100644 R/ObjectiveFSelectBatch.R create mode 100644 man-roxygen/field_id.R create mode 100644 man-roxygen/param_id.R create mode 100644 man-roxygen/param_label.R create mode 100644 man-roxygen/param_packages.R create mode 100644 man-roxygen/param_param_set.R create mode 100644 man-roxygen/param_properties.R rename man/{ArchiveFSelect.Rd => ArchiveBatchFSelect.Rd} (67%) rename man/{CallbackFSelect.Rd => CallbackBatchFSelect.Rd} (70%) rename man/{ContextEval.Rd => ContextBatchFSelect.Rd} (58%) rename man/{FSelectInstanceMultiCrit.Rd => FSelectInstanceBatchMultiCrit.Rd} (68%) rename man/{FSelectInstanceSingleCrit.Rd => FSelectInstanceBatchSingleCrit.Rd} (74%) create mode 100644 man/FSelectorBatch.Rd rename man/{FSelectorFromOptimizer.Rd => FSelectorBatchFromOptimizerBatch.Rd} (55%) create mode 100644 man/ObjectiveFSelectBatch.Rd rename man/{callback_fselect.Rd => callback_batch_fselect.Rd} (69%) create mode 100644 man/mlr3fselect_assertions.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5af055c1..a9d42301 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,12 +25,12 @@ Depends: mlr3 (>= 0.12.0), R (>= 3.1.0) Imports: - bbotk (>= 0.7.2), + bbotk (>= 0.8.0.9000), checkmate (>= 2.0.0), data.table, lgr, - mlr3misc (>= 0.9.4), - paradox (>= 0.7.0), + mlr3misc (>= 0.15.0.9000), + paradox (>= 1.0.0), R6 Suggests: e1071, @@ -39,6 +39,10 @@ Suggests: mlr3pipelines, rpart, testthat (>= 3.0.0) +Remotes: + mlr-org/bbotk, + mlr-org/paradox, + mlr-org/mlr3misc Config/testthat/edition: 3 Config/testthat/parallel: true Encoding: UTF-8 @@ -47,24 +51,26 @@ NeedsCompilation: no Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Collate: - 'ArchiveFSelect.R' + 'ArchiveBatchFSelect.R' 'AutoFSelector.R' - 'CallbackFSelect.R' - 'ContextEval.R' - 'FSelectInstanceSingleCrit.R' - 'FSelectInstanceMultiCrit.R' + 'CallbackBatchFSelect.R' + 'ContextBatchFSelect.R' + 'FSelectInstanceBatchSingleCrit.R' + 'FSelectInstanceBatchMultiCrit.R' 'mlr_fselectors.R' 'FSelector.R' - 'FSelectorDesignPoints.R' - 'FSelectorExhaustiveSearch.R' - 'FSelectorFromOptimizer.R' - 'FSelectorGeneticSearch.R' - 'FSelectorRFE.R' - 'FSelectorRFECV.R' - 'FSelectorRandomSearch.R' - 'FSelectorSequential.R' - 'FSelectorShadowVariableSearch.R' + 'FSelectorBatch.R' + 'FSelectorBatchDesignPoints.R' + 'FSelectorBatchExhaustiveSearch.R' + 'FSelectorBatchFromOptimizerBatch.R' + 'FSelectorBatchGeneticSearch.R' + 'FSelectorBatchRFE.R' + 'FSelectorBatchRFECV.R' + 'FSelectorBatchRandomSearch.R' + 'FSelectorBatchSequential.R' + 'FSelectorBatchShadowVariableSearch.R' 'ObjectiveFSelect.R' + 'ObjectiveFSelectBatch.R' 'assertions.R' 'auto_fselector.R' 'bibentries.R' diff --git a/NAMESPACE b/NAMESPACE index 6e326f11..cf23b592 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,29 +1,37 @@ # Generated by roxygen2: do not edit by hand -S3method(as.data.table,ArchiveFSelect) +S3method(as.data.table,ArchiveBatchFSelect) S3method(as.data.table,DictionaryFSelector) S3method(extract_inner_fselect_archives,BenchmarkResult) S3method(extract_inner_fselect_archives,ResampleResult) S3method(extract_inner_fselect_results,BenchmarkResult) S3method(extract_inner_fselect_results,ResampleResult) -export(ArchiveFSelect) +export(ArchiveBatchFSelect) export(AutoFSelector) -export(ContextEval) -export(FSelectInstanceMultiCrit) -export(FSelectInstanceSingleCrit) +export(ContextBatchFSelect) +export(FSelectInstanceBatchMultiCrit) +export(FSelectInstanceBatchSingleCrit) export(FSelector) -export(FSelectorDesignPoints) -export(FSelectorExhaustiveSearch) -export(FSelectorFromOptimizer) -export(FSelectorGeneticSearch) -export(FSelectorRFE) -export(FSelectorRFECV) -export(FSelectorRandomSearch) -export(FSelectorSequential) -export(FSelectorShadowVariableSearch) +export(FSelectorBatch) +export(FSelectorBatchDesignPoints) +export(FSelectorBatchExhaustiveSearch) +export(FSelectorBatchFromOptimizerBatch) +export(FSelectorBatchGeneticSearch) +export(FSelectorBatchRFE) +export(FSelectorBatchRFECV) +export(FSelectorBatchRandomSearch) +export(FSelectorBatchSequential) +export(FSelectorBatchShadowVariableSearch) export(ObjectiveFSelect) +export(ObjectiveFSelectBatch) +export(assert_fselect_instance) +export(assert_fselect_instance_async) +export(assert_fselect_instance_batch) +export(assert_fselector_async) +export(assert_fselector_batch) +export(assert_fselectors) export(auto_fselector) -export(callback_fselect) +export(callback_batch_fselect) export(clbk) export(clbks) export(extract_inner_fselect_archives) diff --git a/NEWS.md b/NEWS.md index 043f1809..69450d1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,15 +3,15 @@ # mlr3fselect 0.12.0 * feat: Add number of features to `instance$result`. -* feat: Add `ties_method` options `"least_features"` and `"random"` to `ArchiveFSelect$best()`. -* refactor: Optimize runtime of `ArchiveFSelect$best()` method. +* feat: Add `ties_method` options `"least_features"` and `"random"` to `ArchiveBatchFSelect$best()`. +* refactor: Optimize runtime of `ArchiveBatchFSelect$best()` method. * feat: Add importance scores to result of `FSelectorRFE`. -* feat: Add number of features to `as.data.table.ArchiveFSelect()`. +* feat: Add number of features to `as.data.table.ArchiveBatchFSelect()`. * feat: Features can be always included with the `always_include` column role. * fix: Add `$phash()` method to `AutoFSelector`. * fix: Include `FSelector` in hash of `AutoFSelector`. -* refactor: Change default batch size of `FSelectorRandomSearch` to 10. -* feat: Add `batch_size` parameter to `FSelectorExhaustiveSearch` to reduce memory consumption. +* refactor: Change default batch size of `FSelectorBatchRandomSearch` to 10. +* feat: Add `batch_size` parameter to `FSelectorBatchExhaustiveSearch` to reduce memory consumption. * compatibility: Work with new paradox version 1.0.0 # mlr3fselect 0.11.0 @@ -29,7 +29,7 @@ * refactor: The importance scores in `FSelectorRFE` are now aggregated by rank instead of averaging them. * feat: Add `FSelectorRFECV` optimizer to run recursive feature elimination with cross-validation. * refactor: `FSelectorRFE` works without `store_models = TRUE` now. -* feat: The `as.data.table.ArchiveFSelect()` function additionally returns a character vector of selected features for each row. +* feat: The `as.data.table.ArchiveBatchFSelect()` function additionally returns a character vector of selected features for each row. * refactor: Add `callbacks` argument to `fsi()` function. # mlr3fselect 0.9.1 @@ -39,9 +39,9 @@ # mlr3fselect 0.9.0 -* fix: Add `genalg` to required packages of `FSelectorGeneticSearch`. +* fix: Add `genalg` to required packages of `FSelectorBatchGeneticSearch`. * feat: Add new callback that backups the benchmark result to disk after each batch. -* feat: Create custom callbacks with the `callback_fselect()` function. +* feat: Create custom callbacks with the `callback_batch_fselect()` function. # mlr3fselect 0.8.0 @@ -49,8 +49,8 @@ * refactor: The `AutoFSelector` stores the instance and benchmark result if `store_models = TRUE`. * refactor: The `AutoFSelector` stores the instance if `store_benchmark_result = TRUE`. * feat: Add missing parameters from `AutoFSelector` to `auto_fselect()`. -* feat: Add `fsi()` function to create a `FSelectInstanceSingleCrit` or `FSelectInstanceMultiCrit`. -* refactor: Remove `unnest` option from `as.data.table.ArchiveFSelect()` function. +* feat: Add `fsi()` function to create a `FSelectInstanceBatchSingleCrit` or `FSelectInstanceBatchMultiCrit`. +* refactor: Remove `unnest` option from `as.data.table.ArchiveBatchFSelect()` function. # mlr3fselect 0.7.2 @@ -67,7 +67,7 @@ * docs: New examples with `fselect()` function. * feat: `$help()` method which opens manual page of a `FSelector`. * feat: Added a `as.data.table.DictionaryFSelector` function. -* feat: Added `min_features` parameter to `FSelectorSequential`. +* feat: Added `min_features` parameter to `FSelectorBatchSequential`. # mlr3fselect 0.6.1 @@ -90,7 +90,7 @@ * `FSelectorRFE` stores importance values of each evaluated feature set in archive. -* `ArchiveFSelect$data` is a public field now. +* `ArchiveBatchFSelect$data` is a public field now. # mlr3fselect 0.4.1 @@ -110,15 +110,15 @@ * Option to control `store_benchmark_result`, `store_models` and `check_values` in `AutoFSelector`. `store_fselect_instance` must be set as a parameter during initialization. -* Adds `FSelectorGeneticSearch`. -* Fixes `check_values` flag in `FSelectInstanceSingleCrit` and - `FSelectInstanceMultiCrit`. +* Adds `FSelectorBatchGeneticSearch`. +* Fixes `check_values` flag in `FSelectInstanceBatchSingleCrit` and + `FSelectInstanceBatchMultiCrit`. * Removed dependency on orphaned package `bibtex`. * `PipeOpSelect` is internally used for task subsetting. # mlr3fselect 0.3.0 -* `Archive` is `ArchiveFSelect` now which stores the benchmark result in +* `Archive` is `ArchiveBatchFSelect` now which stores the benchmark result in `$benchmark_result`. This change removed the resample results from the archive but they can be still accessed via the benchmark result. diff --git a/R/ArchiveFSelect.R b/R/ArchiveBatchFSelect.R similarity index 94% rename from R/ArchiveFSelect.R rename to R/ArchiveBatchFSelect.R index bc9f7d36..5826657f 100644 --- a/R/ArchiveFSelect.R +++ b/R/ArchiveBatchFSelect.R @@ -1,10 +1,10 @@ #' @title Class for Logging Evaluated Feature Sets #' #' @description -#' The [ArchiveFSelect] stores all evaluated feature sets and performance scores. +#' The [ArchiveBatchFSelect] stores all evaluated feature sets and performance scores. #' #' @details -#' The [ArchiveFSelect] is a container around a [data.table::data.table()]. +#' The [ArchiveBatchFSelect] is a container around a [data.table::data.table()]. #' Each row corresponds to a single evaluation of a feature set. #' See the section on Data Structure for more information. #' The archive stores additionally a [mlr3::BenchmarkResult] (`$benchmark_result`) that records the resampling experiments. @@ -40,10 +40,10 @@ #' Alternatively, measures can be supplied to `as.data.table()`. #' #' @section S3 Methods: -#' * `as.data.table.ArchiveFSelect(x, exclude_columns = "uhash", measures = NULL)`\cr +#' * `as.data.table.ArchiveBatchFSelect(x, exclude_columns = "uhash", measures = NULL)`\cr #' Returns a tabular view of all evaluated feature sets.\cr -#' [ArchiveFSelect] -> [data.table::data.table()]\cr -#' * `x` ([ArchiveFSelect]) +#' [ArchiveBatchFSelect] -> [data.table::data.table()]\cr +#' * `x` ([ArchiveBatchFSelect]) #' * `exclude_columns` (`character()`)\cr #' Exclude columns from table. Set to `NULL` if no column should be excluded. #' * `measures` (list of [mlr3::Measure])\cr @@ -52,8 +52,8 @@ #' @template param_ties_method #' #' @export -ArchiveFSelect = R6Class("ArchiveFSelect", - inherit = Archive, +ArchiveBatchFSelect = R6Class("ArchiveBatchFSelect", + inherit = ArchiveBatch, public = list( @@ -212,7 +212,7 @@ ArchiveFSelect = R6Class("ArchiveFSelect", ) #' @export -as.data.table.ArchiveFSelect = function(x, ..., exclude_columns = "uhash", measures = NULL) { +as.data.table.ArchiveBatchFSelect = function(x, ..., exclude_columns = "uhash", measures = NULL) { if (nrow(x$data) == 0) return(data.table()) # always ignore x_domain column exclude_columns = c("x_domain", exclude_columns) diff --git a/R/AutoFSelector.R b/R/AutoFSelector.R index 906704ab..655cc232 100644 --- a/R/AutoFSelector.R +++ b/R/AutoFSelector.R @@ -100,7 +100,7 @@ AutoFSelector = R6Class("AutoFSelector", public = list( #' @field instance_args (`list()`)\cr - #' All arguments from construction to create the [FSelectInstanceSingleCrit]. + #' All arguments from construction to create the [FSelectInstanceBatchSingleCrit]. instance_args = NULL, #' @field fselector ([FSelector])\cr @@ -122,7 +122,7 @@ AutoFSelector = R6Class("AutoFSelector", store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { ia = list() @@ -249,8 +249,8 @@ AutoFSelector = R6Class("AutoFSelector", active = list( - #' @field archive ([ArchiveFSelect)\cr - #' Returns [FSelectInstanceSingleCrit] archive. + #' @field archive ([ArchiveBatchFSelect)\cr + #' Returns [FSelectInstanceBatchSingleCrit] archive. archive = function() self$fselect_instance$archive, #' @field learner ([mlr3::Learner])\cr @@ -264,12 +264,12 @@ AutoFSelector = R6Class("AutoFSelector", } }, - #' @field fselect_instance ([FSelectInstanceSingleCrit])\cr + #' @field fselect_instance ([FSelectInstanceBatchSingleCrit])\cr #' Internally created feature selection instance with all intermediate results. fselect_instance = function() self$model$fselect_instance, #' @field fselect_result ([data.table::data.table])\cr - #' Short-cut to `$result` from [FSelectInstanceSingleCrit]. + #' Short-cut to `$result` from [FSelectInstanceBatchSingleCrit]. fselect_result = function() self$fselect_instance$result, #' @field predict_type (`character(1)`)\cr @@ -311,7 +311,7 @@ AutoFSelector = R6Class("AutoFSelector", # construct instance from args; then tune ia = self$instance_args ia$task = task$clone() - instance = invoke(FSelectInstanceSingleCrit$new, .args = ia) + instance = invoke(FSelectInstanceBatchSingleCrit$new, .args = ia) self$fselector$optimize(instance) learner = ia$learner$clone(deep = TRUE) task = task$clone() diff --git a/R/CallbackFSelect.R b/R/CallbackBatchFSelect.R similarity index 65% rename from R/CallbackFSelect.R rename to R/CallbackBatchFSelect.R index 7889ced0..b81a355e 100644 --- a/R/CallbackFSelect.R +++ b/R/CallbackBatchFSelect.R @@ -1,36 +1,36 @@ #' @title Create Feature Selection Callback #' #' @description -#' Specialized [bbotk::CallbackOptimization] for feature selection. +#' Specialized [bbotk::CallbackBatch] for feature selection. #' Callbacks allow customizing the behavior of processes in mlr3fselect. -#' The [callback_fselect()] function creates a [CallbackFSelect]. +#' The [callback_batch_fselect()] function creates a [CallbackBatchFSelect]. #' Predefined callbacks are stored in the [dictionary][mlr3misc::Dictionary] [mlr_callbacks] and can be retrieved with [clbk()]. -#' For more information on callbacks see [callback_fselect()]. +#' For more information on callbacks see [callback_batch_fselect()]. #' #' @examples #' # Write archive to disk -#' callback_fselect("mlr3fselect.backup", +#' callback_batch_fselect("mlr3fselect.backup", #' on_optimization_end = function(callback, context) { #' saveRDS(context$instance$archive, "archive.rds") #' } #' ) -CallbackFSelect = R6Class("CallbackFSelect", - inherit = bbotk::CallbackOptimization, +CallbackBatchFSelect = R6Class("CallbackBatchFSelect", + inherit = CallbackBatch, public = list( #' @field on_eval_after_design (`function()`)\cr #' Stage called after design is created. - #' Called in `ObjectiveFSelect$eval_many()`. + #' Called in `ObjectiveFSelectBatch$eval_many()`. on_eval_after_design = NULL, #' @field on_eval_after_benchmark (`function()`)\cr #' Stage called after feature sets are evaluated. - #' Called in `ObjectiveFSelect$eval_many()`. + #' Called in `ObjectiveFSelectBatch$eval_many()`. on_eval_after_benchmark = NULL, #' @field on_eval_before_archive (`function()`)\cr #' Stage called before performance values are written to the archive. - #' Called in `ObjectiveFSelect$eval_many()`. + #' Called in `ObjectiveFSelectBatch$eval_many()`. on_eval_before_archive = NULL ) ) @@ -38,7 +38,7 @@ CallbackFSelect = R6Class("CallbackFSelect", #' @title Create Feature Selection Callback #' #' @description -#' Function to create a [CallbackFSelect]. +#' Function to create a [CallbackBatchFSelect]. #' Predefined callbacks are stored in the [dictionary][mlr3misc::Dictionary] [mlr_callbacks] and can be retrieved with [clbk()]. #' #' Feature selection callbacks can be called from different stages of feature selection. @@ -62,7 +62,7 @@ CallbackFSelect = R6Class("CallbackFSelect", #' ``` #' #' See also the section on parameters for more information on the stages. -#' A feature selection callback works with [bbotk::ContextOptimization] and [ContextEval]. +#' A feature selection callback works with [bbotk::ContextBatch] and [ContextBatchFSelect]. #' #' @details #' When implementing a callback, each function must have two arguments named `callback` and `context`. @@ -72,13 +72,13 @@ CallbackFSelect = R6Class("CallbackFSelect", #' This can slow down the feature selection when the evaluation of configurations is parallelized. #' #' Feature selection callbacks access two different contexts depending on the stage. -#' The stages `on_eval_after_design`, `on_eval_after_benchmark`, `on_eval_before_archive` access [ContextEval]. +#' The stages `on_eval_after_design`, `on_eval_after_benchmark`, `on_eval_before_archive` access [ContextBatchFSelect]. #' This context can be used to customize the evaluation of a batch of feature sets. #' Changes to the state of callback are lost after the evaluation of a batch and changes to the fselect instance or the fselector are not possible. -#' Persistent data should be written to the archive via `$aggregated_performance` (see [ContextEval]). -#' The other stages access [ContextOptimization]. +#' Persistent data should be written to the archive via `$aggregated_performance` (see [ContextBatchFSelect]). +#' The other stages access [ContextBatch]. #' This context can be used to modify the fselect instance, archive, fselector and final result. -#' There are two different contexts because the evaluation can be parallelized i.e. multiple instances of [ContextEval] exists on different workers at the same time. +#' There are two different contexts because the evaluation can be parallelized i.e. multiple instances of [ContextBatchFSelect] exists on different workers at the same time. #' #' @param id (`character(1)`)\cr #' Identifier for the new instance. @@ -90,42 +90,63 @@ CallbackFSelect = R6Class("CallbackFSelect", #' @param on_optimization_begin (`function()`)\cr #' Stage called at the beginning of the optimization. #' Called in `Optimizer$optimize()`. -#' The context available is [bbotk::ContextOptimization]. #' @param on_optimizer_before_eval (`function()`)\cr #' Stage called after the optimizer proposes points. #' Called in `OptimInstance$eval_batch()`. -#' The context available is [bbotk::ContextOptimization]. #' @param on_eval_after_design (`function()`)\cr #' Stage called after design is created. -#' Called in `ObjectiveFSelect$eval_many()`. -#' The context available is [ContextEval]. +#' Called in `ObjectiveFSelectBatch$eval_many()`. #' @param on_eval_after_benchmark (`function()`)\cr #' Stage called after feature sets are evaluated. -#' Called in `ObjectiveFSelect$eval_many()`. -#' The context available is [ContextEval]. +#' Called in `ObjectiveFSelectBatch$eval_many()`. #' @param on_eval_before_archive (`function()`)\cr #' Stage called before performance values are written to the archive. -#' Called in `ObjectiveFSelect$eval_many()`. -#' The context available is [ContextEval]. +#' Called in `ObjectiveFSelectBatch$eval_many()`. #' @param on_optimizer_after_eval (`function()`)\cr #' Stage called after points are evaluated. #' Called in `OptimInstance$eval_batch()`. -#' The context available is [bbotk::ContextOptimization]. #' @param on_result (`function()`)\cr #' Stage called after result are written. #' Called in `OptimInstance$assign_result()`. -#' The context available is [bbotk::ContextOptimization]. #' @param on_optimization_end (`function()`)\cr #' Stage called at the end of the optimization. #' Called in `Optimizer$optimize()`. -#' The context available is [bbotk::ContextOptimization]. #' #' @export -#' @inherit CallbackFSelect examples -callback_fselect = function(id, label = NA_character_, man = NA_character_, on_optimization_begin = NULL, on_optimizer_before_eval = NULL, on_eval_after_design = NULL, on_eval_after_benchmark = NULL, on_eval_before_archive = NULL, on_optimizer_after_eval = NULL, on_result = NULL, on_optimization_end = NULL) { - stages = discard(set_names(list(on_optimization_begin, on_optimizer_before_eval, on_eval_after_design, on_eval_after_benchmark, on_eval_before_archive, on_optimizer_after_eval, on_result, on_optimization_end), c("on_optimization_begin", "on_optimizer_before_eval", "on_eval_after_design", "on_eval_after_benchmark", "on_eval_before_archive", "on_optimizer_after_eval", "on_result", "on_optimization_end")), is.null) +#' @inherit CallbackBatchFSelect examples +callback_batch_fselect = function( + id, + label = NA_character_, + man = NA_character_, + on_optimization_begin = NULL, + on_optimizer_before_eval = NULL, + on_eval_after_design = NULL, + on_eval_after_benchmark = NULL, + on_eval_before_archive = NULL, + on_optimizer_after_eval = NULL, + on_result = NULL, + on_optimization_end = NULL + ) { + stages = discard(set_names(list( + on_optimization_begin, + on_optimizer_before_eval, + on_eval_after_design, + on_eval_after_benchmark, + on_eval_before_archive, + on_optimizer_after_eval, + on_result, + on_optimization_end), + c( + "on_optimization_begin", + "on_optimizer_before_eval", + "on_eval_after_design", + "on_eval_after_benchmark", + "on_eval_before_archive", + "on_optimizer_after_eval", + "on_result", + "on_optimization_end")), is.null) walk(stages, function(stage) assert_function(stage, args = c("callback", "context"))) - callback = CallbackFSelect$new(id, label, man) + callback = CallbackBatchFSelect$new(id, label, man) iwalk(stages, function(stage, name) callback[[name]] = stage) callback } diff --git a/R/ContextEval.R b/R/ContextBatchFSelect.R similarity index 72% rename from R/ContextEval.R rename to R/ContextBatchFSelect.R index 7b69a414..bba0c7f7 100644 --- a/R/ContextEval.R +++ b/R/ContextBatchFSelect.R @@ -1,9 +1,9 @@ #' @title Evaluation Context #' #' @description -#' The [ContextEval] allows [CallbackFSelect]s to access and modify data while a batch of feature sets is evaluated. +#' The [ContextBatchFSelect] allows [CallbackBatchFSelect]s to access and modify data while a batch of feature sets is evaluated. #' See the section on active bindings for a list of modifiable objects. -#' See [callback_fselect()] for a list of stages that access [ContextEval]. +#' See [callback_batch_fselect()] for a list of stages that access [ContextBatchFSelect]. #' #' @details #' This context is re-created each time a new batch of feature sets is evaluated. @@ -12,24 +12,8 @@ #' Any number of columns can be added. #' #' @export -ContextEval = R6Class("ContextEval", - inherit = mlr3misc::Context, - public = list( - - #' @field objective_fselect [ObjectiveFSelect]. - objective_fselect = NULL, - - #' @description - #' Creates a new instance of this [R6][R6::R6Class] class. - #' - #' @param id (`character(1)`)\cr - #' Identifier for the new callback. - #' @param objective_fselect [ObjectiveFSelect]. - initialize = function(objective_fselect) { - self$objective_fselect = assert_r6(objective_fselect, "ObjectiveFSelect") - } - ), - +ContextBatchFSelect = R6Class("ContextBatchFSelect", + inherit = ContextBatch, active = list( #' @field xss (list())\cr #' The feature sets of the latest batch. diff --git a/R/FSelectInstanceMultiCrit.R b/R/FSelectInstanceBatchMultiCrit.R similarity index 79% rename from R/FSelectInstanceMultiCrit.R rename to R/FSelectInstanceBatchMultiCrit.R index cef44c1b..d4491071 100644 --- a/R/FSelectInstanceMultiCrit.R +++ b/R/FSelectInstanceBatchMultiCrit.R @@ -1,13 +1,13 @@ #' @title Class for Multi Criteria Feature Selection #' -#' @include FSelectInstanceSingleCrit.R ArchiveFSelect.R +#' @include FSelectInstanceBatchSingleCrit.R ArchiveBatchFSelect.R #' #' @description -#' The [FSelectInstanceMultiCrit] specifies a feature selection problem for [FSelectors][FSelector]. -#' The function [fsi()] creates a [FSelectInstanceMultiCrit] and the function [fselect()] creates an instance internally. +#' The [FSelectInstanceBatchMultiCrit] specifies a feature selection problem for a [FSelector]. +#' The function [fsi()] creates a [FSelectInstanceBatchMultiCrit] and the function [fselect()] creates an instance internally. #' -#' @inherit FSelectInstanceSingleCrit details -#' @inheritSection ArchiveFSelect Analysis +#' @inherit FSelectInstanceBatchSingleCrit details +#' @inheritSection ArchiveBatchFSelect Analysis #' #' @section Resources: #' There are several sections about feature selection in the [mlr3book](https://mlr3book.mlr-org.com). @@ -55,20 +55,20 @@ #' # Inspect all evaluated sets #' as.data.table(instance$archive) #' } -FSelectInstanceMultiCrit = R6Class("FSelectInstanceMultiCrit", - inherit = OptimInstanceMultiCrit, +FSelectInstanceBatchMultiCrit = R6Class("FSelectInstanceBatchMultiCrit", + inherit = OptimInstanceBatchMultiCrit, public = list( #' @description #' Creates a new instance of this [R6][R6::R6Class] class. - initialize = function(task, learner, resampling, measures, terminator, store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, callbacks = list()) { + initialize = function(task, learner, resampling, measures, terminator, store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, callbacks = NULL) { # initialized specialized fselect archive and objective - archive = ArchiveFSelect$new( + archive = ArchiveBatchFSelect$new( search_space = task_to_domain(assert_task(task)), codomain = measures_to_codomain(assert_measures(measures)), check_values = check_values) - objective = ObjectiveFSelect$new( + objective = ObjectiveFSelectBatch$new( task = task, learner = learner, resampling = resampling, @@ -98,14 +98,10 @@ FSelectInstanceMultiCrit = R6Class("FSelectInstanceMultiCrit", features = map(transpose_list(xdt), function(x) { self$objective$task$feature_names[as.logical(x)] }) - xdt[, features := list(features)] - xdt[, n_features := map(features, length)] - assert_data_table(xdt) - assert_names(names(xdt), must.include = self$search_space$ids()) - assert_data_table(ydt) - assert_names(names(ydt), permutation.of = self$objective$codomain$ids()) - private$.result = cbind(xdt, ydt) - call_back("on_result", self$callbacks, private$.context) + set(xdt, j = "features", value = list(features)) + set(xdt, j = "n_features", value = length(features[[1L]])) + super$assign_result(xdt, ydt) + set(private$.result, j = "x_domain", value = NULL) }, #' @description @@ -134,6 +130,14 @@ FSelectInstanceMultiCrit = R6Class("FSelectInstanceMultiCrit", unlist(x) }) } + ), + + private = list( + # initialize context for optimization + .initialize_context = function(optimizer) { + context = ContextBatchFSelect$new(self, optimizer) + self$objective$context = context + } ) ) diff --git a/R/FSelectInstanceSingleCrit.R b/R/FSelectInstanceBatchSingleCrit.R similarity index 85% rename from R/FSelectInstanceSingleCrit.R rename to R/FSelectInstanceBatchSingleCrit.R index dcdfdd09..0227d4b3 100644 --- a/R/FSelectInstanceSingleCrit.R +++ b/R/FSelectInstanceBatchSingleCrit.R @@ -1,17 +1,17 @@ #' @title Class for Single Criterion Feature Selection #' -#' @include ArchiveFSelect.R +#' @include ArchiveBatchFSelect.R #' #' @description -#' The [FSelectInstanceSingleCrit] specifies a feature selection problem for [FSelectors][FSelector]. -#' The function [fsi()] creates a [FSelectInstanceSingleCrit] and the function [fselect()] creates an instance internally. +#' The [FSelectInstanceBatchSingleCrit] specifies a feature selection problem for a [FSelector]. +#' The function [fsi()] creates a [FSelectInstanceBatchSingleCrit] and the function [fselect()] creates an instance internally. #' #' @description -#' The instance contains an [ObjectiveFSelect] object that encodes the black box objective function a [FSelector] has to optimize. +#' The instance contains an [ObjectiveFSelectBatch] object that encodes the black box objective function a [FSelector] has to optimize. #' The instance allows the basic operations of querying the objective at design points (`$eval_batch()`). #' This operation is usually done by the [FSelector]. #' Evaluations of feature subsets are performed in batches by calling [mlr3::benchmark()] internally. -#' The evaluated feature subsets are stored in the [Archive][ArchiveFSelect] (`$archive`). +#' The evaluated feature subsets are stored in the [Archive][ArchiveBatchFSelect] (`$archive`). #' Before a batch is evaluated, the [bbotk::Terminator] is queried for the remaining budget. #' If the available budget is exhausted, an exception is raised, and no further evaluations can be performed from this point on. #' The [FSelector] is also supposed to store its final result, consisting of a selected feature subset and associated estimated performance values, by calling the method `instance$assign_result()`. @@ -30,7 +30,7 @@ #' | `"regr_st"` | `"regr.mse"` | \CRANpkg{mlr3spatial} | #' | `"clust"` | `"clust.dunn"` | \CRANpkg{mlr3cluster} | #' -#' @inheritSection ArchiveFSelect Analysis +#' @inheritSection ArchiveBatchFSelect Analysis #' #' @section Resources: #' There are several sections about feature selection in the [mlr3book](https://mlr3book.mlr-org.com). @@ -88,8 +88,8 @@ #' # Inspect all evaluated sets #' as.data.table(instance$archive) #' } -FSelectInstanceSingleCrit = R6Class("FSelectInstanceSingleCrit", - inherit = OptimInstanceSingleCrit, +FSelectInstanceBatchSingleCrit = R6Class("FSelectInstanceBatchSingleCrit", + inherit = OptimInstanceBatchSingleCrit, public = list( #' @description @@ -103,17 +103,17 @@ FSelectInstanceSingleCrit = R6Class("FSelectInstanceSingleCrit", store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { # initialized specialized fselect archive and objective - archive = ArchiveFSelect$new( + archive = ArchiveBatchFSelect$new( search_space = task_to_domain(assert_task(task)), codomain = measures_to_codomain(assert_measure(measure)), check_values = check_values, ties_method = ties_method) - objective = ObjectiveFSelect$new( + objective = ObjectiveFSelectBatch$new( task = task, learner = learner, resampling = resampling, @@ -142,14 +142,10 @@ FSelectInstanceSingleCrit = R6Class("FSelectInstanceSingleCrit", # Add feature names to result for easy task subsetting feature_names = self$objective$task$feature_names features = list(feature_names[as.logical(xdt[, feature_names, with = FALSE])]) - xdt[, features := list(features)] - xdt[, n_features := length(features[[1L]])] - assert_data_table(xdt, nrows = 1L) - assert_names(names(xdt), must.include = self$search_space$ids()) - assert_number(y) - assert_names(names(y), permutation.of = self$objective$codomain$ids()) - private$.result = cbind(xdt, t(y)) # t(y) so the name of y stays - call_back("on_result", self$callbacks, private$.context) + set(xdt, j = "features", value = list(features)) + set(xdt, j = "n_features", value = length(features[[1L]])) + super$assign_result(xdt, y) + set(private$.result, j = "x_domain", value = NULL) }, #' @description @@ -176,6 +172,14 @@ FSelectInstanceSingleCrit = R6Class("FSelectInstanceSingleCrit", result_feature_set = function() { unlist(self$result$features) } + ), + + private = list( + # initialize context for optimization + .initialize_context = function(optimizer) { + context = ContextBatchFSelect$new(self, optimizer) + self$objective$context = context + } ) ) diff --git a/R/FSelector.R b/R/FSelector.R index 01b6551c..81ec89e5 100644 --- a/R/FSelector.R +++ b/R/FSelector.R @@ -1,32 +1,12 @@ -#' @title Class for Feature Selection Algorithms +#' @title FSelector #' #' @include mlr_fselectors.R #' #' @description -#' The [FSelector] implements the optimization algorithm. +#' The `FSelector`` implements the optimization algorithm. #' #' @details -#' [FSelector] is an abstract base class that implements the base functionality each fselector must provide. -#' A subclass is implemented in the following way: -#' * Inherit from FSelector. -#' * Specify the private abstract method `$.optimize()` and use it to call into your optimizer. -#' * You need to call `instance$eval_batch()` to evaluate design points. -#' * The batch evaluation is requested at the [FSelectInstanceSingleCrit]/[FSelectInstanceMultiCrit] object `instance`, so each batch is possibly executed in parallel via [mlr3::benchmark()], and all evaluations are stored inside of `instance$archive`. -#' * Before the batch evaluation, the [bbotk::Terminator] is checked, and if it is positive, an exception of class `"terminated_error"` is generated. -#' In the latter case the current batch of evaluations is still stored in `instance`, but the numeric scores are not sent back to the handling optimizer as it has lost execution control. -#' * After such an exception was caught we select the best set from `instance$archive` and return it. -#' * Note that therefore more points than specified by the [bbotk::Terminator] may be evaluated, as the Terminator is only checked before a batch evaluation, and not in-between evaluation in a batch. -#' How many more depends on the setting of the batch size. -#' * Overwrite the private super-method `.assign_result()` if you want to decide how to estimate the final set in the instance and its estimated performance. -#' The default behavior is: We pick the best resample experiment, regarding the given measure, then assign its set and aggregated performance to the instance. -#' -#' @section Private Methods: -#' * `.optimize(instance)` -> `NULL`\cr -#' Abstract base method. Implement to specify feature selection of your subclass. -#' See technical details sections. -#' * `.assign_result(instance)` -> `NULL`\cr -#' Abstract base method. Implement to specify how the final feature subset is selected. -#' See technical details sections. +#' `FSelector` is an abstract base class that implements the base functionality each fselector must provide. #' #' @section Resources: #' There are several sections about feature selection in the [mlr3book](https://mlr3book.mlr-org.com). @@ -38,38 +18,32 @@ #' * Utilize the built-in feature importance of models with [Recursive Feature Elimination](https://mlr-org.com/gallery/optimization/2023-02-07-recursive-feature-elimination/). #' * Run a feature selection with [Shadow Variable Search](https://mlr-org.com/gallery/optimization/2023-02-01-shadow-variable-search/). #' +#' @family FSelector +#' @template field_id +#' +#' @template param_id +#' @template param_param_set +#' @template param_properties +#' @template param_packages +#' @template param_label #' @template param_man #' #' @export FSelector = R6Class("FSelector", public = list( - #' @field id (`character(1)`)\cr - #' Identifier of the object. - #' Used in tables, plot and text output. id = NULL, #' @description #' Creates a new instance of this [R6][R6::R6Class] class. - #' - #' @param id (`character(1)`)\cr - #' Identifier for the new instance. - #' - #' @param param_set [paradox::ParamSet]\cr - #' Set of control parameters. - #' - #' @param properties (`character()`)\cr - #' Set of properties of the fselector. - #' Must be a subset of [`mlr_reflections$fselect_properties`][mlr3::mlr_reflections]. - #' - #' @param packages (`character()`)\cr - #' Set of required packages. - #' Note that these packages will be loaded via [requireNamespace()], and are not attached. - #' - #' @param label (`character(1)`)\cr - #' Label for this object. - #' Can be used in tables, plot and text output instead of the ID. - initialize = function(id = "fselector", param_set, properties, packages = character(), label = NA_character_, man = NA_character_) { + initialize = function( + id = "fselector", + param_set, + 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) private$.properties = assert_subset(properties, bbotk_reflections$optimizer_properties, empty.ok = FALSE) @@ -100,35 +74,10 @@ FSelector = R6Class("FSelector", catf(str_indent("* Packages:", self$packages)) }, - #' @description #' Opens the corresponding help page referenced by field `$man`. help = function() { open_help(self$man) - }, - - #' @description - #' Performs the feature selection on a [FSelectInstanceSingleCrit] or [FSelectInstanceMultiCrit] until termination. - #' The single evaluations will be written into the [ArchiveFSelect] that resides in the [FSelectInstanceSingleCrit] / [FSelectInstanceMultiCrit]. - #' The result will be written into the instance object. - #' - #' @param inst ([FSelectInstanceSingleCrit] | [FSelectInstanceMultiCrit]). - #' - #' @return [data.table::data.table()]. - optimize = function(inst) { - assert_multi_class(inst, c("FSelectInstanceSingleCrit", "FSelectInstanceMultiCrit")) - - inst$.__enclos_env__$private$.context = ContextOptimization$new(instance = inst, optimizer = self) - call_back("on_optimization_begin", inst$callbacks, get_private(inst)$.context) - - if ("requires_model" %in% self$properties) inst$objective$.__enclos_env__$private$.model_required = TRUE - - result = optimize_default(inst, self, private) - - if (!inst$objective$store_models) inst$archive$benchmark_result$discard(models = TRUE) - - call_back("on_optimization_end", inst$callbacks, get_private(inst)$.context) - result } ), @@ -188,7 +137,7 @@ FSelector = R6Class("FSelector", .optimize = function(inst) stop("abstract"), .assign_result = function(inst) { - assert_multi_class(inst, c("FSelectInstanceSingleCrit", "FSelectInstanceMultiCrit")) + assert_fselect_instance(inst) assign_result_default(inst) }, diff --git a/R/FSelectorBatch.R b/R/FSelectorBatch.R new file mode 100644 index 00000000..2031fdab --- /dev/null +++ b/R/FSelectorBatch.R @@ -0,0 +1,79 @@ +#' @title Class for Batch Feature Selection Algorithms +#' +#' @include mlr_fselectors.R +#' +#' @description +#' The [FSelectorBatch] implements the optimization algorithm. +#' +#' @details +#' [FSelectorBatch] is an abstract base class that implements the base functionality each fselector must provide. +#' A subclass is implemented in the following way: +#' * Inherit from FSelectorBatch. +#' * Specify the private abstract method `$.optimize()` and use it to call into your optimizer. +#' * You need to call `instance$eval_batch()` to evaluate design points. +#' * The batch evaluation is requested at the [FSelectInstanceBatchSingleCrit]/[FSelectInstanceBatchMultiCrit] object `instance`, so each batch is possibly executed in parallel via [mlr3::benchmark()], and all evaluations are stored inside of `instance$archive`. +#' * Before the batch evaluation, the [bbotk::Terminator] is checked, and if it is positive, an exception of class `"terminated_error"` is generated. +#' In the latter case the current batch of evaluations is still stored in `instance`, but the numeric scores are not sent back to the handling optimizer as it has lost execution control. +#' * After such an exception was caught we select the best set from `instance$archive` and return it. +#' * Note that therefore more points than specified by the [bbotk::Terminator] may be evaluated, as the Terminator is only checked before a batch evaluation, and not in-between evaluation in a batch. +#' How many more depends on the setting of the batch size. +#' * Overwrite the private super-method `.assign_result()` if you want to decide how to estimate the final set in the instance and its estimated performance. +#' The default behavior is: We pick the best resample experiment, regarding the given measure, then assign its set and aggregated performance to the instance. +#' +#' @section Private Methods: +#' * `.optimize(instance)` -> `NULL`\cr +#' Abstract base method. Implement to specify feature selection of your subclass. +#' See technical details sections. +#' * `.assign_result(instance)` -> `NULL`\cr +#' Abstract base method. Implement to specify how the final feature subset is selected. +#' See technical details sections. +#' +#' @inheritSection FSelector Resources +#' +#' @template param_id +#' @template param_param_set +#' @template param_properties +#' @template param_packages +#' @template param_label +#' @template param_man +#' +#' @export +FSelectorBatch = R6Class("FSelectorBatch", + inherit = FSelector, + public = list( + + #' @description + #' Creates a new instance of this [R6][R6::R6Class] class. + initialize = function( + id = "fselector_batch", + param_set, + properties, + packages = character(), + label = NA_character_, + man = NA_character_ + ) { + super$initialize( + id = id, + param_set = param_set, + properties = properties, + packages = packages, + label = label, + man = man + ) + }, + + #' @description + #' Performs the feature selection on a [FSelectInstanceBatchSingleCrit] or [FSelectInstanceBatchMultiCrit] until termination. + #' The single evaluations will be written into the [ArchiveBatchFSelect] that resides in the [FSelectInstanceBatchSingleCrit] / [FSelectInstanceBatchMultiCrit]. + #' The result will be written into the instance object. + #' + #' @param inst ([FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit]). + #' + #' @return [data.table::data.table()]. + optimize = function(inst) { + assert_fselect_instance_batch(inst) + if ("requires_model" %in% self$properties) inst$objective$.__enclos_env__$private$.model_required = TRUE + optimize_batch_default(inst, self) + } + ) +) diff --git a/R/FSelectorDesignPoints.R b/R/FSelectorBatchDesignPoints.R similarity index 86% rename from R/FSelectorDesignPoints.R rename to R/FSelectorBatchDesignPoints.R index 85d9e7e7..a1a060a1 100644 --- a/R/FSelectorDesignPoints.R +++ b/R/FSelectorBatchDesignPoints.R @@ -15,7 +15,7 @@ #' @templateVar id design_points #' @template section_dictionary_fselectors #' -#' @inheritSection bbotk::OptimizerDesignPoints Parameters +#' @inheritSection bbotk::OptimizerBatchDesignPoints Parameters #' #' @family FSelector #' @export @@ -55,19 +55,19 @@ #' task$select(instance$result_feature_set) #' learner$train(task) #' } -FSelectorDesignPoints = R6Class("FSelectorDesignPoints", - inherit = FSelectorFromOptimizer, +FSelectorBatchDesignPoints = R6Class("FSelectorBatchDesignPoints", + inherit = FSelectorBatchFromOptimizerBatch, public = list( #' @description #' Creates a new instance of this [R6][R6::R6Class] class. initialize = function() { super$initialize( - optimizer = OptimizerDesignPoints$new(), + optimizer = OptimizerBatchDesignPoints$new(), man = "mlr3fselect::mlr_fselectors_design_points" ) } ) ) -mlr_fselectors$add("design_points", FSelectorDesignPoints) +mlr_fselectors$add("design_points", FSelectorBatchDesignPoints) diff --git a/R/FSelectorExhaustiveSearch.R b/R/FSelectorBatchExhaustiveSearch.R similarity index 91% rename from R/FSelectorExhaustiveSearch.R rename to R/FSelectorBatchExhaustiveSearch.R index add13cd1..8bbc7790 100644 --- a/R/FSelectorExhaustiveSearch.R +++ b/R/FSelectorBatchExhaustiveSearch.R @@ -24,8 +24,8 @@ #' @family FSelector #' @export #' @template example -FSelectorExhaustiveSearch = R6Class("FSelectorExhaustiveSearch", - inherit = FSelector, +FSelectorBatchExhaustiveSearch = R6Class("FSelectorBatchExhaustiveSearch", + inherit = FSelectorBatch, public = list( #' @description @@ -66,4 +66,4 @@ FSelectorExhaustiveSearch = R6Class("FSelectorExhaustiveSearch", ) ) -mlr_fselectors$add("exhaustive_search", FSelectorExhaustiveSearch) +mlr_fselectors$add("exhaustive_search", FSelectorBatchExhaustiveSearch) diff --git a/R/FSelectorFromOptimizer.R b/R/FSelectorBatchFromOptimizerBatch.R similarity index 74% rename from R/FSelectorFromOptimizer.R rename to R/FSelectorBatchFromOptimizerBatch.R index 2aac8082..cdd16374 100644 --- a/R/FSelectorFromOptimizer.R +++ b/R/FSelectorBatchFromOptimizerBatch.R @@ -1,4 +1,4 @@ -#' @title FSelectorFromOptimizer +#' @title FSelectorBatchFromOptimizerBatch #' #' @description #' Internally used to transform [bbotk::Optimizer] to [FSelector]. @@ -7,8 +7,8 @@ #' #' @keywords internal #' @export -FSelectorFromOptimizer = R6Class("FSelectorFromOptimizer", - inherit = FSelector, +FSelectorBatchFromOptimizerBatch= R6Class("FSelectorBatchFromOptimizerBatch", + inherit = FSelectorBatch, public = list( #' @description @@ -32,17 +32,17 @@ FSelectorFromOptimizer = R6Class("FSelectorFromOptimizer", }, #' @description - #' Performs the feature selection on a [FSelectInstanceSingleCrit] / - #' [FSelectInstanceMultiCrit] until termination. + #' Performs the feature selection on a [FSelectInstanceBatchSingleCrit] / + #' [FSelectInstanceBatchMultiCrit] until termination. #' - #' @param inst ([FSelectInstanceSingleCrit] | [FSelectInstanceMultiCrit]). + #' @param inst ([FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit]). #' #' @return [data.table::data.table]. optimize = function(inst) { # We check for both classes since there is no FSelectInstance super # class anymore and OptimInstance would not ensure that we are in the # scope of mlr3fselect - assert_multi_class(inst, c("FSelectInstanceSingleCrit", "FSelectInstanceMultiCrit")) + assert_fselect_instance_batch(inst) private$.optimizer$optimize(inst) } ), diff --git a/R/FSelectorGeneticSearch.R b/R/FSelectorBatchGeneticSearch.R similarity index 91% rename from R/FSelectorGeneticSearch.R rename to R/FSelectorBatchGeneticSearch.R index e7ae6f5c..4b73cd3f 100644 --- a/R/FSelectorGeneticSearch.R +++ b/R/FSelectorBatchGeneticSearch.R @@ -18,8 +18,8 @@ #' @family FSelector #' @export #' @template example -FSelectorGeneticSearch = R6Class("FSelectorGeneticSearch", - inherit = FSelector, +FSelectorBatchGeneticSearch = R6Class("FSelectorBatchGeneticSearch", + inherit = FSelectorBatch, public = list( #' @description @@ -57,4 +57,4 @@ FSelectorGeneticSearch = R6Class("FSelectorGeneticSearch", ) ) -mlr_fselectors$add("genetic_search", FSelectorGeneticSearch) +mlr_fselectors$add("genetic_search", FSelectorBatchGeneticSearch) diff --git a/R/FSelectorRFE.R b/R/FSelectorBatchRFE.R similarity index 97% rename from R/FSelectorRFE.R rename to R/FSelectorBatchRFE.R index 138e1b33..acc8dcba 100644 --- a/R/FSelectorRFE.R +++ b/R/FSelectorBatchRFE.R @@ -24,7 +24,7 @@ #' Averaging the scores is not appropriate for most importance measures. #' #' @section Archive: -#' The [ArchiveFSelect] holds the following additional columns: +#' The [ArchiveBatchFSelect] holds the following additional columns: #' * `"importance"` (`numeric()`)\cr #' The importance score vector of the feature subset. #' @@ -91,8 +91,8 @@ #' task$select(instance$result_feature_set) #' learner$train(task) #' } -FSelectorRFE = R6Class("FSelectorRFE", - inherit = FSelector, +FSelectorBatchRFE = R6Class("FSelectorBatchRFE", + inherit = FSelectorBatch, public = list( #' @description @@ -153,7 +153,7 @@ FSelectorRFE = R6Class("FSelectorRFE", }, .assign_result = function(inst) { - assert_class(inst, "FSelectInstanceSingleCrit") + assert_class(inst, "FSelectInstanceBatchSingleCrit") res = inst$archive$best() xdt = res[, c(inst$search_space$ids(), "importance"), with = FALSE] @@ -271,4 +271,4 @@ rfe_workhorse = function(inst, subsets, recursive, aggregation = raw_importance, if (!inst$objective$store_models) inst$archive$benchmark_result$discard(models = TRUE) } -mlr_fselectors$add("rfe", FSelectorRFE) +mlr_fselectors$add("rfe", FSelectorBatchRFE) diff --git a/R/FSelectorRFECV.R b/R/FSelectorBatchRFECV.R similarity index 94% rename from R/FSelectorRFECV.R rename to R/FSelectorBatchRFECV.R index 33b73e59..7f2b3f3c 100644 --- a/R/FSelectorRFECV.R +++ b/R/FSelectorBatchRFECV.R @@ -1,11 +1,11 @@ #' @title Feature Selection with Recursive Feature Elimination with Cross Validation #' -#' @include mlr_fselectors.R FSelectorRFE.R +#' @include mlr_fselectors.R FSelectorBatchRFE.R #' @name mlr_fselectors_rfecv #' #' @description #' Feature selection using the Recursive Feature Elimination with Cross-Validation (RFE-CV) algorithm. -#' See [FSelectorRFE] for a description of the base algorithm. +#' See [FSelectorBatchRFE] for a description of the base algorithm. #' RFE-CV runs a recursive feature elimination in each iteration of a cross-validation to determine the optimal number of features. #' Then a recursive feature elimination is run again on the complete dataset with the optimal number of features as the final feature set size. #' The performance of the optimal feature set is calculated on the complete data set and should not be reported as the performance of the final model. @@ -22,7 +22,7 @@ #' It is not necessary to set a termination criterion. #' #' @section Archive: -#' The [ArchiveFSelect] holds the following additional columns: +#' The [ArchiveBatchFSelect] holds the following additional columns: #' * `"iteration"` (`integer(1)`)\cr #' The resampling iteration in which the feature subset was evaluated. #' * `"importance"` (`numeric()`)\cr @@ -85,8 +85,8 @@ #' task$select(instance$result_feature_set) #' learner$train(task) #' } -FSelectorRFECV = R6Class("FSelectorRFECV", - inherit = FSelector, +FSelectorBatchRFECV = R6Class("FSelectorBatchRFECV", + inherit = FSelectorBatch, public = list( #' @description @@ -167,7 +167,7 @@ FSelectorRFECV = R6Class("FSelectorRFECV", .assign_result = function(inst) { - assert_multi_class(inst, c("FSelectInstanceSingleCrit", "FSelectInstanceMultiCrit")) + assert_multi_class(inst, c("FSelectInstanceBatchSingleCrit", "FSelectInstanceBatchMultiCrit")) xdt = inst$archive$data[inst$archive$n_evals, inst$search_space$ids(), with = FALSE] y = unlist(inst$archive$data[inst$archive$n_evals, inst$archive$cols_y, with = FALSE]) @@ -177,4 +177,4 @@ FSelectorRFECV = R6Class("FSelectorRFECV", ) ) -mlr_fselectors$add("rfecv", FSelectorRFECV) +mlr_fselectors$add("rfecv", FSelectorBatchRFECV) diff --git a/R/FSelectorRandomSearch.R b/R/FSelectorBatchRandomSearch.R similarity index 94% rename from R/FSelectorRandomSearch.R rename to R/FSelectorBatchRandomSearch.R index 8a0c65b9..6143e13e 100644 --- a/R/FSelectorRandomSearch.R +++ b/R/FSelectorBatchRandomSearch.R @@ -56,8 +56,8 @@ #' task$select(instance$result_feature_set) #' learner$train(task) #' } -FSelectorRandomSearch = R6Class("FSelectorRandomSearch", - inherit = FSelector, +FSelectorBatchRandomSearch = R6Class("FSelectorBatchRandomSearch", + inherit = FSelectorBatch, public = list( #' @description @@ -98,4 +98,4 @@ FSelectorRandomSearch = R6Class("FSelectorRandomSearch", ) ) -mlr_fselectors$add("random_search", FSelectorRandomSearch) +mlr_fselectors$add("random_search", FSelectorBatchRandomSearch) diff --git a/R/FSelectorSequential.R b/R/FSelectorBatchSequential.R similarity index 93% rename from R/FSelectorSequential.R rename to R/FSelectorBatchSequential.R index 132db32b..db508717 100644 --- a/R/FSelectorSequential.R +++ b/R/FSelectorBatchSequential.R @@ -29,8 +29,8 @@ #' @family FSelector #' @export #' @template example -FSelectorSequential = R6Class("FSelectorSequential", - inherit = FSelector, +FSelectorBatchSequential = R6Class("FSelectorBatchSequential", + inherit = FSelectorBatch, public = list( #' @description @@ -55,8 +55,8 @@ FSelectorSequential = R6Class("FSelectorSequential", #' @description #' Returns the optimization path. #' - #' @param inst ([FSelectInstanceSingleCrit])\cr - #' Instance optimized with [FSelectorSequential]. + #' @param inst ([FSelectInstanceBatchSingleCrit])\cr + #' Instance optimized with [FSelectorBatchSequential]. #' @param include_uhash (`logical(1)`)\cr #' Include `uhash` column? #' @@ -118,4 +118,4 @@ FSelectorSequential = R6Class("FSelectorSequential", ) ) -mlr_fselectors$add("sequential", FSelectorSequential) +mlr_fselectors$add("sequential", FSelectorBatchSequential) diff --git a/R/FSelectorShadowVariableSearch.R b/R/FSelectorBatchShadowVariableSearch.R similarity index 93% rename from R/FSelectorShadowVariableSearch.R rename to R/FSelectorBatchShadowVariableSearch.R index 46ffe1bf..a10392eb 100644 --- a/R/FSelectorShadowVariableSearch.R +++ b/R/FSelectorBatchShadowVariableSearch.R @@ -51,8 +51,8 @@ #' task$select(instance$result_feature_set) #' learner$train(task) #' } -FSelectorShadowVariableSearch = R6Class("FSelectorShadowVariableSearch", - inherit = FSelector, +FSelectorBatchShadowVariableSearch = R6Class("FSelectorBatchShadowVariableSearch", + inherit = FSelectorBatch, public = list( #' @description @@ -70,8 +70,8 @@ FSelectorShadowVariableSearch = R6Class("FSelectorShadowVariableSearch", #' @description #' Returns the optimization path. #' - #' @param inst ([FSelectInstanceSingleCrit])\cr - #' Instance optimized with [FSelectorShadowVariableSearch]. + #' @param inst ([FSelectInstanceBatchSingleCrit])\cr + #' Instance optimized with [FSelectorBatchShadowVariableSearch]. #' #' @return [data.table::data.table] optimization_path = function(inst) { @@ -162,4 +162,4 @@ FSelectorShadowVariableSearch = R6Class("FSelectorShadowVariableSearch", ) ) -mlr_fselectors$add("shadow_variable_search", FSelectorShadowVariableSearch) +mlr_fselectors$add("shadow_variable_search", FSelectorBatchShadowVariableSearch) diff --git a/R/ObjectiveFSelect.R b/R/ObjectiveFSelect.R index 52bfabc8..f99f6cc9 100644 --- a/R/ObjectiveFSelect.R +++ b/R/ObjectiveFSelect.R @@ -2,7 +2,7 @@ #' #' @description #' Stores the objective function that estimates the performance of feature subsets. -#' This class is usually constructed internally by the [FSelectInstanceSingleCrit] / [FSelectInstanceMultiCrit]. +#' This class is usually constructed internally by the [FSelectInstanceBatchSingleCrit] / [FSelectInstanceBatchMultiCrit]. #' #' @template param_task #' @template param_learner @@ -36,35 +36,35 @@ ObjectiveFSelect = R6Class("ObjectiveFSelect", #' @field store_benchmark_result (`logical(1)`). store_benchmark_result = NULL, - #' @field archive ([ArchiveFSelect]). - archive = NULL, - - #' @field callbacks (List of [CallbackFSelect]s). + #' @field callbacks (List of [CallbackBatchFSelect]s). callbacks = NULL, #' @description #' Creates a new instance of this [R6][R6::R6Class] class. - #' - #' @param archive ([ArchiveFSelect])\cr - #' Reference to the archive of [FSelectInstanceSingleCrit] | [FSelectInstanceMultiCrit]. - #' If `NULL` (default), benchmark result and models cannot be stored. - initialize = function(task, learner, resampling, measures, check_values = TRUE, store_benchmark_result = TRUE, store_models = FALSE, archive = NULL, callbacks = list()) { + initialize = function( + task, + learner, + resampling, + measures, + check_values = TRUE, + store_benchmark_result = TRUE, + store_models = FALSE, + callbacks = NULL + ) { self$task = assert_task(as_task(task, clone = TRUE)) self$learner = assert_learner(as_learner(learner, clone = TRUE), task = self$task) self$measures = assert_measures(as_measures(measures, clone = TRUE), task = self$task, learner = self$learner) - - self$archive = assert_r6(archive, "ArchiveFSelect", null.ok = TRUE) - if (is.null(self$archive)) store_benchmark_result = store_models = FALSE self$store_models = assert_flag(store_models) self$store_benchmark_result = assert_flag(store_benchmark_result) || self$store_models self$callbacks = assert_callbacks(as_callbacks(callbacks)) super$initialize( id = sprintf("%s_on_%s", self$learner$id, self$task$id), + properties = "noisy", domain = task_to_domain(self$task), codomain = measures_to_codomain(self$measures), - check_values = check_values, - constants = ps(resampling = p_uty())) + constants = ps(resampling = p_uty()), + check_values = check_values) # set resamplings in constants resampling = assert_resampling(as_resampling(resampling, clone = TRUE)) @@ -72,51 +72,5 @@ ObjectiveFSelect = R6Class("ObjectiveFSelect", self$resampling = resampling self$constants$values$resampling = list(resampling) } - ), - - private = list( - .eval_many = function(xss, resampling) { - context = ContextEval$new(self) - private$.xss = xss - - tasks = map(private$.xss, function(x) { - state = self$task$feature_names[unlist(x)] - task = self$task$clone() - always_included = task$col_roles$always_included - task$set_col_roles(always_included, "feature") - task$select(c(state, always_included)) - task - }) - - # benchmark feature subsets - private$.design = data.table(task = tasks, learner = list(self$learner), resampling = resampling) - call_back("on_eval_after_design", self$callbacks, context) - - # learner is already cloned, task is internally cloned by PipeOpSelect, and resampling is not changed - private$.benchmark_result = benchmark(private$.design, store_models = self$store_models || private$.model_required, clone = character()) - call_back("on_eval_after_benchmark", self$callbacks, context) - - # aggregate performance scores - private$.aggregated_performance = private$.benchmark_result$aggregate(self$measures, conditions = TRUE)[, c(self$codomain$target_ids, "warnings", "errors"), with = FALSE] - - # add runtime to evaluations - time = map_dbl(private$.benchmark_result$resample_results$resample_result, function(rr) { - sum(map_dbl(get_private(rr)$.data$learner_states(get_private(rr)$.view), function(state) state$train_time + state$predict_time)) - }) - set(private$.aggregated_performance, j = "runtime_learners", value = time) - - # store benchmark result in archive - if (self$store_benchmark_result) { - self$archive$benchmark_result$combine(private$.benchmark_result) - set(private$.aggregated_performance, j = "uhash", value = private$.benchmark_result$uhashes) - } - private$.aggregated_performance - }, - - .xss = NULL, - .design = NULL, - .benchmark_result = NULL, - .aggregated_performance = NULL, - .model_required = FALSE ) ) diff --git a/R/ObjectiveFSelectBatch.R b/R/ObjectiveFSelectBatch.R new file mode 100644 index 00000000..61a95c34 --- /dev/null +++ b/R/ObjectiveFSelectBatch.R @@ -0,0 +1,101 @@ +#' @title Class for Feature Selection Objective +#' +#' @description +#' Stores the objective function that estimates the performance of feature subsets. +#' This class is usually constructed internally by the [FSelectInstanceBatchSingleCrit] / [FSelectInstanceBatchMultiCrit]. +#' +#' @template param_task +#' @template param_learner +#' @template param_resampling +#' @template param_measures +#' @template param_store_models +#' @template param_check_values +#' @template param_store_benchmark_result +#' @template param_callbacks +#' +#' @export +ObjectiveFSelectBatch = R6Class("ObjectiveFSelectBatch", + inherit = ObjectiveFSelect, + public = list( + + #' @field archive ([ArchiveBatchFSelect]). + archive = NULL, + + #' @description + #' Creates a new instance of this [R6][R6::R6Class] class. + #' + #' @param archive ([ArchiveBatchFSelect])\cr + #' Reference to the archive of [FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit]. + #' If `NULL` (default), benchmark result and models cannot be stored. + initialize = function( + task, + learner, + resampling, + measures, + check_values = TRUE, + store_benchmark_result = TRUE, + store_models = FALSE, + archive = NULL, + callbacks = NULL + ) { + self$archive = assert_r6(archive, "ArchiveBatchFSelect", null.ok = TRUE) + if (is.null(self$archive)) store_benchmark_result = store_models = FALSE + + super$initialize( + task = task, + learner = learner, + resampling = resampling, + measures = measures, + store_benchmark_result = store_benchmark_result, + store_models = store_models, + check_values = check_values, + callbacks = callbacks + ) + } + ), + + private = list( + .eval_many = function(xss, resampling) { + private$.xss = xss + + tasks = map(private$.xss, function(x) { + state = self$task$feature_names[unlist(x)] + task = self$task$clone() + always_included = task$col_roles$always_included + task$set_col_roles(always_included, "feature") + task$select(c(state, always_included)) + task + }) + + # benchmark feature subsets + private$.design = data.table(task = tasks, learner = list(self$learner), resampling = resampling) + call_back("on_eval_after_design", self$callbacks, self$context) + + # learner is already cloned, task is internally cloned by PipeOpSelect, and resampling is not changed + private$.benchmark_result = benchmark(private$.design, store_models = self$store_models || private$.model_required, clone = character()) + call_back("on_eval_after_benchmark", self$callbacks, self$context) + + # aggregate performance scores + private$.aggregated_performance = private$.benchmark_result$aggregate(self$measures, conditions = TRUE)[, c(self$codomain$target_ids, "warnings", "errors"), with = FALSE] + + # add runtime to evaluations + time = map_dbl(private$.benchmark_result$resample_results$resample_result, function(rr) { + sum(map_dbl(get_private(rr)$.data$learner_states(get_private(rr)$.view), function(state) state$train_time + state$predict_time)) + }) + set(private$.aggregated_performance, j = "runtime_learners", value = time) + + # store benchmark result in archive + if (self$store_benchmark_result) { + self$archive$benchmark_result$combine(private$.benchmark_result) + set(private$.aggregated_performance, j = "uhash", value = private$.benchmark_result$uhashes) + } + private$.aggregated_performance + }, + + .xss = NULL, + .design = NULL, + .benchmark_result = NULL, + .aggregated_performance = NULL, + .model_required = FALSE + ) +) diff --git a/R/assertions.R b/R/assertions.R index 3044c852..74de09f4 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -1,3 +1,63 @@ +#' @title Assertion for mlr3fselect objects +#' +#' @description +#' Most assertion functions ensure the right class attribute, and optionally additional properties. +#' +#' @name mlr3fselect_assertions +#' @keywords internal +NULL + assert_fselector = function(fselector) { assert_r6(fselector, "FSelector") } + +#' @export +#' @param fselectors (list of [FSelector]). +#' @rdname mlr3fselect_assertions +assert_fselectors = function(fselectors) { + invisible(lapply(fselectors, assert_fselector)) +} + +#' @export +#' @param fselector (`FSelectorAsync`). +#' @rdname mlr3fselect_assertions +assert_fselector_async = function(fselector) { + assert_r6(fselector, "FSelectorAsync") +} + +#' @export +#' @param fselector ([FSelectorBatch]). +#' @rdname mlr3fselect_assertions +assert_fselector_batch = function(fselector) { + assert_r6(fselector, "FSelectorBatch") +} + +#' @export +#' @param inst ([FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit] | `FSelectInstanceAsyncSingleCrit` | `FSelectInstanceAsyncMultiCrit`). +#' @rdname mlr3fselect_assertions +assert_fselect_instance = function(inst) { + assert_multi_class(inst, c( + "FSelectInstanceBatchSingleCrit", + "FSelectInstanceBatchMultiCrit", + "FSelectInstanceAsyncSingleCrit", + "FSelectInstanceAsyncMultiCrit")) +} + +#' @export +#' @param inst (`FSelectInstanceAsyncSingleCrit` | `FSelectInstanceAsyncMultiCrit`). +#' @rdname mlr3fselect_assertions +assert_fselect_instance_async = function(inst) { + assert_multi_class(inst, c( + "FSelectInstanceAsyncSingleCrit", + "FSelectInstanceAsyncMultiCrit")) +} + +#' @export +#' @param inst ([FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit]). +#' @rdname mlr3fselect_assertions +assert_fselect_instance_batch = function(inst) { + assert_multi_class(inst, c( + "FSelectInstanceBatchSingleCrit", + "FSelectInstanceBatchMultiCrit")) +} + diff --git a/R/auto_fselector.R b/R/auto_fselector.R index 918795ea..8a92d7be 100644 --- a/R/auto_fselector.R +++ b/R/auto_fselector.R @@ -35,7 +35,7 @@ auto_fselector = function( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { terminator = terminator %??% terminator_selection(term_evals, term_time) diff --git a/R/fselect.R b/R/fselect.R index ce2e8a0f..7b0f85a6 100644 --- a/R/fselect.R +++ b/R/fselect.R @@ -1,29 +1,29 @@ #' @title Function for Feature Selection #' -#' @include FSelectInstanceSingleCrit.R ArchiveFSelect.R +#' @include FSelectInstanceBatchSingleCrit.R ArchiveBatchFSelect.R #' #' @description #' Function to optimize the features of a [mlr3::Learner]. -#' The function internally creates a [FSelectInstanceSingleCrit] or [FSelectInstanceMultiCrit] which describes the feature selection problem. +#' The function internally creates a [FSelectInstanceBatchSingleCrit] or [FSelectInstanceBatchMultiCrit] which describes the feature selection problem. #' It executes the feature selection with the [FSelector] (`method`) and returns the result with the fselect instance (`$result`). -#' The [ArchiveFSelect] (`$archive`) stores all evaluated hyperparameter configurations and performance scores. +#' The [ArchiveBatchFSelect] (`$archive`) stores all evaluated hyperparameter configurations and performance scores. #' #' @details -#' The [mlr3::Task], [mlr3::Learner], [mlr3::Resampling], [mlr3::Measure] and [Terminator] are used to construct a [FSelectInstanceSingleCrit]. -#' If multiple performance [Measures][Measure] are supplied, a [FSelectInstanceMultiCrit] is created. +#' The [mlr3::Task], [mlr3::Learner], [mlr3::Resampling], [mlr3::Measure] and [Terminator] are used to construct a [FSelectInstanceBatchSingleCrit]. +#' If multiple performance [Measures][Measure] are supplied, a [FSelectInstanceBatchMultiCrit] is created. #' The parameter `term_evals` and `term_time` are shortcuts to create a [Terminator]. #' If both parameters are passed, a [TerminatorCombo] is constructed. #' For other [Terminators][Terminator], pass one with `terminator`. #' If no termination criterion is needed, set `term_evals`, `term_time` and `terminator` to `NULL`. #' -#' @inheritSection FSelectInstanceSingleCrit Resources -#' @inheritSection ArchiveFSelect Analysis +#' @inheritSection FSelectInstanceBatchSingleCrit Resources +#' @inheritSection ArchiveBatchFSelect Analysis #' #' @param measures ([mlr3::Measure] or list of [mlr3::Measure])\cr -#' A single measure creates a [FSelectInstanceSingleCrit] and multiple measures a [FSelectInstanceMultiCrit]. +#' A single measure creates a [FSelectInstanceBatchSingleCrit] and multiple measures a [FSelectInstanceBatchMultiCrit]. #' If `NULL`, default measure is used. #' -#' @return [FSelectInstanceSingleCrit] | [FSelectInstanceMultiCrit] +#' @return [FSelectInstanceBatchSingleCrit] | [FSelectInstanceBatchMultiCrit] #' #' @template param_fselector #' @template param_task @@ -73,14 +73,14 @@ fselect = function( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { assert_fselector(fselector) terminator = terminator %??% terminator_selection(term_evals, term_time) instance = if (!is.list(measures)) { - FSelectInstanceSingleCrit$new( + FSelectInstanceBatchSingleCrit$new( task = task, learner = learner, resampling = resampling, @@ -92,7 +92,7 @@ fselect = function( callbacks = callbacks, ties_method = ties_method) } else { - FSelectInstanceMultiCrit$new( + FSelectInstanceBatchMultiCrit$new( task = task, learner = learner, resampling = resampling, diff --git a/R/fselect_nested.R b/R/fselect_nested.R index c5588077..735754bd 100644 --- a/R/fselect_nested.R +++ b/R/fselect_nested.R @@ -55,7 +55,7 @@ fselect_nested = function( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { assert_task(task) diff --git a/R/mlr_callbacks.R b/R/mlr_callbacks.R index a937296f..99bad922 100644 --- a/R/mlr_callbacks.R +++ b/R/mlr_callbacks.R @@ -1,10 +1,10 @@ #' @title Backup Benchmark Result Callback #' -#' @include CallbackFSelect.R +#' @include CallbackBatchFSelect.R #' @name mlr3fselect.backup #' #' @description -#' This [CallbackFSelect] writes the [mlr3::BenchmarkResult] after each batch to disk. +#' This [CallbackBatchFSelect] writes the [mlr3::BenchmarkResult] after each batch to disk. #' #' @examples #' clbk("mlr3fselect.backup", path = "backup.rds") @@ -21,7 +21,7 @@ NULL load_callback_backup = function() { - callback_fselect("mlr3fselect.backup", + callback_batch_fselect("mlr3fselect.backup", label = "Backup Benchmark Result Callback", man = "mlr3fselect::mlr3fselect.backup", on_optimization_begin = function(callback, context) { @@ -38,7 +38,7 @@ load_callback_backup = function() { #' @title SVM-RFE Callback #' -#' @include CallbackFSelect.R +#' @include CallbackBatchFSelect.R #' @name mlr3fselect.svm_rfe #' #' @description @@ -71,7 +71,7 @@ load_callback_backup = function() { NULL load_callback_svm_rfe = function() { - callback_fselect("mlr3fselect.svm_rfe", + callback_batch_fselect("mlr3fselect.svm_rfe", label = "SVM-RFE Callback", man = "mlr3fselect::mlr3fselect.svm_rfe", on_optimization_begin = function(callback, context) { @@ -111,7 +111,7 @@ load_callback_svm_rfe = function() { #' @title One Standard Error Rule Callback #' -#' @include CallbackFSelect.R +#' @include CallbackBatchFSelect.R #' @name mlr3fselect.one_se_rule #' #' @description @@ -139,7 +139,7 @@ load_callback_svm_rfe = function() { NULL load_callback_one_se_rule = function() { - callback = callback_fselect("mlr3fselect.one_se_rule", + callback = callback_batch_fselect("mlr3fselect.one_se_rule", label = "One Standard Error Rule Callback", man = "mlr3fselect::mlr3fselect.one_se_rule", @@ -155,8 +155,7 @@ load_callback_one_se_rule = function() { # select smallest future set within one standard error of the best best_y = context$instance$result_y data = data[y > best_y - se & y < best_y + se, ][which.min(n_features)] - - context$instance$.__enclos_env__$private$.result = data[, names(context$instance$result), with = FALSE] + context$instance$.__enclos_env__$private$.result = data[, setdiff(names(context$instance$result), "x_domain"), with = FALSE] } ) } diff --git a/R/mlr_fselectors.R b/R/mlr_fselectors.R index 1cfe0a3b..9f2eda6b 100644 --- a/R/mlr_fselectors.R +++ b/R/mlr_fselectors.R @@ -25,7 +25,7 @@ #' #' @export #' @examples -#' as.data.table(mlr_fselectors) +#' as.data.table(mlr_fselectors)x #' mlr_fselectors$get("random_search") #' fs("random_search") mlr_fselectors = R6Class("DictionaryFSelector", diff --git a/R/sugar.R b/R/sugar.R index 72e36353..c1f97c00 100644 --- a/R/sugar.R +++ b/R/sugar.R @@ -5,7 +5,7 @@ #' Relies on [mlr3misc::dictionary_sugar_get()] to extract objects from the respective [mlr3misc::Dictionary]: #' #' * `fs()` for a [FSelector] from [mlr_fselectors]. -#' * `fss()` for a list of [FSelectors][FSelector] from [mlr_fselectors]. +#' * `fss()` for a list of a [FSelector] from [mlr_fselectors]. #' * `trm()` for a [Terminator] from [mlr_terminators]. #' * `trms()` for a list of [Terminators][Terminator] from [mlr_terminators]. #' @@ -32,10 +32,10 @@ fss = function(.keys, ...) { #' @title Syntactic Sugar for Instance Construction #' #' @description -#' Function to construct a [FSelectInstanceSingleCrit] or [FSelectInstanceMultiCrit]. +#' Function to construct a [FSelectInstanceBatchSingleCrit] or [FSelectInstanceBatchMultiCrit]. #' #' @param measures ([mlr3::Measure] or list of [mlr3::Measure])\cr -#' A single measure creates a [FSelectInstanceSingleCrit] and multiple measures a [FSelectInstanceMultiCrit]. +#' A single measure creates a [FSelectInstanceBatchSingleCrit] and multiple measures a [FSelectInstanceBatchMultiCrit]. #' If `NULL`, default measure is used. #' #' @template param_task @@ -48,11 +48,11 @@ fss = function(.keys, ...) { #' @template param_callbacks #' @template param_ties_method #' -#' @inheritSection FSelectInstanceSingleCrit Resources -#' @inheritSection FSelectInstanceSingleCrit Default Measures +#' @inheritSection FSelectInstanceBatchSingleCrit Resources +#' @inheritSection FSelectInstanceBatchSingleCrit Default Measures #' #' @export -#' @inherit FSelectInstanceSingleCrit examples +#' @inherit FSelectInstanceBatchSingleCrit examples fsi = function( task, learner, @@ -62,11 +62,11 @@ fsi = function( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) { if (!is.list(measures)) { - FSelectInstanceSingleCrit$new( + FSelectInstanceBatchSingleCrit$new( task = task, learner = learner, resampling = resampling, @@ -78,7 +78,7 @@ fsi = function( callbacks = callbacks, ties_method = ties_method) } else { - FSelectInstanceMultiCrit$new( + FSelectInstanceBatchMultiCrit$new( task = task, learner = learner, resampling = resampling, diff --git a/README.md b/README.md index 20b7009e..80ccc4f7 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ instance = fsi( instance ``` - ## + ## ## * State: Not optimized ## * Objective: ## * Terminator: @@ -116,7 +116,7 @@ fselector = fs("random_search", batch_size = 5) fselector ``` - ## : Random Search + ## : Random Search ## * Parameters: batch_size=5 ## * Properties: single-crit, multi-crit ## * Packages: mlr3fselect @@ -135,19 +135,19 @@ instance. instance$result_feature_set ``` - ## [1] "address" "addresses" "all" "business" - ## [5] "capitalAve" "capitalLong" "capitalTotal" "charDollar" - ## [9] "charExclamation" "charHash" "charRoundbracket" "charSemicolon" - ## [13] "charSquarebracket" "conference" "credit" "cs" - ## [17] "data" "direct" "edu" "email" - ## [21] "font" "free" "george" "hp" - ## [25] "internet" "lab" "labs" "mail" - ## [29] "make" "meeting" "money" "num000" - ## [33] "num1999" "num3d" "num415" "num650" - ## [37] "num85" "num857" "order" "our" - ## [41] "parts" "people" "pm" "project" - ## [45] "re" "receive" "remove" "report" - ## [49] "table" "technology" "telnet" "will" + ## [1] "address" "addresses" "all" "business" + ## [5] "capitalAve" "capitalLong" "capitalTotal" "charDollar" + ## [9] "charExclamation" "charHash" "charRoundbracket" "charSemicolon" + ## [13] "charSquarebracket" "conference" "credit" "cs" + ## [17] "data" "direct" "edu" "email" + ## [21] "font" "free" "george" "hp" + ## [25] "internet" "lab" "labs" "mail" + ## [29] "make" "meeting" "money" "num000" + ## [33] "num1999" "num3d" "num415" "num650" + ## [37] "num85" "num857" "order" "our" + ## [41] "parts" "people" "pm" "project" + ## [45] "re" "receive" "remove" "report" + ## [49] "table" "technology" "telnet" "will" ## [53] "you" "your" And the corresponding measured performance. @@ -156,7 +156,7 @@ And the corresponding measured performance. instance$result_y ``` - ## classif.ce + ## classif.ce ## 0.07042005 The archive contains all evaluated hyperparameter configurations. @@ -171,7 +171,7 @@ as.data.table(instance$archive) ## 3: TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE ## 4: TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## 5: FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE - ## --- + ## --- ## 16: FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE ## 17: FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE TRUE ## 18: FALSE FALSE TRUE TRUE FALSE FALSE FALSE TRUE FALSE diff --git a/inst/WORDLIST b/inst/WORDLIST index 19533116..1dadf1bc 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,20 +1,20 @@ -ArchiveFSelect +ArchiveBatchFSelect AutoFSelector BenchmarkResult Bengio Bergstra -CallbackFSelect -CallbackFSelects +CallbackBatchFSelect +CallbackBatchFSelects Codomain -ContextEval -ContextOptimization +ContextBatchFSelect +ContextBatch FSelect -FSelectInstanceMultiCrit -FSelectInstanceSingleCrit +FSelectInstanceBatchMultiCrit +FSelectInstanceBatchSingleCrit FSelector -FSelectorFromOptimizer -FSelectorSequential -FSelectorShadowVariableSearch +FSelectorBatchFromOptimizerBatch +FSelectorBatchSequential +FSelectorBatchShadowVariableSearch FSelectors Hepp Mattermost diff --git a/inst/testthat/helper_misc.R b/inst/testthat/helper_misc.R index bd522a8f..89aa032b 100644 --- a/inst/testthat/helper_misc.R +++ b/inst/testthat/helper_misc.R @@ -6,7 +6,7 @@ TEST_MAKE_TSK = function(n = 4L) { TEST_MAKE_INST_1D = function(n = 4L, folds = 2L, store_models = TRUE, store_benchmark_result = TRUE, measure = msr("dummy"), terminator = trm("evals", n_evals = 10)) { - FSelectInstanceSingleCrit$new( + FSelectInstanceBatchSingleCrit$new( task = TEST_MAKE_TSK(n), learner = lrn("regr.rpart"), resampling = rsmp("cv", folds = folds), @@ -17,7 +17,7 @@ TEST_MAKE_INST_1D = function(n = 4L, folds = 2L, store_models = TRUE, store_benc } TEST_MAKE_INST_2D = function(n = 4L, folds = 2L, store_models = FALSE, store_benchmark_result = TRUE) { - FSelectInstanceMultiCrit$new( + FSelectInstanceBatchMultiCrit$new( task = TEST_MAKE_TSK(n), learner = lrn("regr.rpart"), resampling = rsmp("cv", folds = folds), diff --git a/man-roxygen/field_id.R b/man-roxygen/field_id.R new file mode 100644 index 00000000..7f28fb59 --- /dev/null +++ b/man-roxygen/field_id.R @@ -0,0 +1,3 @@ +#' @field id (`character(1)`)\cr +#' Identifier of the object. +#' Used in tables, plot and text output. diff --git a/man-roxygen/param_callbacks.R b/man-roxygen/param_callbacks.R index 125107bd..ff3dce11 100644 --- a/man-roxygen/param_callbacks.R +++ b/man-roxygen/param_callbacks.R @@ -1,2 +1,2 @@ -#' @param callbacks (list of [CallbackFSelect])\cr +#' @param callbacks (list of [CallbackBatchFSelect])\cr #' List of callbacks. diff --git a/man-roxygen/param_id.R b/man-roxygen/param_id.R new file mode 100644 index 00000000..1f50f0ec --- /dev/null +++ b/man-roxygen/param_id.R @@ -0,0 +1,2 @@ +#' @param id (`character(1)`)\cr +#' Identifier for the new instance. diff --git a/man-roxygen/param_label.R b/man-roxygen/param_label.R new file mode 100644 index 00000000..1a73abff --- /dev/null +++ b/man-roxygen/param_label.R @@ -0,0 +1,3 @@ +#' @param label (`character(1)`)\cr +#' Label for this object. +#' Can be used in tables, plot and text output instead of the ID. diff --git a/man-roxygen/param_packages.R b/man-roxygen/param_packages.R new file mode 100644 index 00000000..8e95795b --- /dev/null +++ b/man-roxygen/param_packages.R @@ -0,0 +1,3 @@ +#' @param packages (`character()`)\cr +#' Set of required packages. +#' Note that these packages will be loaded via [requireNamespace()], and are not attached. diff --git a/man-roxygen/param_param_set.R b/man-roxygen/param_param_set.R new file mode 100644 index 00000000..26289d70 --- /dev/null +++ b/man-roxygen/param_param_set.R @@ -0,0 +1,2 @@ +#' @param param_set [paradox::ParamSet]\cr +#' Set of control parameters. diff --git a/man-roxygen/param_properties.R b/man-roxygen/param_properties.R new file mode 100644 index 00000000..d830f847 --- /dev/null +++ b/man-roxygen/param_properties.R @@ -0,0 +1,3 @@ +#' @param properties (`character()`)\cr +#' Set of properties of the fselector. +#' Must be a subset of [`mlr_reflections$fselect_properties`][mlr3::mlr_reflections]. diff --git a/man-roxygen/param_store_fselect_instance.R b/man-roxygen/param_store_fselect_instance.R index a6a569e8..2e6d284a 100644 --- a/man-roxygen/param_store_fselect_instance.R +++ b/man-roxygen/param_store_fselect_instance.R @@ -1,3 +1,3 @@ #' @param store_fselect_instance (`logical(1)`)\cr -#' If `TRUE` (default), stores the internally created [FSelectInstanceSingleCrit] with all intermediate results in slot `$fselect_instance`. +#' If `TRUE` (default), stores the internally created [FSelectInstanceBatchSingleCrit] with all intermediate results in slot `$fselect_instance`. #' Is set to `TRUE`, if `store_models = TRUE` diff --git a/man-roxygen/param_xdt.R b/man-roxygen/param_xdt.R index 087bfdae..d497a93b 100644 --- a/man-roxygen/param_xdt.R +++ b/man-roxygen/param_xdt.R @@ -1,4 +1,4 @@ #' @param xdt (`data.table::data.table()`)\cr #' x values as `data.table`. Each row is one point. Contains the value in -#' the *search space* of the [FSelectInstanceMultiCrit] object. Can contain +#' the *search space* of the [FSelectInstanceBatchMultiCrit] object. Can contain #' additional columns for extra information. diff --git a/man/ArchiveFSelect.Rd b/man/ArchiveBatchFSelect.Rd similarity index 67% rename from man/ArchiveFSelect.Rd rename to man/ArchiveBatchFSelect.Rd index b15739e0..ea417690 100644 --- a/man/ArchiveFSelect.Rd +++ b/man/ArchiveBatchFSelect.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ArchiveFSelect.R -\name{ArchiveFSelect} -\alias{ArchiveFSelect} +% Please edit documentation in R/ArchiveBatchFSelect.R +\name{ArchiveBatchFSelect} +\alias{ArchiveBatchFSelect} \title{Class for Logging Evaluated Feature Sets} \description{ -The \link{ArchiveFSelect} stores all evaluated feature sets and performance scores. +The \link{ArchiveBatchFSelect} stores all evaluated feature sets and performance scores. } \details{ -The \link{ArchiveFSelect} is a container around a \code{\link[data.table:data.table]{data.table::data.table()}}. +The \link{ArchiveBatchFSelect} is a container around a \code{\link[data.table:data.table]{data.table::data.table()}}. Each row corresponds to a single evaluation of a feature set. See the section on Data Structure for more information. The archive stores additionally a \link[mlr3:BenchmarkResult]{mlr3::BenchmarkResult} (\verb{$benchmark_result}) that records the resampling experiments. @@ -50,11 +50,11 @@ Alternatively, measures can be supplied to \code{as.data.table()}. \section{S3 Methods}{ \itemize{ -\item \code{as.data.table.ArchiveFSelect(x, exclude_columns = "uhash", measures = NULL)}\cr +\item \code{as.data.table.ArchiveBatchFSelect(x, exclude_columns = "uhash", measures = NULL)}\cr Returns a tabular view of all evaluated feature sets.\cr -\link{ArchiveFSelect} -> \code{\link[data.table:data.table]{data.table::data.table()}}\cr +\link{ArchiveBatchFSelect} -> \code{\link[data.table:data.table]{data.table::data.table()}}\cr \itemize{ -\item \code{x} (\link{ArchiveFSelect}) +\item \code{x} (\link{ArchiveBatchFSelect}) \item \code{exclude_columns} (\code{character()})\cr Exclude columns from table. Set to \code{NULL} if no column should be excluded. \item \code{measures} (list of \link[mlr3:Measure]{mlr3::Measure})\cr @@ -63,8 +63,8 @@ Score feature sets on additional measures. } } -\section{Super class}{ -\code{\link[bbotk:Archive]{bbotk::Archive}} -> \code{ArchiveFSelect} +\section{Super classes}{ +\code{\link[bbotk:Archive]{bbotk::Archive}} -> \code{\link[bbotk:ArchiveBatch]{bbotk::ArchiveBatch}} -> \code{ArchiveBatchFSelect} } \section{Public fields}{ \if{html}{\out{
}} @@ -85,33 +85,33 @@ Method to handle ties.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-ArchiveFSelect-new}{\code{ArchiveFSelect$new()}} -\item \href{#method-ArchiveFSelect-learner}{\code{ArchiveFSelect$learner()}} -\item \href{#method-ArchiveFSelect-learners}{\code{ArchiveFSelect$learners()}} -\item \href{#method-ArchiveFSelect-predictions}{\code{ArchiveFSelect$predictions()}} -\item \href{#method-ArchiveFSelect-resample_result}{\code{ArchiveFSelect$resample_result()}} -\item \href{#method-ArchiveFSelect-print}{\code{ArchiveFSelect$print()}} -\item \href{#method-ArchiveFSelect-best}{\code{ArchiveFSelect$best()}} -\item \href{#method-ArchiveFSelect-clone}{\code{ArchiveFSelect$clone()}} +\item \href{#method-ArchiveBatchFSelect-new}{\code{ArchiveBatchFSelect$new()}} +\item \href{#method-ArchiveBatchFSelect-learner}{\code{ArchiveBatchFSelect$learner()}} +\item \href{#method-ArchiveBatchFSelect-learners}{\code{ArchiveBatchFSelect$learners()}} +\item \href{#method-ArchiveBatchFSelect-predictions}{\code{ArchiveBatchFSelect$predictions()}} +\item \href{#method-ArchiveBatchFSelect-resample_result}{\code{ArchiveBatchFSelect$resample_result()}} +\item \href{#method-ArchiveBatchFSelect-print}{\code{ArchiveBatchFSelect$print()}} +\item \href{#method-ArchiveBatchFSelect-best}{\code{ArchiveBatchFSelect$best()}} +\item \href{#method-ArchiveBatchFSelect-clone}{\code{ArchiveBatchFSelect$clone()}} } } \if{html}{\out{
Inherited methods
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$new( +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$new( search_space, codomain, check_values = TRUE, @@ -145,14 +145,14 @@ Ignored if multiple measures are used.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-learner}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-learner}{}}} \subsection{Method \code{learner()}}{ Retrieve \link[mlr3:Learner]{mlr3::Learner} of the i-th evaluation, by position or by unique hash \code{uhash}. \code{i} and \code{uhash} are mutually exclusive. Learner does not contain a model. Use \verb{$learners()} to get learners with models. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$learner(i = NULL, uhash = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$learner(i = NULL, uhash = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -168,14 +168,14 @@ The \code{uhash} value to filter for.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-learners}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-learners}{}}} \subsection{Method \code{learners()}}{ Retrieve list of trained \link[mlr3:Learner]{mlr3::Learner} objects of the i-th evaluation, by position or by unique hash \code{uhash}. \code{i} and \code{uhash} are mutually exclusive. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$learners(i = NULL, uhash = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$learners(i = NULL, uhash = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -191,14 +191,14 @@ The \code{uhash} value to filter for.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-predictions}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-predictions}{}}} \subsection{Method \code{predictions()}}{ Retrieve list of \link[mlr3:Prediction]{mlr3::Prediction} objects of the i-th evaluation, by position or by unique hash \code{uhash}. \code{i} and \code{uhash} are mutually exclusive. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$predictions(i = NULL, uhash = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$predictions(i = NULL, uhash = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -214,13 +214,13 @@ The \code{uhash} value to filter for.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-resample_result}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-resample_result}{}}} \subsection{Method \code{resample_result()}}{ Retrieve \link[mlr3:ResampleResult]{mlr3::ResampleResult} of the i-th evaluation, by position or by unique hash \code{uhash}. \code{i} and \code{uhash} are mutually exclusive. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$resample_result(i = NULL, uhash = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$resample_result(i = NULL, uhash = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -236,12 +236,12 @@ The \code{uhash} value to filter for.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-print}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-print}{}}} \subsection{Method \code{print()}}{ Printer. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$print()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$print()}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -253,12 +253,12 @@ Printer. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-best}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-best}{}}} \subsection{Method \code{best()}}{ Returns the best scoring feature sets. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$best(batch = NULL, ties_method = NULL)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$best(batch = NULL, ties_method = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -282,12 +282,12 @@ The \code{random} method returns a random feature set from the best feature sets } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ArchiveFSelect-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ArchiveBatchFSelect-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ArchiveFSelect$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ArchiveBatchFSelect$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/AutoFSelector.Rd b/man/AutoFSelector.Rd index 26485557..bc2c8bb8 100644 --- a/man/AutoFSelector.Rd +++ b/man/AutoFSelector.Rd @@ -99,7 +99,7 @@ rr$aggregate() \if{html}{\out{
}} \describe{ \item{\code{instance_args}}{(\code{list()})\cr -All arguments from construction to create the \link{FSelectInstanceSingleCrit}.} +All arguments from construction to create the \link{FSelectInstanceBatchSingleCrit}.} \item{\code{fselector}}{(\link{FSelector})\cr Optimization algorithm.} @@ -109,17 +109,17 @@ Optimization algorithm.} \section{Active bindings}{ \if{html}{\out{
}} \describe{ -\item{\code{archive}}{([ArchiveFSelect)\cr -Returns \link{FSelectInstanceSingleCrit} archive.} +\item{\code{archive}}{([ArchiveBatchFSelect)\cr +Returns \link{FSelectInstanceBatchSingleCrit} archive.} \item{\code{learner}}{(\link[mlr3:Learner]{mlr3::Learner})\cr Trained learner.} -\item{\code{fselect_instance}}{(\link{FSelectInstanceSingleCrit})\cr +\item{\code{fselect_instance}}{(\link{FSelectInstanceBatchSingleCrit})\cr Internally created feature selection instance with all intermediate results.} \item{\code{fselect_result}}{(\link[data.table:data.table]{data.table::data.table})\cr -Short-cut to \verb{$result} from \link{FSelectInstanceSingleCrit}.} +Short-cut to \verb{$result} from \link{FSelectInstanceBatchSingleCrit}.} \item{\code{predict_type}}{(\code{character(1)})\cr Stores the currently active predict type, e.g. \code{"response"}. @@ -149,6 +149,7 @@ Hash (unique identifier) for this partial object, excluding some components whic \if{html}{\out{
Inherited methods
}} } @@ -200,7 +201,7 @@ Measure to optimize. If \code{NULL}, default measure is used.} Stop criterion of the feature selection.} \item{\code{store_fselect_instance}}{(\code{logical(1)})\cr -If \code{TRUE} (default), stores the internally created \link{FSelectInstanceSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. +If \code{TRUE} (default), stores the internally created \link{FSelectInstanceBatchSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. Is set to \code{TRUE}, if \code{store_models = TRUE}} \item{\code{store_benchmark_result}}{(\code{logical(1)})\cr @@ -213,7 +214,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{\code{callbacks}}{(list of \link{CallbackFSelect})\cr +\item{\code{callbacks}}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{\code{ties_method}}{(\code{character(1)})\cr diff --git a/man/CallbackFSelect.Rd b/man/CallbackBatchFSelect.Rd similarity index 70% rename from man/CallbackFSelect.Rd rename to man/CallbackBatchFSelect.Rd index ccf6e9fe..378444f3 100644 --- a/man/CallbackFSelect.Rd +++ b/man/CallbackBatchFSelect.Rd @@ -1,47 +1,47 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CallbackFSelect.R -\name{CallbackFSelect} -\alias{CallbackFSelect} +% Please edit documentation in R/CallbackBatchFSelect.R +\name{CallbackBatchFSelect} +\alias{CallbackBatchFSelect} \title{Create Feature Selection Callback} \description{ -Specialized \link[bbotk:CallbackOptimization]{bbotk::CallbackOptimization} for feature selection. +Specialized \link[bbotk:CallbackBatch]{bbotk::CallbackBatch} for feature selection. Callbacks allow customizing the behavior of processes in mlr3fselect. -The \code{\link[=callback_fselect]{callback_fselect()}} function creates a \link{CallbackFSelect}. +The \code{\link[=callback_batch_fselect]{callback_batch_fselect()}} function creates a \link{CallbackBatchFSelect}. Predefined callbacks are stored in the \link[mlr3misc:Dictionary]{dictionary} \link{mlr_callbacks} and can be retrieved with \code{\link[=clbk]{clbk()}}. -For more information on callbacks see \code{\link[=callback_fselect]{callback_fselect()}}. +For more information on callbacks see \code{\link[=callback_batch_fselect]{callback_batch_fselect()}}. } \examples{ # Write archive to disk -callback_fselect("mlr3fselect.backup", +callback_batch_fselect("mlr3fselect.backup", on_optimization_end = function(callback, context) { saveRDS(context$instance$archive, "archive.rds") } ) } \section{Super classes}{ -\code{\link[mlr3misc:Callback]{mlr3misc::Callback}} -> \code{\link[bbotk:CallbackOptimization]{bbotk::CallbackOptimization}} -> \code{CallbackFSelect} +\code{\link[mlr3misc:Callback]{mlr3misc::Callback}} -> \code{\link[bbotk:CallbackBatch]{bbotk::CallbackBatch}} -> \code{CallbackBatchFSelect} } \section{Public fields}{ \if{html}{\out{
}} \describe{ \item{\code{on_eval_after_design}}{(\verb{function()})\cr Stage called after design is created. -Called in \code{ObjectiveFSelect$eval_many()}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} \item{\code{on_eval_after_benchmark}}{(\verb{function()})\cr Stage called after feature sets are evaluated. -Called in \code{ObjectiveFSelect$eval_many()}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} \item{\code{on_eval_before_archive}}{(\verb{function()})\cr Stage called before performance values are written to the archive. -Called in \code{ObjectiveFSelect$eval_many()}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} } \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-CallbackFSelect-clone}{\code{CallbackFSelect$clone()}} +\item \href{#method-CallbackBatchFSelect-clone}{\code{CallbackBatchFSelect$clone()}} } } \if{html}{\out{ @@ -56,12 +56,12 @@ Called in \code{ObjectiveFSelect$eval_many()}.} }} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-CallbackFSelect-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-CallbackBatchFSelect-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{CallbackFSelect$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{CallbackBatchFSelect$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/ContextEval.Rd b/man/ContextBatchFSelect.Rd similarity index 58% rename from man/ContextEval.Rd rename to man/ContextBatchFSelect.Rd index a2aa17db..9bc20d3b 100644 --- a/man/ContextEval.Rd +++ b/man/ContextBatchFSelect.Rd @@ -1,12 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ContextEval.R -\name{ContextEval} -\alias{ContextEval} +% Please edit documentation in R/ContextBatchFSelect.R +\name{ContextBatchFSelect} +\alias{ContextBatchFSelect} \title{Evaluation Context} \description{ -The \link{ContextEval} allows \link{CallbackFSelect}s to access and modify data while a batch of feature sets is evaluated. +The \link{ContextBatchFSelect} allows \link{CallbackBatchFSelect}s to access and modify data while a batch of feature sets is evaluated. See the section on active bindings for a list of modifiable objects. -See \code{\link[=callback_fselect]{callback_fselect()}} for a list of stages that access \link{ContextEval}. +See \code{\link[=callback_batch_fselect]{callback_batch_fselect()}} for a list of stages that access \link{ContextBatchFSelect}. } \details{ This context is re-created each time a new batch of feature sets is evaluated. @@ -14,15 +14,8 @@ Changes to \verb{$objective_fselect}, \verb{$design} \verb{$benchmark_result} ar Modification on the data table in \verb{$aggregated_performance} are written to the archive. Any number of columns can be added. } -\section{Super class}{ -\code{\link[mlr3misc:Context]{mlr3misc::Context}} -> \code{ContextEval} -} -\section{Public fields}{ -\if{html}{\out{
}} -\describe{ -\item{\code{objective_fselect}}{\link{ObjectiveFSelect}.} -} -\if{html}{\out{
}} +\section{Super classes}{ +\code{\link[mlr3misc:Context]{mlr3misc::Context}} -> \code{\link[bbotk:ContextBatch]{bbotk::ContextBatch}} -> \code{ContextBatchFSelect} } \section{Active bindings}{ \if{html}{\out{
}} @@ -46,8 +39,7 @@ A callback can add additional columns which are also written to the archive.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-ContextEval-new}{\code{ContextEval$new()}} -\item \href{#method-ContextEval-clone}{\code{ContextEval$clone()}} +\item \href{#method-ContextBatchFSelect-clone}{\code{ContextBatchFSelect$clone()}} } } \if{html}{\out{ @@ -55,36 +47,17 @@ A callback can add additional columns which are also written to the archive.} }} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ContextEval-new}{}}} -\subsection{Method \code{new()}}{ -Creates a new instance of this \link[R6:R6Class]{R6} class. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ContextEval$new(objective_fselect)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{objective_fselect}}{\link{ObjectiveFSelect}.} - -\item{\code{id}}{(\code{character(1)})\cr -Identifier for the new callback.} -} -\if{html}{\out{
}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ContextEval-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ContextBatchFSelect-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ContextEval$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ContextBatchFSelect$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/FSelectInstanceMultiCrit.Rd b/man/FSelectInstanceBatchMultiCrit.Rd similarity index 68% rename from man/FSelectInstanceMultiCrit.Rd rename to man/FSelectInstanceBatchMultiCrit.Rd index 9a69d755..7668f6d3 100644 --- a/man/FSelectInstanceMultiCrit.Rd +++ b/man/FSelectInstanceBatchMultiCrit.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectInstanceMultiCrit.R -\name{FSelectInstanceMultiCrit} -\alias{FSelectInstanceMultiCrit} +% Please edit documentation in R/FSelectInstanceBatchMultiCrit.R +\name{FSelectInstanceBatchMultiCrit} +\alias{FSelectInstanceBatchMultiCrit} \title{Class for Multi Criteria Feature Selection} \description{ -The \link{FSelectInstanceMultiCrit} specifies a feature selection problem for \link[=FSelector]{FSelectors}. -The function \code{\link[=fsi]{fsi()}} creates a \link{FSelectInstanceMultiCrit} and the function \code{\link[=fselect]{fselect()}} creates an instance internally. +The \link{FSelectInstanceBatchMultiCrit} specifies a feature selection problem for a \link{FSelector}. +The function \code{\link[=fsi]{fsi()}} creates a \link{FSelectInstanceBatchMultiCrit} and the function \code{\link[=fselect]{fselect()}} creates an instance internally. } \section{Resources}{ @@ -59,7 +59,7 @@ as.data.table(instance$archive) } } \section{Super classes}{ -\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceMultiCrit]{bbotk::OptimInstanceMultiCrit}} -> \code{FSelectInstanceMultiCrit} +\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceBatch]{bbotk::OptimInstanceBatch}} -> \code{\link[bbotk:OptimInstanceBatchMultiCrit]{bbotk::OptimInstanceBatchMultiCrit}} -> \code{FSelectInstanceBatchMultiCrit} } \section{Active bindings}{ \if{html}{\out{
}} @@ -72,29 +72,29 @@ Feature sets for task subsetting.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectInstanceMultiCrit-new}{\code{FSelectInstanceMultiCrit$new()}} -\item \href{#method-FSelectInstanceMultiCrit-assign_result}{\code{FSelectInstanceMultiCrit$assign_result()}} -\item \href{#method-FSelectInstanceMultiCrit-print}{\code{FSelectInstanceMultiCrit$print()}} -\item \href{#method-FSelectInstanceMultiCrit-clone}{\code{FSelectInstanceMultiCrit$clone()}} +\item \href{#method-FSelectInstanceBatchMultiCrit-new}{\code{FSelectInstanceBatchMultiCrit$new()}} +\item \href{#method-FSelectInstanceBatchMultiCrit-assign_result}{\code{FSelectInstanceBatchMultiCrit$assign_result()}} +\item \href{#method-FSelectInstanceBatchMultiCrit-print}{\code{FSelectInstanceBatchMultiCrit$print()}} +\item \href{#method-FSelectInstanceBatchMultiCrit-clone}{\code{FSelectInstanceBatchMultiCrit$clone()}} } } \if{html}{\out{
Inherited methods
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceMultiCrit-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchMultiCrit-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceMultiCrit$new( +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchMultiCrit$new( task, learner, resampling, @@ -103,7 +103,7 @@ Creates a new instance of this \link[R6:R6Class]{R6} class. store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list() + callbacks = NULL )}\if{html}{\out{
}} } @@ -138,20 +138,20 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{\code{callbacks}}{(list of \link{CallbackFSelect})\cr +\item{\code{callbacks}}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} } \if{html}{\out{
}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceMultiCrit-assign_result}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchMultiCrit-assign_result}{}}} \subsection{Method \code{assign_result()}}{ The \link{FSelector} object writes the best found feature subsets and estimated performance values here. For internal use. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceMultiCrit$assign_result(xdt, ydt)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchMultiCrit$assign_result(xdt, ydt)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -159,7 +159,7 @@ For internal use. \describe{ \item{\code{xdt}}{(\code{data.table::data.table()})\cr x values as \code{data.table}. Each row is one point. Contains the value in -the \emph{search space} of the \link{FSelectInstanceMultiCrit} object. Can contain +the \emph{search space} of the \link{FSelectInstanceBatchMultiCrit} object. Can contain additional columns for extra information.} \item{\code{ydt}}{(\code{data.table::data.table()})\cr @@ -169,12 +169,12 @@ Optimal outcomes, e.g. the Pareto front.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceMultiCrit-print}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchMultiCrit-print}{}}} \subsection{Method \code{print()}}{ Printer. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceMultiCrit$print(...)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchMultiCrit$print(...)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -186,12 +186,12 @@ Printer. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceMultiCrit-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchMultiCrit-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceMultiCrit$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchMultiCrit$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/FSelectInstanceSingleCrit.Rd b/man/FSelectInstanceBatchSingleCrit.Rd similarity index 74% rename from man/FSelectInstanceSingleCrit.Rd rename to man/FSelectInstanceBatchSingleCrit.Rd index 280102fb..e745ceb2 100644 --- a/man/FSelectInstanceSingleCrit.Rd +++ b/man/FSelectInstanceBatchSingleCrit.Rd @@ -1,17 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectInstanceSingleCrit.R -\name{FSelectInstanceSingleCrit} -\alias{FSelectInstanceSingleCrit} +% Please edit documentation in R/FSelectInstanceBatchSingleCrit.R +\name{FSelectInstanceBatchSingleCrit} +\alias{FSelectInstanceBatchSingleCrit} \title{Class for Single Criterion Feature Selection} \description{ -The \link{FSelectInstanceSingleCrit} specifies a feature selection problem for \link[=FSelector]{FSelectors}. -The function \code{\link[=fsi]{fsi()}} creates a \link{FSelectInstanceSingleCrit} and the function \code{\link[=fselect]{fselect()}} creates an instance internally. +The \link{FSelectInstanceBatchSingleCrit} specifies a feature selection problem for a \link{FSelector}. +The function \code{\link[=fsi]{fsi()}} creates a \link{FSelectInstanceBatchSingleCrit} and the function \code{\link[=fselect]{fselect()}} creates an instance internally. -The instance contains an \link{ObjectiveFSelect} object that encodes the black box objective function a \link{FSelector} has to optimize. +The instance contains an \link{ObjectiveFSelectBatch} object that encodes the black box objective function a \link{FSelector} has to optimize. The instance allows the basic operations of querying the objective at design points (\verb{$eval_batch()}). This operation is usually done by the \link{FSelector}. Evaluations of feature subsets are performed in batches by calling \code{\link[mlr3:benchmark]{mlr3::benchmark()}} internally. -The evaluated feature subsets are stored in the \link[=ArchiveFSelect]{Archive} (\verb{$archive}). +The evaluated feature subsets are stored in the \link[=ArchiveBatchFSelect]{Archive} (\verb{$archive}). Before a batch is evaluated, the \link[bbotk:Terminator]{bbotk::Terminator} is queried for the remaining budget. If the available budget is exhausted, an exception is raised, and no further evaluations can be performed from this point on. The \link{FSelector} is also supposed to store its final result, consisting of a selected feature subset and associated estimated performance values, by calling the method \code{instance$assign_result()}. @@ -93,7 +93,7 @@ as.data.table(instance$archive) } } \section{Super classes}{ -\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceSingleCrit]{bbotk::OptimInstanceSingleCrit}} -> \code{FSelectInstanceSingleCrit} +\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceBatch]{bbotk::OptimInstanceBatch}} -> \code{\link[bbotk:OptimInstanceBatchSingleCrit]{bbotk::OptimInstanceBatchSingleCrit}} -> \code{FSelectInstanceBatchSingleCrit} } \section{Active bindings}{ \if{html}{\out{
}} @@ -106,29 +106,29 @@ Feature set for task subsetting.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectInstanceSingleCrit-new}{\code{FSelectInstanceSingleCrit$new()}} -\item \href{#method-FSelectInstanceSingleCrit-assign_result}{\code{FSelectInstanceSingleCrit$assign_result()}} -\item \href{#method-FSelectInstanceSingleCrit-print}{\code{FSelectInstanceSingleCrit$print()}} -\item \href{#method-FSelectInstanceSingleCrit-clone}{\code{FSelectInstanceSingleCrit$clone()}} +\item \href{#method-FSelectInstanceBatchSingleCrit-new}{\code{FSelectInstanceBatchSingleCrit$new()}} +\item \href{#method-FSelectInstanceBatchSingleCrit-assign_result}{\code{FSelectInstanceBatchSingleCrit$assign_result()}} +\item \href{#method-FSelectInstanceBatchSingleCrit-print}{\code{FSelectInstanceBatchSingleCrit$print()}} +\item \href{#method-FSelectInstanceBatchSingleCrit-clone}{\code{FSelectInstanceBatchSingleCrit$clone()}} } } \if{html}{\out{
Inherited methods
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceSingleCrit-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchSingleCrit-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceSingleCrit$new( +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchSingleCrit$new( task, learner, resampling, @@ -137,7 +137,7 @@ Creates a new instance of this \link[R6:R6Class]{R6} class. store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" )}\if{html}{\out{
}} } @@ -172,7 +172,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{\code{callbacks}}{(list of \link{CallbackFSelect})\cr +\item{\code{callbacks}}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{\code{ties_method}}{(\code{character(1)})\cr @@ -187,13 +187,13 @@ Ignored if multiple measures are used.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceSingleCrit-assign_result}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchSingleCrit-assign_result}{}}} \subsection{Method \code{assign_result()}}{ The \link{FSelector} writes the best found feature subset and estimated performance value here. For internal use. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceSingleCrit$assign_result(xdt, y)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchSingleCrit$assign_result(xdt, y)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -201,7 +201,7 @@ For internal use. \describe{ \item{\code{xdt}}{(\code{data.table::data.table()})\cr x values as \code{data.table}. Each row is one point. Contains the value in -the \emph{search space} of the \link{FSelectInstanceMultiCrit} object. Can contain +the \emph{search space} of the \link{FSelectInstanceBatchMultiCrit} object. Can contain additional columns for extra information.} \item{\code{y}}{(\code{numeric(1)})\cr @@ -211,12 +211,12 @@ Optimal outcome.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceSingleCrit-print}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchSingleCrit-print}{}}} \subsection{Method \code{print()}}{ Printer. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceSingleCrit$print(...)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchSingleCrit$print(...)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -228,12 +228,12 @@ Printer. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectInstanceSingleCrit-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectInstanceBatchSingleCrit-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectInstanceSingleCrit$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectInstanceBatchSingleCrit$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/FSelector.Rd b/man/FSelector.Rd index 3c7bfb97..d15d33ba 100644 --- a/man/FSelector.Rd +++ b/man/FSelector.Rd @@ -2,39 +2,13 @@ % Please edit documentation in R/FSelector.R \name{FSelector} \alias{FSelector} -\title{Class for Feature Selection Algorithms} +\title{FSelector} \description{ -The \link{FSelector} implements the optimization algorithm. +The `FSelector`` implements the optimization algorithm. } \details{ -\link{FSelector} is an abstract base class that implements the base functionality each fselector must provide. -A subclass is implemented in the following way: -\itemize{ -\item Inherit from FSelector. -\item Specify the private abstract method \verb{$.optimize()} and use it to call into your optimizer. -\item You need to call \code{instance$eval_batch()} to evaluate design points. -\item The batch evaluation is requested at the \link{FSelectInstanceSingleCrit}/\link{FSelectInstanceMultiCrit} object \code{instance}, so each batch is possibly executed in parallel via \code{\link[mlr3:benchmark]{mlr3::benchmark()}}, and all evaluations are stored inside of \code{instance$archive}. -\item Before the batch evaluation, the \link[bbotk:Terminator]{bbotk::Terminator} is checked, and if it is positive, an exception of class \code{"terminated_error"} is generated. -In the latter case the current batch of evaluations is still stored in \code{instance}, but the numeric scores are not sent back to the handling optimizer as it has lost execution control. -\item After such an exception was caught we select the best set from \code{instance$archive} and return it. -\item Note that therefore more points than specified by the \link[bbotk:Terminator]{bbotk::Terminator} may be evaluated, as the Terminator is only checked before a batch evaluation, and not in-between evaluation in a batch. -How many more depends on the setting of the batch size. -\item Overwrite the private super-method \code{.assign_result()} if you want to decide how to estimate the final set in the instance and its estimated performance. -The default behavior is: We pick the best resample experiment, regarding the given measure, then assign its set and aggregated performance to the instance. -} -} -\section{Private Methods}{ - -\itemize{ -\item \code{.optimize(instance)} -> \code{NULL}\cr -Abstract base method. Implement to specify feature selection of your subclass. -See technical details sections. -\item \code{.assign_result(instance)} -> \code{NULL}\cr -Abstract base method. Implement to specify how the final feature subset is selected. -See technical details sections. -} +\code{FSelector} is an abstract base class that implements the base functionality each fselector must provide. } - \section{Resources}{ There are several sections about feature selection in the \href{https://mlr3book.mlr-org.com}{mlr3book}. @@ -49,6 +23,19 @@ The \href{https://mlr-org.com/gallery.html}{gallery} features a collection of ca } } +\seealso{ +Other FSelector: +\code{\link{mlr_fselectors}}, +\code{\link{mlr_fselectors_design_points}}, +\code{\link{mlr_fselectors_exhaustive_search}}, +\code{\link{mlr_fselectors_genetic_search}}, +\code{\link{mlr_fselectors_random_search}}, +\code{\link{mlr_fselectors_rfe}}, +\code{\link{mlr_fselectors_rfecv}}, +\code{\link{mlr_fselectors_sequential}}, +\code{\link{mlr_fselectors_shadow_variable_search}} +} +\concept{FSelector} \section{Public fields}{ \if{html}{\out{
}} \describe{ @@ -89,7 +76,6 @@ The referenced help package can be opened via method \verb{$help()}.} \item \href{#method-FSelector-format}{\code{FSelector$format()}} \item \href{#method-FSelector-print}{\code{FSelector$print()}} \item \href{#method-FSelector-help}{\code{FSelector$help()}} -\item \href{#method-FSelector-optimize}{\code{FSelector$optimize()}} \item \href{#method-FSelector-clone}{\code{FSelector$clone()}} } } @@ -179,28 +165,6 @@ Opens the corresponding help page referenced by field \verb{$man}. \if{html}{\out{
}}\preformatted{FSelector$help()}\if{html}{\out{
}} } -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelector-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Performs the feature selection on a \link{FSelectInstanceSingleCrit} or \link{FSelectInstanceMultiCrit} until termination. -The single evaluations will be written into the \link{ArchiveFSelect} that resides in the \link{FSelectInstanceSingleCrit} / \link{FSelectInstanceMultiCrit}. -The result will be written into the instance object. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelector$optimize(inst)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{inst}}{(\link{FSelectInstanceSingleCrit} | \link{FSelectInstanceMultiCrit}).} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{\link[data.table:data.table]{data.table::data.table()}}. -} } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/FSelectorBatch.Rd b/man/FSelectorBatch.Rd new file mode 100644 index 00000000..bb7d65d5 --- /dev/null +++ b/man/FSelectorBatch.Rd @@ -0,0 +1,155 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/FSelectorBatch.R +\name{FSelectorBatch} +\alias{FSelectorBatch} +\title{Class for Batch Feature Selection Algorithms} +\description{ +The \link{FSelectorBatch} implements the optimization algorithm. +} +\details{ +\link{FSelectorBatch} is an abstract base class that implements the base functionality each fselector must provide. +A subclass is implemented in the following way: +\itemize{ +\item Inherit from FSelectorBatch. +\item Specify the private abstract method \verb{$.optimize()} and use it to call into your optimizer. +\item You need to call \code{instance$eval_batch()} to evaluate design points. +\item The batch evaluation is requested at the \link{FSelectInstanceBatchSingleCrit}/\link{FSelectInstanceBatchMultiCrit} object \code{instance}, so each batch is possibly executed in parallel via \code{\link[mlr3:benchmark]{mlr3::benchmark()}}, and all evaluations are stored inside of \code{instance$archive}. +\item Before the batch evaluation, the \link[bbotk:Terminator]{bbotk::Terminator} is checked, and if it is positive, an exception of class \code{"terminated_error"} is generated. +In the latter case the current batch of evaluations is still stored in \code{instance}, but the numeric scores are not sent back to the handling optimizer as it has lost execution control. +\item After such an exception was caught we select the best set from \code{instance$archive} and return it. +\item Note that therefore more points than specified by the \link[bbotk:Terminator]{bbotk::Terminator} may be evaluated, as the Terminator is only checked before a batch evaluation, and not in-between evaluation in a batch. +How many more depends on the setting of the batch size. +\item Overwrite the private super-method \code{.assign_result()} if you want to decide how to estimate the final set in the instance and its estimated performance. +The default behavior is: We pick the best resample experiment, regarding the given measure, then assign its set and aggregated performance to the instance. +} +} +\section{Private Methods}{ + +\itemize{ +\item \code{.optimize(instance)} -> \code{NULL}\cr +Abstract base method. Implement to specify feature selection of your subclass. +See technical details sections. +\item \code{.assign_result(instance)} -> \code{NULL}\cr +Abstract base method. Implement to specify how the final feature subset is selected. +See technical details sections. +} +} + +\section{Resources}{ + +There are several sections about feature selection in the \href{https://mlr3book.mlr-org.com}{mlr3book}. +\itemize{ +\item Learn more about \href{https://mlr3book.mlr-org.com/chapters/chapter6/feature_selection.html#the-fselector-class}{fselectors}. +} + +The \href{https://mlr-org.com/gallery.html}{gallery} features a collection of case studies and demos about optimization. +\itemize{ +\item Utilize the built-in feature importance of models with \href{https://mlr-org.com/gallery/optimization/2023-02-07-recursive-feature-elimination/}{Recursive Feature Elimination}. +\item Run a feature selection with \href{https://mlr-org.com/gallery/optimization/2023-02-01-shadow-variable-search/}{Shadow Variable Search}. +} +} + +\section{Super class}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorBatch} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-FSelectorBatch-new}{\code{FSelectorBatch$new()}} +\item \href{#method-FSelectorBatch-optimize}{\code{FSelectorBatch$optimize()}} +\item \href{#method-FSelectorBatch-clone}{\code{FSelectorBatch$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatch-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FSelectorBatch$new( + id = "fselector_batch", + param_set, + properties, + packages = character(), + label = NA_character_, + man = NA_character_ +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{id}}{(\code{character(1)})\cr +Identifier for the new instance.} + +\item{\code{param_set}}{\link[paradox:ParamSet]{paradox::ParamSet}\cr +Set of control parameters.} + +\item{\code{properties}}{(\code{character()})\cr +Set of properties of the fselector. +Must be a subset of \code{\link[mlr3:mlr_reflections]{mlr_reflections$fselect_properties}}.} + +\item{\code{packages}}{(\code{character()})\cr +Set of required packages. +Note that these packages will be loaded via \code{\link[=requireNamespace]{requireNamespace()}}, and are not attached.} + +\item{\code{label}}{(\code{character(1)})\cr +Label for this object. +Can be used in tables, plot and text output instead of the ID.} + +\item{\code{man}}{(\code{character(1)})\cr +String in the format \verb{[pkg]::[topic]} pointing to a manual page for this object. +The referenced help package can be opened via method \verb{$help()}.} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatch-optimize}{}}} +\subsection{Method \code{optimize()}}{ +Performs the feature selection on a \link{FSelectInstanceBatchSingleCrit} or \link{FSelectInstanceBatchMultiCrit} until termination. +The single evaluations will be written into the \link{ArchiveBatchFSelect} that resides in the \link{FSelectInstanceBatchSingleCrit} / \link{FSelectInstanceBatchMultiCrit}. +The result will be written into the instance object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FSelectorBatch$optimize(inst)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{inst}}{(\link{FSelectInstanceBatchSingleCrit} | \link{FSelectInstanceBatchMultiCrit}).} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{\link[data.table:data.table]{data.table::data.table()}}. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatch-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FSelectorBatch$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/FSelectorFromOptimizer.Rd b/man/FSelectorBatchFromOptimizerBatch.Rd similarity index 55% rename from man/FSelectorFromOptimizer.Rd rename to man/FSelectorBatchFromOptimizerBatch.Rd index 534abf48..e4563474 100644 --- a/man/FSelectorFromOptimizer.Rd +++ b/man/FSelectorBatchFromOptimizerBatch.Rd @@ -1,21 +1,21 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorFromOptimizer.R -\name{FSelectorFromOptimizer} -\alias{FSelectorFromOptimizer} -\title{FSelectorFromOptimizer} +% Please edit documentation in R/FSelectorBatchFromOptimizerBatch.R +\name{FSelectorBatchFromOptimizerBatch} +\alias{FSelectorBatchFromOptimizerBatch} +\title{FSelectorBatchFromOptimizerBatch} \description{ Internally used to transform \link[bbotk:Optimizer]{bbotk::Optimizer} to \link{FSelector}. } \keyword{internal} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorFromOptimizer} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchFromOptimizerBatch} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorFromOptimizer-new}{\code{FSelectorFromOptimizer$new()}} -\item \href{#method-FSelectorFromOptimizer-optimize}{\code{FSelectorFromOptimizer$optimize()}} -\item \href{#method-FSelectorFromOptimizer-clone}{\code{FSelectorFromOptimizer$clone()}} +\item \href{#method-FSelectorBatchFromOptimizerBatch-new}{\code{FSelectorBatchFromOptimizerBatch$new()}} +\item \href{#method-FSelectorBatchFromOptimizerBatch-optimize}{\code{FSelectorBatchFromOptimizerBatch$optimize()}} +\item \href{#method-FSelectorBatchFromOptimizerBatch-clone}{\code{FSelectorBatchFromOptimizerBatch$clone()}} } } \if{html}{\out{ @@ -28,12 +28,12 @@ Internally used to transform \link[bbotk:Optimizer]{bbotk::Optimizer} to \link{F }} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorFromOptimizer-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchFromOptimizerBatch-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectorFromOptimizer$new(optimizer, man = NA_character_)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectorBatchFromOptimizerBatch$new(optimizer, man = NA_character_)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -50,19 +50,19 @@ The referenced help package can be opened via method \verb{$help()}.} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorFromOptimizer-optimize}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchFromOptimizerBatch-optimize}{}}} \subsection{Method \code{optimize()}}{ -Performs the feature selection on a \link{FSelectInstanceSingleCrit} / -\link{FSelectInstanceMultiCrit} until termination. +Performs the feature selection on a \link{FSelectInstanceBatchSingleCrit} / +\link{FSelectInstanceBatchMultiCrit} until termination. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectorFromOptimizer$optimize(inst)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectorBatchFromOptimizerBatch$optimize(inst)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{inst}}{(\link{FSelectInstanceSingleCrit} | \link{FSelectInstanceMultiCrit}).} +\item{\code{inst}}{(\link{FSelectInstanceBatchSingleCrit} | \link{FSelectInstanceBatchMultiCrit}).} } \if{html}{\out{
}} } @@ -71,12 +71,12 @@ Performs the feature selection on a \link{FSelectInstanceSingleCrit} / } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorFromOptimizer-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchFromOptimizerBatch-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{FSelectorFromOptimizer$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{FSelectorBatchFromOptimizerBatch$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/ObjectiveFSelect.Rd b/man/ObjectiveFSelect.Rd index f3789ad7..61ad1fe7 100644 --- a/man/ObjectiveFSelect.Rd +++ b/man/ObjectiveFSelect.Rd @@ -5,7 +5,7 @@ \title{Class for Feature Selection Objective} \description{ Stores the objective function that estimates the performance of feature subsets. -This class is usually constructed internally by the \link{FSelectInstanceSingleCrit} / \link{FSelectInstanceMultiCrit}. +This class is usually constructed internally by the \link{FSelectInstanceBatchSingleCrit} / \link{FSelectInstanceBatchMultiCrit}. } \section{Super class}{ \code{\link[bbotk:Objective]{bbotk::Objective}} -> \code{ObjectiveFSelect} @@ -25,9 +25,7 @@ This class is usually constructed internally by the \link{FSelectInstanceSingleC \item{\code{store_benchmark_result}}{(\code{logical(1)}).} -\item{\code{archive}}{(\link{ArchiveFSelect}).} - -\item{\code{callbacks}}{(List of \link{CallbackFSelect}s).} +\item{\code{callbacks}}{(List of \link{CallbackBatchFSelect}s).} } \if{html}{\out{
}} } @@ -63,8 +61,7 @@ Creates a new instance of this \link[R6:R6Class]{R6} class. check_values = TRUE, store_benchmark_result = TRUE, store_models = FALSE, - archive = NULL, - callbacks = list() + callbacks = NULL )}\if{html}{\out{
}} } @@ -96,11 +93,7 @@ Store benchmark result in archive?} \item{\code{store_models}}{(\code{logical(1)}). Store models in benchmark result?} -\item{\code{archive}}{(\link{ArchiveFSelect})\cr -Reference to the archive of \link{FSelectInstanceSingleCrit} | \link{FSelectInstanceMultiCrit}. -If \code{NULL} (default), benchmark result and models cannot be stored.} - -\item{\code{callbacks}}{(list of \link{CallbackFSelect})\cr +\item{\code{callbacks}}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} } \if{html}{\out{
}} diff --git a/man/ObjectiveFSelectBatch.Rd b/man/ObjectiveFSelectBatch.Rd new file mode 100644 index 00000000..ddaadb78 --- /dev/null +++ b/man/ObjectiveFSelectBatch.Rd @@ -0,0 +1,112 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ObjectiveFSelectBatch.R +\name{ObjectiveFSelectBatch} +\alias{ObjectiveFSelectBatch} +\title{Class for Feature Selection Objective} +\description{ +Stores the objective function that estimates the performance of feature subsets. +This class is usually constructed internally by the \link{FSelectInstanceBatchSingleCrit} / \link{FSelectInstanceBatchMultiCrit}. +} +\section{Super classes}{ +\code{\link[bbotk:Objective]{bbotk::Objective}} -> \code{\link[mlr3fselect:ObjectiveFSelect]{mlr3fselect::ObjectiveFSelect}} -> \code{ObjectiveFSelectBatch} +} +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{archive}}{(\link{ArchiveBatchFSelect}).} +} +\if{html}{\out{
}} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-ObjectiveFSelectBatch-new}{\code{ObjectiveFSelectBatch$new()}} +\item \href{#method-ObjectiveFSelectBatch-clone}{\code{ObjectiveFSelectBatch$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ObjectiveFSelectBatch-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ObjectiveFSelectBatch$new( + task, + learner, + resampling, + measures, + check_values = TRUE, + store_benchmark_result = TRUE, + store_models = FALSE, + archive = NULL, + callbacks = NULL +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{task}}{(\link[mlr3:Task]{mlr3::Task})\cr +Task to operate on.} + +\item{\code{learner}}{(\link[mlr3:Learner]{mlr3::Learner})\cr +Learner to optimize the feature subset for.} + +\item{\code{resampling}}{(\link[mlr3:Resampling]{mlr3::Resampling})\cr +Resampling that is used to evaluated the performance of the feature subsets. +Uninstantiated resamplings are instantiated during construction so that all feature subsets are evaluated on the same data splits. +Already instantiated resamplings are kept unchanged.} + +\item{\code{measures}}{(list of \link[mlr3:Measure]{mlr3::Measure})\cr +Measures to optimize. +If \code{NULL}, \CRANpkg{mlr3}'s default measure is used.} + +\item{\code{check_values}}{(\code{logical(1)})\cr +Check the parameters before the evaluation and the results for +validity?} + +\item{\code{store_benchmark_result}}{(\code{logical(1)})\cr +Store benchmark result in archive?} + +\item{\code{store_models}}{(\code{logical(1)}). +Store models in benchmark result?} + +\item{\code{archive}}{(\link{ArchiveBatchFSelect})\cr +Reference to the archive of \link{FSelectInstanceBatchSingleCrit} | \link{FSelectInstanceBatchMultiCrit}. +If \code{NULL} (default), benchmark result and models cannot be stored.} + +\item{\code{callbacks}}{(list of \link{CallbackBatchFSelect})\cr +List of callbacks.} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ObjectiveFSelectBatch-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ObjectiveFSelectBatch$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/auto_fselector.Rd b/man/auto_fselector.Rd index 61ab526d..2ecdb421 100644 --- a/man/auto_fselector.Rd +++ b/man/auto_fselector.Rd @@ -16,7 +16,7 @@ auto_fselector( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) } @@ -47,7 +47,7 @@ Ignored if \code{terminator} is passed.} Stop criterion of the feature selection.} \item{store_fselect_instance}{(\code{logical(1)})\cr -If \code{TRUE} (default), stores the internally created \link{FSelectInstanceSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. +If \code{TRUE} (default), stores the internally created \link{FSelectInstanceBatchSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. Is set to \code{TRUE}, if \code{store_models = TRUE}} \item{store_benchmark_result}{(\code{logical(1)})\cr @@ -60,7 +60,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{callbacks}{(list of \link{CallbackFSelect})\cr +\item{callbacks}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{ties_method}{(\code{character(1)})\cr diff --git a/man/callback_fselect.Rd b/man/callback_batch_fselect.Rd similarity index 69% rename from man/callback_fselect.Rd rename to man/callback_batch_fselect.Rd index 0bf12025..33e9794e 100644 --- a/man/callback_fselect.Rd +++ b/man/callback_batch_fselect.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CallbackFSelect.R -\name{callback_fselect} -\alias{callback_fselect} +% Please edit documentation in R/CallbackBatchFSelect.R +\name{callback_batch_fselect} +\alias{callback_batch_fselect} \title{Create Feature Selection Callback} \usage{ -callback_fselect( +callback_batch_fselect( id, label = NA_character_, man = NA_character_, @@ -31,46 +31,38 @@ The referenced help package can be opened via method \verb{$help()}.} \item{on_optimization_begin}{(\verb{function()})\cr Stage called at the beginning of the optimization. -Called in \code{Optimizer$optimize()}. -The context available is \link[bbotk:ContextOptimization]{bbotk::ContextOptimization}.} +Called in \code{Optimizer$optimize()}.} \item{on_optimizer_before_eval}{(\verb{function()})\cr Stage called after the optimizer proposes points. -Called in \code{OptimInstance$eval_batch()}. -The context available is \link[bbotk:ContextOptimization]{bbotk::ContextOptimization}.} +Called in \code{OptimInstance$eval_batch()}.} \item{on_eval_after_design}{(\verb{function()})\cr Stage called after design is created. -Called in \code{ObjectiveFSelect$eval_many()}. -The context available is \link{ContextEval}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} \item{on_eval_after_benchmark}{(\verb{function()})\cr Stage called after feature sets are evaluated. -Called in \code{ObjectiveFSelect$eval_many()}. -The context available is \link{ContextEval}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} \item{on_eval_before_archive}{(\verb{function()})\cr Stage called before performance values are written to the archive. -Called in \code{ObjectiveFSelect$eval_many()}. -The context available is \link{ContextEval}.} +Called in \code{ObjectiveFSelectBatch$eval_many()}.} \item{on_optimizer_after_eval}{(\verb{function()})\cr Stage called after points are evaluated. -Called in \code{OptimInstance$eval_batch()}. -The context available is \link[bbotk:ContextOptimization]{bbotk::ContextOptimization}.} +Called in \code{OptimInstance$eval_batch()}.} \item{on_result}{(\verb{function()})\cr Stage called after result are written. -Called in \code{OptimInstance$assign_result()}. -The context available is \link[bbotk:ContextOptimization]{bbotk::ContextOptimization}.} +Called in \code{OptimInstance$assign_result()}.} \item{on_optimization_end}{(\verb{function()})\cr Stage called at the end of the optimization. -Called in \code{Optimizer$optimize()}. -The context available is \link[bbotk:ContextOptimization]{bbotk::ContextOptimization}.} +Called in \code{Optimizer$optimize()}.} } \description{ -Function to create a \link{CallbackFSelect}. +Function to create a \link{CallbackBatchFSelect}. Predefined callbacks are stored in the \link[mlr3misc:Dictionary]{dictionary} \link{mlr_callbacks} and can be retrieved with \code{\link[=clbk]{clbk()}}. Feature selection callbacks can be called from different stages of feature selection. @@ -93,7 +85,7 @@ End Feature Selection }\if{html}{\out{
}} See also the section on parameters for more information on the stages. -A feature selection callback works with \link[bbotk:ContextOptimization]{bbotk::ContextOptimization} and \link{ContextEval}. +A feature selection callback works with \link[bbotk:ContextBatch]{bbotk::ContextBatch} and \link{ContextBatchFSelect}. } \details{ When implementing a callback, each function must have two arguments named \code{callback} and \code{context}. @@ -103,17 +95,17 @@ Avoid writing large data the state. This can slow down the feature selection when the evaluation of configurations is parallelized. Feature selection callbacks access two different contexts depending on the stage. -The stages \code{on_eval_after_design}, \code{on_eval_after_benchmark}, \code{on_eval_before_archive} access \link{ContextEval}. +The stages \code{on_eval_after_design}, \code{on_eval_after_benchmark}, \code{on_eval_before_archive} access \link{ContextBatchFSelect}. This context can be used to customize the evaluation of a batch of feature sets. Changes to the state of callback are lost after the evaluation of a batch and changes to the fselect instance or the fselector are not possible. -Persistent data should be written to the archive via \verb{$aggregated_performance} (see \link{ContextEval}). -The other stages access \link{ContextOptimization}. +Persistent data should be written to the archive via \verb{$aggregated_performance} (see \link{ContextBatchFSelect}). +The other stages access \link{ContextBatch}. This context can be used to modify the fselect instance, archive, fselector and final result. -There are two different contexts because the evaluation can be parallelized i.e. multiple instances of \link{ContextEval} exists on different workers at the same time. +There are two different contexts because the evaluation can be parallelized i.e. multiple instances of \link{ContextBatchFSelect} exists on different workers at the same time. } \examples{ # Write archive to disk -callback_fselect("mlr3fselect.backup", +callback_batch_fselect("mlr3fselect.backup", on_optimization_end = function(callback, context) { saveRDS(context$instance$archive, "archive.rds") } diff --git a/man/fs.Rd b/man/fs.Rd index be73f51e..16212d10 100644 --- a/man/fs.Rd +++ b/man/fs.Rd @@ -28,7 +28,7 @@ Functions to retrieve objects, set parameters and assign to fields in one go. Relies on \code{\link[mlr3misc:dictionary_sugar_get]{mlr3misc::dictionary_sugar_get()}} to extract objects from the respective \link[mlr3misc:Dictionary]{mlr3misc::Dictionary}: \itemize{ \item \code{fs()} for a \link{FSelector} from \link{mlr_fselectors}. -\item \code{fss()} for a list of \link[=FSelector]{FSelectors} from \link{mlr_fselectors}. +\item \code{fss()} for a list of a \link{FSelector} from \link{mlr_fselectors}. \item \code{trm()} for a \link{Terminator} from \link{mlr_terminators}. \item \code{trms()} for a list of \link[=Terminator]{Terminators} from \link{mlr_terminators}. } diff --git a/man/fselect.Rd b/man/fselect.Rd index 2431c713..cbe19b8f 100644 --- a/man/fselect.Rd +++ b/man/fselect.Rd @@ -16,7 +16,7 @@ fselect( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) } @@ -36,7 +36,7 @@ Uninstantiated resamplings are instantiated during construction so that all feat Already instantiated resamplings are kept unchanged.} \item{measures}{(\link[mlr3:Measure]{mlr3::Measure} or list of \link[mlr3:Measure]{mlr3::Measure})\cr -A single measure creates a \link{FSelectInstanceSingleCrit} and multiple measures a \link{FSelectInstanceMultiCrit}. +A single measure creates a \link{FSelectInstanceBatchSingleCrit} and multiple measures a \link{FSelectInstanceBatchMultiCrit}. If \code{NULL}, default measure is used.} \item{term_evals}{(\code{integer(1)})\cr @@ -60,7 +60,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{callbacks}{(list of \link{CallbackFSelect})\cr +\item{callbacks}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{ties_method}{(\code{character(1)})\cr @@ -72,17 +72,17 @@ The \code{random} method returns a random feature set from the best feature sets Ignored if multiple measures are used.} } \value{ -\link{FSelectInstanceSingleCrit} | \link{FSelectInstanceMultiCrit} +\link{FSelectInstanceBatchSingleCrit} | \link{FSelectInstanceBatchMultiCrit} } \description{ Function to optimize the features of a \link[mlr3:Learner]{mlr3::Learner}. -The function internally creates a \link{FSelectInstanceSingleCrit} or \link{FSelectInstanceMultiCrit} which describes the feature selection problem. +The function internally creates a \link{FSelectInstanceBatchSingleCrit} or \link{FSelectInstanceBatchMultiCrit} which describes the feature selection problem. It executes the feature selection with the \link{FSelector} (\code{method}) and returns the result with the fselect instance (\verb{$result}). -The \link{ArchiveFSelect} (\verb{$archive}) stores all evaluated hyperparameter configurations and performance scores. +The \link{ArchiveBatchFSelect} (\verb{$archive}) stores all evaluated hyperparameter configurations and performance scores. } \details{ -The \link[mlr3:Task]{mlr3::Task}, \link[mlr3:Learner]{mlr3::Learner}, \link[mlr3:Resampling]{mlr3::Resampling}, \link[mlr3:Measure]{mlr3::Measure} and \link{Terminator} are used to construct a \link{FSelectInstanceSingleCrit}. -If multiple performance \link[=Measure]{Measures} are supplied, a \link{FSelectInstanceMultiCrit} is created. +The \link[mlr3:Task]{mlr3::Task}, \link[mlr3:Learner]{mlr3::Learner}, \link[mlr3:Resampling]{mlr3::Resampling}, \link[mlr3:Measure]{mlr3::Measure} and \link{Terminator} are used to construct a \link{FSelectInstanceBatchSingleCrit}. +If multiple performance \link[=Measure]{Measures} are supplied, a \link{FSelectInstanceBatchMultiCrit} is created. The parameter \code{term_evals} and \code{term_time} are shortcuts to create a \link{Terminator}. If both parameters are passed, a \link{TerminatorCombo} is constructed. For other \link[=Terminator]{Terminators}, pass one with \code{terminator}. diff --git a/man/fselect_nested.Rd b/man/fselect_nested.Rd index c939347d..ed04cfdb 100644 --- a/man/fselect_nested.Rd +++ b/man/fselect_nested.Rd @@ -18,7 +18,7 @@ fselect_nested( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) } @@ -53,7 +53,7 @@ Ignored if \code{terminator} is passed.} Stop criterion of the feature selection.} \item{store_fselect_instance}{(\code{logical(1)})\cr -If \code{TRUE} (default), stores the internally created \link{FSelectInstanceSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. +If \code{TRUE} (default), stores the internally created \link{FSelectInstanceBatchSingleCrit} with all intermediate results in slot \verb{$fselect_instance}. Is set to \code{TRUE}, if \code{store_models = TRUE}} \item{store_benchmark_result}{(\code{logical(1)})\cr @@ -66,7 +66,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{callbacks}{(list of \link{CallbackFSelect})\cr +\item{callbacks}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{ties_method}{(\code{character(1)})\cr diff --git a/man/fsi.Rd b/man/fsi.Rd index 99a53968..a33dacbe 100644 --- a/man/fsi.Rd +++ b/man/fsi.Rd @@ -13,7 +13,7 @@ fsi( store_benchmark_result = TRUE, store_models = FALSE, check_values = FALSE, - callbacks = list(), + callbacks = NULL, ties_method = "least_features" ) } @@ -30,7 +30,7 @@ Uninstantiated resamplings are instantiated during construction so that all feat Already instantiated resamplings are kept unchanged.} \item{measures}{(\link[mlr3:Measure]{mlr3::Measure} or list of \link[mlr3:Measure]{mlr3::Measure})\cr -A single measure creates a \link{FSelectInstanceSingleCrit} and multiple measures a \link{FSelectInstanceMultiCrit}. +A single measure creates a \link{FSelectInstanceBatchSingleCrit} and multiple measures a \link{FSelectInstanceBatchMultiCrit}. If \code{NULL}, default measure is used.} \item{terminator}{(\link{Terminator})\cr @@ -46,7 +46,7 @@ Store models in benchmark result?} Check the parameters before the evaluation and the results for validity?} -\item{callbacks}{(list of \link{CallbackFSelect})\cr +\item{callbacks}{(list of \link{CallbackBatchFSelect})\cr List of callbacks.} \item{ties_method}{(\code{character(1)})\cr @@ -58,7 +58,7 @@ The \code{random} method returns a random feature set from the best feature sets Ignored if multiple measures are used.} } \description{ -Function to construct a \link{FSelectInstanceSingleCrit} or \link{FSelectInstanceMultiCrit}. +Function to construct a \link{FSelectInstanceBatchSingleCrit} or \link{FSelectInstanceBatchMultiCrit}. } \section{Resources}{ diff --git a/man/mlr3fselect.backup.Rd b/man/mlr3fselect.backup.Rd index a0e5938c..5dcaa535 100644 --- a/man/mlr3fselect.backup.Rd +++ b/man/mlr3fselect.backup.Rd @@ -4,7 +4,7 @@ \alias{mlr3fselect.backup} \title{Backup Benchmark Result Callback} \description{ -This \link{CallbackFSelect} writes the \link[mlr3:BenchmarkResult]{mlr3::BenchmarkResult} after each batch to disk. +This \link{CallbackBatchFSelect} writes the \link[mlr3:BenchmarkResult]{mlr3::BenchmarkResult} after each batch to disk. } \examples{ clbk("mlr3fselect.backup", path = "backup.rds") diff --git a/man/mlr3fselect_assertions.Rd b/man/mlr3fselect_assertions.Rd new file mode 100644 index 00000000..172a3666 --- /dev/null +++ b/man/mlr3fselect_assertions.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/assertions.R +\name{mlr3fselect_assertions} +\alias{mlr3fselect_assertions} +\alias{assert_fselectors} +\alias{assert_fselector_async} +\alias{assert_fselector_batch} +\alias{assert_fselect_instance} +\alias{assert_fselect_instance_async} +\alias{assert_fselect_instance_batch} +\title{Assertion for mlr3fselect objects} +\usage{ +assert_fselectors(fselectors) + +assert_fselector_async(fselector) + +assert_fselector_batch(fselector) + +assert_fselect_instance(inst) + +assert_fselect_instance_async(inst) + +assert_fselect_instance_batch(inst) +} +\arguments{ +\item{fselectors}{(list of \link{FSelector}).} + +\item{fselector}{(\link{FSelectorBatch}).} + +\item{inst}{(\link{FSelectInstanceBatchSingleCrit} | \link{FSelectInstanceBatchMultiCrit}).} +} +\description{ +Most assertion functions ensure the right class attribute, and optionally additional properties. +} +\keyword{internal} diff --git a/man/mlr_fselectors.Rd b/man/mlr_fselectors.Rd index 798d30da..c103ca17 100644 --- a/man/mlr_fselectors.Rd +++ b/man/mlr_fselectors.Rd @@ -37,6 +37,7 @@ fs("random_search") Sugar functions: \code{\link[=fs]{fs()}}, \code{\link[=fss]{fss()}} Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, \code{\link{mlr_fselectors_genetic_search}}, diff --git a/man/mlr_fselectors_design_points.Rd b/man/mlr_fselectors_design_points.Rd index 03c455d8..b571ee71 100644 --- a/man/mlr_fselectors_design_points.Rd +++ b/man/mlr_fselectors_design_points.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorDesignPoints.R +% Please edit documentation in R/FSelectorBatchDesignPoints.R \name{mlr_fselectors_design_points} \alias{mlr_fselectors_design_points} -\alias{FSelectorDesignPoints} +\alias{FSelectorBatchDesignPoints} \title{Feature Selection with Design Points} \description{ Feature selection using user-defined feature sets. @@ -72,6 +72,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_exhaustive_search}}, \code{\link{mlr_fselectors_genetic_search}}, @@ -83,13 +84,13 @@ Other FSelector: } \concept{FSelector} \section{Super classes}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorFromOptimizer]{mlr3fselect::FSelectorFromOptimizer}} -> \code{FSelectorDesignPoints} +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{\link[mlr3fselect:FSelectorBatchFromOptimizerBatch]{mlr3fselect::FSelectorBatchFromOptimizerBatch}} -> \code{FSelectorBatchDesignPoints} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorDesignPoints-new}{\code{FSelectorDesignPoints$new()}} -\item \href{#method-FSelectorDesignPoints-clone}{\code{FSelectorDesignPoints$clone()}} +\item \href{#method-FSelectorBatchDesignPoints-new}{\code{FSelectorBatchDesignPoints$new()}} +\item \href{#method-FSelectorBatchDesignPoints-clone}{\code{FSelectorBatchDesignPoints$clone()}} } } \if{html}{\out{ @@ -98,27 +99,27 @@ Other FSelector:
  • mlr3fselect::FSelector$format()
  • mlr3fselect::FSelector$help()
  • mlr3fselect::FSelector$print()
  • -
  • mlr3fselect::FSelectorFromOptimizer$optimize()
  • +
  • mlr3fselect::FSelectorBatchFromOptimizerBatch$optimize()
  • }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorDesignPoints-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchDesignPoints-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorDesignPoints$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchDesignPoints$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorDesignPoints-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchDesignPoints-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorDesignPoints$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchDesignPoints$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_exhaustive_search.Rd b/man/mlr_fselectors_exhaustive_search.Rd index d103977c..4c473ce2 100644 --- a/man/mlr_fselectors_exhaustive_search.Rd +++ b/man/mlr_fselectors_exhaustive_search.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorExhaustiveSearch.R +% Please edit documentation in R/FSelectorBatchExhaustiveSearch.R \name{mlr_fselectors_exhaustive_search} \alias{mlr_fselectors_exhaustive_search} -\alias{FSelectorExhaustiveSearch} +\alias{FSelectorBatchExhaustiveSearch} \title{Feature Selection with Exhaustive Search} \description{ Feature Selection using the Exhaustive Search Algorithm. @@ -60,6 +60,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_genetic_search}}, @@ -70,14 +71,14 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorExhaustiveSearch} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchExhaustiveSearch} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorExhaustiveSearch-new}{\code{FSelectorExhaustiveSearch$new()}} -\item \href{#method-FSelectorExhaustiveSearch-clone}{\code{FSelectorExhaustiveSearch$clone()}} +\item \href{#method-FSelectorBatchExhaustiveSearch-new}{\code{FSelectorBatchExhaustiveSearch$new()}} +\item \href{#method-FSelectorBatchExhaustiveSearch-clone}{\code{FSelectorBatchExhaustiveSearch$clone()}} } } \if{html}{\out{ @@ -85,28 +86,28 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorExhaustiveSearch-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchExhaustiveSearch-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorExhaustiveSearch$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchExhaustiveSearch$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorExhaustiveSearch-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchExhaustiveSearch-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorExhaustiveSearch$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchExhaustiveSearch$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_genetic_search.Rd b/man/mlr_fselectors_genetic_search.Rd index 7aae3d9a..22bd8f6d 100644 --- a/man/mlr_fselectors_genetic_search.Rd +++ b/man/mlr_fselectors_genetic_search.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorGeneticSearch.R +% Please edit documentation in R/FSelectorBatchGeneticSearch.R \name{mlr_fselectors_genetic_search} \alias{mlr_fselectors_genetic_search} -\alias{FSelectorGeneticSearch} +\alias{FSelectorBatchGeneticSearch} \title{Feature Selection with Genetic Search} \description{ Feature selection using the Genetic Algorithm from the package \CRANpkg{genalg}. @@ -54,6 +54,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -64,14 +65,14 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorGeneticSearch} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchGeneticSearch} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorGeneticSearch-new}{\code{FSelectorGeneticSearch$new()}} -\item \href{#method-FSelectorGeneticSearch-clone}{\code{FSelectorGeneticSearch$clone()}} +\item \href{#method-FSelectorBatchGeneticSearch-new}{\code{FSelectorBatchGeneticSearch$new()}} +\item \href{#method-FSelectorBatchGeneticSearch-clone}{\code{FSelectorBatchGeneticSearch$clone()}} } } \if{html}{\out{ @@ -79,28 +80,28 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorGeneticSearch-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchGeneticSearch-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorGeneticSearch$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchGeneticSearch$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorGeneticSearch-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchGeneticSearch-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorGeneticSearch$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchGeneticSearch$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_random_search.Rd b/man/mlr_fselectors_random_search.Rd index b400883c..1c2cae99 100644 --- a/man/mlr_fselectors_random_search.Rd +++ b/man/mlr_fselectors_random_search.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorRandomSearch.R +% Please edit documentation in R/FSelectorBatchRandomSearch.R \name{mlr_fselectors_random_search} \alias{mlr_fselectors_random_search} -\alias{FSelectorRandomSearch} +\alias{FSelectorBatchRandomSearch} \title{Feature Selection with Random Search} \source{ Bergstra J, Bengio Y (2012). @@ -68,6 +68,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -78,14 +79,14 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorRandomSearch} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchRandomSearch} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorRandomSearch-new}{\code{FSelectorRandomSearch$new()}} -\item \href{#method-FSelectorRandomSearch-clone}{\code{FSelectorRandomSearch$clone()}} +\item \href{#method-FSelectorBatchRandomSearch-new}{\code{FSelectorBatchRandomSearch$new()}} +\item \href{#method-FSelectorBatchRandomSearch-clone}{\code{FSelectorBatchRandomSearch$clone()}} } } \if{html}{\out{ @@ -93,28 +94,28 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRandomSearch-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRandomSearch-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRandomSearch$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRandomSearch$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRandomSearch-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRandomSearch-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRandomSearch$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRandomSearch$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_rfe.Rd b/man/mlr_fselectors_rfe.Rd index ef1c8510..7be53d8a 100644 --- a/man/mlr_fselectors_rfe.Rd +++ b/man/mlr_fselectors_rfe.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorRFE.R +% Please edit documentation in R/FSelectorBatchRFE.R \name{mlr_fselectors_rfe} \alias{mlr_fselectors_rfe} -\alias{FSelectorRFE} +\alias{FSelectorBatchRFE} \title{Feature Selection with Recursive Feature Elimination} \source{ Guyon I, Weston J, Barnhill S, Vapnik V (2002). @@ -32,7 +32,7 @@ Averaging the scores is not appropriate for most importance measures. } \section{Archive}{ -The \link{ArchiveFSelect} holds the following additional columns: +The \link{ArchiveBatchFSelect} holds the following additional columns: \itemize{ \item \code{"importance"} (\code{numeric()})\cr The importance score vector of the feature subset. @@ -110,6 +110,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -120,14 +121,14 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorRFE} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchRFE} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorRFE-new}{\code{FSelectorRFE$new()}} -\item \href{#method-FSelectorRFE-clone}{\code{FSelectorRFE$clone()}} +\item \href{#method-FSelectorBatchRFE-new}{\code{FSelectorBatchRFE$new()}} +\item \href{#method-FSelectorBatchRFE-clone}{\code{FSelectorBatchRFE$clone()}} } } \if{html}{\out{ @@ -135,28 +136,28 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRFE-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRFE-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRFE$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRFE$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRFE-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRFE-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRFE$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRFE$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_rfecv.Rd b/man/mlr_fselectors_rfecv.Rd index c32fcf3b..eb7e3d56 100644 --- a/man/mlr_fselectors_rfecv.Rd +++ b/man/mlr_fselectors_rfecv.Rd @@ -1,12 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorRFECV.R +% Please edit documentation in R/FSelectorBatchRFECV.R \name{mlr_fselectors_rfecv} \alias{mlr_fselectors_rfecv} -\alias{FSelectorRFECV} +\alias{FSelectorBatchRFECV} \title{Feature Selection with Recursive Feature Elimination with Cross Validation} \description{ Feature selection using the Recursive Feature Elimination with Cross-Validation (RFE-CV) algorithm. -See \link{FSelectorRFE} for a description of the base algorithm. +See \link{FSelectorBatchRFE} for a description of the base algorithm. RFE-CV runs a recursive feature elimination in each iteration of a cross-validation to determine the optimal number of features. Then a recursive feature elimination is run again on the complete dataset with the optimal number of features as the final feature set size. The performance of the optimal feature set is calculated on the complete data set and should not be reported as the performance of the final model. @@ -24,7 +24,7 @@ It is not necessary to set a termination criterion. } \section{Archive}{ -The \link{ArchiveFSelect} holds the following additional columns: +The \link{ArchiveBatchFSelect} holds the following additional columns: \itemize{ \item \code{"iteration"} (\code{integer(1)})\cr The resampling iteration in which the feature subset was evaluated. @@ -101,6 +101,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -111,14 +112,14 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorRFECV} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchRFECV} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorRFECV-new}{\code{FSelectorRFECV$new()}} -\item \href{#method-FSelectorRFECV-clone}{\code{FSelectorRFECV$clone()}} +\item \href{#method-FSelectorBatchRFECV-new}{\code{FSelectorBatchRFECV$new()}} +\item \href{#method-FSelectorBatchRFECV-clone}{\code{FSelectorBatchRFECV$clone()}} } } \if{html}{\out{ @@ -126,28 +127,28 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRFECV-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRFECV-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRFECV$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRFECV$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorRFECV-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchRFECV-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorRFECV$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchRFECV$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_sequential.Rd b/man/mlr_fselectors_sequential.Rd index 6054b323..4cf5553d 100644 --- a/man/mlr_fselectors_sequential.Rd +++ b/man/mlr_fselectors_sequential.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorSequential.R +% Please edit documentation in R/FSelectorBatchSequential.R \name{mlr_fselectors_sequential} \alias{mlr_fselectors_sequential} -\alias{FSelectorSequential} +\alias{FSelectorBatchSequential} \title{Feature Selection with Sequential Search} \description{ Feature selection using Sequential Search Algorithm. @@ -65,6 +65,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -75,15 +76,15 @@ Other FSelector: \code{\link{mlr_fselectors_shadow_variable_search}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorSequential} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchSequential} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorSequential-new}{\code{FSelectorSequential$new()}} -\item \href{#method-FSelectorSequential-optimization_path}{\code{FSelectorSequential$optimization_path()}} -\item \href{#method-FSelectorSequential-clone}{\code{FSelectorSequential$clone()}} +\item \href{#method-FSelectorBatchSequential-new}{\code{FSelectorBatchSequential$new()}} +\item \href{#method-FSelectorBatchSequential-optimization_path}{\code{FSelectorBatchSequential$optimization_path()}} +\item \href{#method-FSelectorBatchSequential-clone}{\code{FSelectorBatchSequential$clone()}} } } \if{html}{\out{ @@ -91,35 +92,35 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorSequential-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchSequential-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class.` \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorSequential$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchSequential$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorSequential-optimization_path}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchSequential-optimization_path}{}}} \subsection{Method \code{optimization_path()}}{ Returns the optimization path. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorSequential$optimization_path(inst, include_uhash = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchSequential$optimization_path(inst, include_uhash = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ \if{html}{\out{
    }} \describe{ -\item{\code{inst}}{(\link{FSelectInstanceSingleCrit})\cr -Instance optimized with \link{FSelectorSequential}.} +\item{\code{inst}}{(\link{FSelectInstanceBatchSingleCrit})\cr +Instance optimized with \link{FSelectorBatchSequential}.} \item{\code{include_uhash}}{(\code{logical(1)})\cr Include \code{uhash} column?} @@ -131,12 +132,12 @@ Include \code{uhash} column?} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorSequential-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchSequential-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorSequential$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchSequential$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/man/mlr_fselectors_shadow_variable_search.Rd b/man/mlr_fselectors_shadow_variable_search.Rd index 7302af96..10dee876 100644 --- a/man/mlr_fselectors_shadow_variable_search.Rd +++ b/man/mlr_fselectors_shadow_variable_search.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSelectorShadowVariableSearch.R +% Please edit documentation in R/FSelectorBatchShadowVariableSearch.R \name{mlr_fselectors_shadow_variable_search} \alias{mlr_fselectors_shadow_variable_search} -\alias{FSelectorShadowVariableSearch} +\alias{FSelectorBatchShadowVariableSearch} \title{Feature Selection with Shadow Variable Search} \source{ Thomas J, Hepp T, Mayr A, Bischl B (2017). @@ -69,6 +69,7 @@ learner$train(task) } \seealso{ Other FSelector: +\code{\link{FSelector}}, \code{\link{mlr_fselectors}}, \code{\link{mlr_fselectors_design_points}}, \code{\link{mlr_fselectors_exhaustive_search}}, @@ -79,15 +80,15 @@ Other FSelector: \code{\link{mlr_fselectors_sequential}} } \concept{FSelector} -\section{Super class}{ -\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{FSelectorShadowVariableSearch} +\section{Super classes}{ +\code{\link[mlr3fselect:FSelector]{mlr3fselect::FSelector}} -> \code{\link[mlr3fselect:FSelectorBatch]{mlr3fselect::FSelectorBatch}} -> \code{FSelectorBatchShadowVariableSearch} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-FSelectorShadowVariableSearch-new}{\code{FSelectorShadowVariableSearch$new()}} -\item \href{#method-FSelectorShadowVariableSearch-optimization_path}{\code{FSelectorShadowVariableSearch$optimization_path()}} -\item \href{#method-FSelectorShadowVariableSearch-clone}{\code{FSelectorShadowVariableSearch$clone()}} +\item \href{#method-FSelectorBatchShadowVariableSearch-new}{\code{FSelectorBatchShadowVariableSearch$new()}} +\item \href{#method-FSelectorBatchShadowVariableSearch-optimization_path}{\code{FSelectorBatchShadowVariableSearch$optimization_path()}} +\item \href{#method-FSelectorBatchShadowVariableSearch-clone}{\code{FSelectorBatchShadowVariableSearch$clone()}} } } \if{html}{\out{ @@ -95,35 +96,35 @@ Other FSelector: }} \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorShadowVariableSearch-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchShadowVariableSearch-new}{}}} \subsection{Method \code{new()}}{ Creates a new instance of this \link[R6:R6Class]{R6} class.` \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorShadowVariableSearch$new()}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchShadowVariableSearch$new()}\if{html}{\out{
    }} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorShadowVariableSearch-optimization_path}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchShadowVariableSearch-optimization_path}{}}} \subsection{Method \code{optimization_path()}}{ Returns the optimization path. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorShadowVariableSearch$optimization_path(inst)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchShadowVariableSearch$optimization_path(inst)}\if{html}{\out{
    }} } \subsection{Arguments}{ \if{html}{\out{
    }} \describe{ -\item{\code{inst}}{(\link{FSelectInstanceSingleCrit})\cr -Instance optimized with \link{FSelectorShadowVariableSearch}.} +\item{\code{inst}}{(\link{FSelectInstanceBatchSingleCrit})\cr +Instance optimized with \link{FSelectorBatchShadowVariableSearch}.} } \if{html}{\out{
    }} } @@ -132,12 +133,12 @@ Instance optimized with \link{FSelectorShadowVariableSearch}.} } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FSelectorShadowVariableSearch-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FSelectorBatchShadowVariableSearch-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FSelectorShadowVariableSearch$clone(deep = FALSE)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FSelectorBatchShadowVariableSearch$clone(deep = FALSE)}\if{html}{\out{
    }} } \subsection{Arguments}{ diff --git a/tests/testthat/test_ArchiveFSelect.R b/tests/testthat/test_ArchiveFSelect.R index cb36f4a2..e5b9b2d6 100644 --- a/tests/testthat/test_ArchiveFSelect.R +++ b/tests/testthat/test_ArchiveFSelect.R @@ -1,4 +1,4 @@ -test_that("ArchiveFSelect access methods work", { +test_that("ArchiveBatchFSelect access methods work", { instance = fselect( fselector = fs("random_search"), task = tsk("iris"), @@ -50,7 +50,7 @@ test_that("ArchiveFSelect access methods work", { # }) }) -test_that("ArchiveFSelect as.data.table function works", { +test_that("ArchiveBatchFSelect as.data.table function works", { instance = fselect( fselector = fs("random_search", batch_size = 4), task = tsk("pima"), @@ -102,7 +102,7 @@ test_that("ArchiveFSelect as.data.table function works", { "runtime_learners", "timestamp", "batch_nr", "warnings", "errors", "features", "n_features", "resample_result")) # without benchmark result - instance = FSelectInstanceSingleCrit$new( + instance = FSelectInstanceBatchSingleCrit$new( task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp("holdout"), @@ -118,7 +118,7 @@ test_that("ArchiveFSelect as.data.table function works", { "runtime_learners", "timestamp", "batch_nr", "warnings", "errors", "features", "n_features")) # empty archive - instance = FSelectInstanceSingleCrit$new( + instance = FSelectInstanceBatchSingleCrit$new( task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp("holdout"), diff --git a/tests/testthat/test_AutoFSelector.R b/tests/testthat/test_AutoFSelector.R index 06abe41d..58df4180 100644 --- a/tests/testthat/test_AutoFSelector.R +++ b/tests/testthat/test_AutoFSelector.R @@ -73,7 +73,7 @@ test_that("store_fselect_instance, store_benchmark_result and store_models flags store_models = TRUE) at$train(task) - expect_r6(at$fselect_instance, "FSelectInstanceSingleCrit") + expect_r6(at$fselect_instance, "FSelectInstanceBatchSingleCrit") expect_benchmark_result(at$fselect_instance$archive$benchmark_result) expect_class(at$fselect_instance$archive$benchmark_result$resample_result(1)$learners[[1]]$model, "rpart") @@ -82,7 +82,7 @@ test_that("store_fselect_instance, store_benchmark_result and store_models flags store_models = FALSE) at$train(task) - expect_r6(at$fselect_instance, "FSelectInstanceSingleCrit") + expect_r6(at$fselect_instance, "FSelectInstanceBatchSingleCrit") expect_benchmark_result(at$fselect_instance$archive$benchmark_result) expect_null(at$fselect_instance$archive$benchmark_result$resample_result(1)$learners[[1]]$model) @@ -91,7 +91,7 @@ test_that("store_fselect_instance, store_benchmark_result and store_models flags store_models = FALSE) at$train(task) - expect_r6(at$fselect_instance, "FSelectInstanceSingleCrit") + expect_r6(at$fselect_instance, "FSelectInstanceBatchSingleCrit") expect_equal(at$fselect_instance$archive$benchmark_result$n_resample_results, 0L) at = AutoFSelector$new(lrn("classif.rpart"), rsmp("holdout"), ms, te, @@ -106,7 +106,7 @@ test_that("store_fselect_instance, store_benchmark_result and store_models flags store_models = TRUE) at$train(task) - expect_r6(at$fselect_instance, "FSelectInstanceSingleCrit") + expect_r6(at$fselect_instance, "FSelectInstanceBatchSingleCrit") expect_benchmark_result(at$fselect_instance$archive$benchmark_result) expect_class(at$fselect_instance$archive$benchmark_result$resample_result(1)$learners[[1]]$model, "rpart") @@ -115,7 +115,7 @@ test_that("store_fselect_instance, store_benchmark_result and store_models flags store_models = FALSE) at$train(task) - expect_r6(at$fselect_instance, "FSelectInstanceSingleCrit") + expect_r6(at$fselect_instance, "FSelectInstanceBatchSingleCrit") expect_benchmark_result(at$fselect_instance$archive$benchmark_result) expect_null(at$fselect_instance$archive$benchmark_result$resample_result(1)$learners[[1]]$model) }) diff --git a/tests/testthat/test_FSelectInstanceMultiCrit.R b/tests/testthat/test_FSelectInstanceMultiCrit.R index 9f05588a..d78da7a3 100644 --- a/tests/testthat/test_FSelectInstanceMultiCrit.R +++ b/tests/testthat/test_FSelectInstanceMultiCrit.R @@ -1,4 +1,4 @@ -test_that("empty FSelectInstanceMultiCrit works", { +test_that("empty FSelectInstanceBatchMultiCrit works", { inst = TEST_MAKE_INST_2D() expect_data_table(inst$archive$data, nrows = 0L) diff --git a/tests/testthat/test_FSelectInstanceSingleCrit.R b/tests/testthat/test_FSelectInstanceSingleCrit.R index a9401f8c..44c7d7d9 100644 --- a/tests/testthat/test_FSelectInstanceSingleCrit.R +++ b/tests/testthat/test_FSelectInstanceSingleCrit.R @@ -1,4 +1,4 @@ -test_that("empty FSelectInstanceSingleCrit works", { +test_that("empty FSelectInstanceBatchSingleCrit works", { inst = TEST_MAKE_INST_1D() expect_data_table(inst$archive$data, nrows = 0L) diff --git a/tests/testthat/test_ObjectiveFSelect.R b/tests/testthat/test_ObjectiveFSelect.R index 6172434d..4b46c107 100644 --- a/tests/testthat/test_ObjectiveFSelect.R +++ b/tests/testthat/test_ObjectiveFSelect.R @@ -1,12 +1,12 @@ -test_that("ObjectiveFSelect", { +test_that("ObjectiveFSelectBatch", { task = TEST_MAKE_TSK() learner = lrn("regr.rpart") resampling = rsmp("holdout") measures = msr("dummy") - archive = ArchiveFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) + archive = ArchiveBatchFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) - obj = ObjectiveFSelect$new(task = task, learner = learner, resampling = resampling, measures = measures, archive = archive) + obj = ObjectiveFSelectBatch$new(task = task, learner = learner, resampling = resampling, measures = measures, archive = archive) xss = list( list("x1" = TRUE, "x2" = FALSE, "x3" = TRUE, "x4" = TRUE), @@ -19,14 +19,14 @@ test_that("ObjectiveFSelect", { expect_null(obj$archive$benchmark_result$resample_result(1)$learners[[1]]$model) }) -test_that("ObjectiveFSelect works with multiple measures", { +test_that("ObjectiveFSelectBatch works with multiple measures", { task = TEST_MAKE_TSK() learner = lrn("regr.rpart") resampling = rsmp("holdout") measures = msrs(c("regr.mse", "regr.rmse")) - archive = ArchiveFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) - obj = ObjectiveFSelect$new(task = task, learner = learner, resampling = resampling, measures = measures, archive = archive) + archive = ArchiveBatchFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) + obj = ObjectiveFSelectBatch$new(task = task, learner = learner, resampling = resampling, measures = measures, archive = archive) xss = list( list("x1" = TRUE, "x2" = FALSE, "x3" = TRUE, "x4" = TRUE), @@ -36,14 +36,14 @@ test_that("ObjectiveFSelect works with multiple measures", { expect_data_table(z, nrows = 2, ncols = 6) }) -test_that("ObjectiveFSelect works with store_models", { +test_that("ObjectiveFSelectBatch works with store_models", { task = TEST_MAKE_TSK() learner = lrn("regr.rpart") resampling = rsmp("holdout") measures = msr("dummy") - archive = ArchiveFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) - obj = ObjectiveFSelect$new(task = task, learner = learner, + archive = ArchiveBatchFSelect$new(search_space = task_to_domain(task), codomain = measures_to_codomain(measures)) + obj = ObjectiveFSelectBatch$new(task = task, learner = learner, resampling = resampling, measures = measures, archive = archive, store_models = TRUE) diff --git a/tests/testthat/test_fselect.R b/tests/testthat/test_fselect.R index 6e83c196..14a2ed1f 100644 --- a/tests/testthat/test_fselect.R +++ b/tests/testthat/test_fselect.R @@ -2,7 +2,7 @@ test_that("fselect function works with single measure", { instance = fselect(fselector = fs("random_search", batch_size = 1), task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp ("holdout"), measures = msr("classif.ce"), term_evals = 2) - expect_class(instance, "FSelectInstanceSingleCrit") + expect_class(instance, "FSelectInstanceBatchSingleCrit") expect_data_table(instance$archive$data, nrows = 2) expect_class(instance$terminator, "TerminatorEvals") }) @@ -11,7 +11,7 @@ test_that("fselect function works with multiple measures", { instance = fselect(fselector = fs("random_search", batch_size = 1), task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp ("holdout"), measures = msrs(c("classif.ce", "classif.acc")), term_evals = 2) - expect_class(instance, "FSelectInstanceMultiCrit") + expect_class(instance, "FSelectInstanceBatchMultiCrit") expect_data_table(instance$archive$data, nrows = 2) expect_class(instance$terminator, "TerminatorEvals") }) @@ -20,27 +20,27 @@ test_that("fselect function accepts string input for method", { instance = fselect(fselector = fs("random_search", batch_size = 1), task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp ("holdout"), measures = msr("classif.ce"), term_evals = 2) - expect_class(instance, "FSelectInstanceSingleCrit") + expect_class(instance, "FSelectInstanceBatchSingleCrit") expect_data_table(instance$archive$data, nrows = 2) expect_class(instance$terminator, "TerminatorEvals") }) -test_that("fselect interface is equal to FSelectInstanceSingleCrit", { +test_that("fselect interface is equal to FSelectInstanceBatchSingleCrit", { fselect_args = formalArgs(fselect) fselect_args = fselect_args[fselect_args != "fselector"] fselect_args[fselect_args == "measures"] = "measure" - instance_args = formalArgs(FSelectInstanceSingleCrit$public_methods$initialize) + instance_args = formalArgs(FSelectInstanceBatchSingleCrit$public_methods$initialize) instance_args = c(instance_args, "term_evals", "term_time") expect_set_equal(fselect_args, instance_args) }) -test_that("fselect interface is equal to FSelectInstanceMultiCrit", { +test_that("fselect interface is equal to FSelectInstanceBatchMultiCrit", { fselect_args = formalArgs(fselect) fselect_args = fselect_args[fselect_args %nin% c("fselector", "ties_method")] - instance_args = formalArgs(FSelectInstanceMultiCrit$public_methods$initialize) + instance_args = formalArgs(FSelectInstanceBatchMultiCrit$public_methods$initialize) instance_args = c(instance_args, "term_evals", "term_time") expect_set_equal(fselect_args, instance_args) diff --git a/tests/testthat/test_fsi.R b/tests/testthat/test_fsi.R index 1c53b18a..b07a5191 100644 --- a/tests/testthat/test_fsi.R +++ b/tests/testthat/test_fsi.R @@ -1,28 +1,28 @@ -test_that("fsi function creates a FSelectInstanceSingleCrit", { +test_that("fsi function creates a FSelectInstanceBatchSingleCrit", { instance = fsi( task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp ("holdout"), measures = msr("classif.ce"), terminator = trm("evals", n_evals = 2)) - expect_class(instance, "FSelectInstanceSingleCrit") + expect_class(instance, "FSelectInstanceBatchSingleCrit") }) -test_that("fsi function creates a FSelectInstanceMultiCrit", { +test_that("fsi function creates a FSelectInstanceBatchMultiCrit", { instance = fsi( task = tsk("pima"), learner = lrn("classif.rpart"), resampling = rsmp ("holdout"), measures = msrs(c("classif.ce", "classif.acc")), terminator = trm("evals", n_evals = 2)) - expect_class(instance, "FSelectInstanceMultiCrit") + expect_class(instance, "FSelectInstanceBatchMultiCrit") }) -test_that("fsi and FSelectInstanceSingleCrit are equal", { +test_that("fsi and FSelectInstanceBatchSingleCrit are equal", { fsi_args = formalArgs(fsi) fsi_args[fsi_args == "measures"] = "measure" - expect_equal(fsi_args, formalArgs(FSelectInstanceSingleCrit$public_methods$initialize)) + expect_equal(fsi_args, formalArgs(FSelectInstanceBatchSingleCrit$public_methods$initialize)) task = tsk("pima") learner = lrn("classif.rpart") @@ -35,17 +35,17 @@ test_that("fsi and FSelectInstanceSingleCrit are equal", { callbacks = clbk("mlr3fselect.backup") resampling$instantiate(task) - instance_1 = FSelectInstanceSingleCrit$new(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) + instance_1 = FSelectInstanceBatchSingleCrit$new(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) instance_2 = fsi(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) expect_equal(instance_1, instance_2) }) -test_that("fsi and FSelectInstanceMultiCrit are equal", { +test_that("fsi and FSelectInstanceBatchMultiCrit are equal", { fsi_args = formalArgs(fsi) fsi_args = fsi_args[fsi_args != "ties_method"] - expect_equal(fsi_args, formalArgs(FSelectInstanceMultiCrit$public_methods$initialize)) + expect_equal(fsi_args, formalArgs(FSelectInstanceBatchMultiCrit$public_methods$initialize)) task = tsk("pima") learner = lrn("classif.rpart") @@ -58,7 +58,7 @@ test_that("fsi and FSelectInstanceMultiCrit are equal", { callbacks = clbk("mlr3fselect.backup") resampling$instantiate(task) - instance_1 = FSelectInstanceMultiCrit$new(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) + instance_1 = FSelectInstanceBatchMultiCrit$new(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) instance_2 = fsi(task, learner, resampling, measures, terminator, store_benchmark_result, store_models, check_values, callbacks) expect_equal(instance_1, instance_2) From 6270d935913b0c24e8e80de6bb2cc3e9b432157d Mon Sep 17 00:00:00 2001 From: be-marc Date: Fri, 10 May 2024 10:04:32 +0200 Subject: [PATCH 2/2] docs: fix examples --- R/FSelectInstanceBatchMultiCrit.R | 2 +- R/FSelectInstanceBatchSingleCrit.R | 2 +- R/mlr_fselectors.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/FSelectInstanceBatchMultiCrit.R b/R/FSelectInstanceBatchMultiCrit.R index d4491071..a710107c 100644 --- a/R/FSelectInstanceBatchMultiCrit.R +++ b/R/FSelectInstanceBatchMultiCrit.R @@ -101,7 +101,7 @@ FSelectInstanceBatchMultiCrit = R6Class("FSelectInstanceBatchMultiCrit", set(xdt, j = "features", value = list(features)) set(xdt, j = "n_features", value = length(features[[1L]])) super$assign_result(xdt, ydt) - set(private$.result, j = "x_domain", value = NULL) + if (!is.null(private$.result$x_domain)) set(private$.result, j = "x_domain", value = NULL) }, #' @description diff --git a/R/FSelectInstanceBatchSingleCrit.R b/R/FSelectInstanceBatchSingleCrit.R index 0227d4b3..cc1be330 100644 --- a/R/FSelectInstanceBatchSingleCrit.R +++ b/R/FSelectInstanceBatchSingleCrit.R @@ -145,7 +145,7 @@ FSelectInstanceBatchSingleCrit = R6Class("FSelectInstanceBatchSingleCrit", set(xdt, j = "features", value = list(features)) set(xdt, j = "n_features", value = length(features[[1L]])) super$assign_result(xdt, y) - set(private$.result, j = "x_domain", value = NULL) + if (!is.null(private$.result$x_domain)) set(private$.result, j = "x_domain", value = NULL) }, #' @description diff --git a/R/mlr_fselectors.R b/R/mlr_fselectors.R index 9f2eda6b..1cfe0a3b 100644 --- a/R/mlr_fselectors.R +++ b/R/mlr_fselectors.R @@ -25,7 +25,7 @@ #' #' @export #' @examples -#' as.data.table(mlr_fselectors)x +#' as.data.table(mlr_fselectors) #' mlr_fselectors$get("random_search") #' fs("random_search") mlr_fselectors = R6Class("DictionaryFSelector",