Skip to content

Commit e7dad77

Browse files
committed
refactor: rename to least features and remove first option
1 parent ca61f35 commit e7dad77

File tree

10 files changed

+33
-49
lines changed

10 files changed

+33
-49
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Encoding: UTF-8
4545
Language: en-US
4646
NeedsCompilation: no
4747
Roxygen: list(markdown = TRUE)
48-
RoxygenNote: 7.2.3
48+
RoxygenNote: 7.2.3.9000
4949
Collate:
5050
'ArchiveFSelect.R'
5151
'AutoFSelector.R'

R/ArchiveFSelect.R

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,36 +159,29 @@ ArchiveFSelect = R6Class("ArchiveFSelect",
159159
#' Default is all batches.
160160
#' @param ties_method (`character(1)`)\cr
161161
#' Method to handle ties.
162-
#' Can be one of `n_features`, `first`, `random`.
163162
#' If `NULL` (default), the global ties method set during initialization is used.
164-
#' The default global ties method is `n_features` which selects the feature set with the least features.
165-
#' If there are multiple best feature sets with the same number of features, the first one is selected.
166-
#' The `first` method returns the first added best feature set.
163+
#' The default global ties method is `least_features` which selects the feature set with the least features.
164+
#' If there are multiple best feature sets with the same number of features, one is selected randomly.
167165
#' The `random` method returns a random feature set from the best feature sets.
168166
#
169167
#' @return [data.table::data.table()]
170168
best = function(batch = NULL, ties_method = NULL) {
171-
assert_choice(ties_method, c("first", "random", "n_features"), null.ok = TRUE)
172-
if (is.null(ties_method)) ties_method = self$ties_method
169+
ties_method = assert_choice(ties_method, c("least_features", "random"), null.ok = TRUE) %??% self$ties_method
173170
assert_subset(batch, seq_len(self$n_batch))
174171
if (self$n_batch == 0L) return(data.table())
175172

176-
if (is.null(batch)) {
177-
tab = self$data
178-
} else {
179-
tab = self$data[list(batch), , on = "batch_nr"]
180-
}
173+
tab = if (is.null(batch)) self$data else self$data[list(batch), , on = "batch_nr"]
181174

182175
if (self$codomain$target_length == 1L) {
183176
y = tab[[self$cols_y]] * -self$codomain$maximization_to_minimization
184177

185-
if (ties_method == "n_features") {
178+
if (ties_method == "least_features") {
186179
ii = which(y == max(y))
187180
tab = tab[ii]
188-
ii = which.min(rowSums(tab[, self$cols_x, with = FALSE]))
181+
ii = which_min(rowSums(tab[, self$cols_x, with = FALSE]), ties_method = "random")
189182
tab[ii]
190183
} else {
191-
ii = which_max(y, ties_method = ties_method)
184+
ii = which_max(y, ties_method = "random")
192185
tab[ii]
193186
}
194187
} else {
@@ -205,7 +198,7 @@ ArchiveFSelect = R6Class("ArchiveFSelect",
205198
#' Method to handle ties.
206199
ties_method = function(rhs) {
207200
if (!missing(rhs)) {
208-
assert_choice(rhs, c("first", "random", "n_features"))
201+
assert_choice(rhs, c("least_features", "random"))
209202
private$.ties_method = rhs
210203
} else {
211204
private$.ties_method

R/AutoFSelector.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ AutoFSelector = R6Class("AutoFSelector",
138138

139139
ia$check_values = assert_flag(check_values)
140140
ia$callbacks = assert_callbacks(as_callbacks(callbacks))
141-
ia$ties_method = assert_choice(ties_method, c("n_features", "first", "random"))
141+
ia$ties_method = assert_choice(ties_method, c("least_features", "random"))
142142
self$instance_args = ia
143143

144144
super$initialize(

man-roxygen/param_ties_method.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#' @param ties_method (`character(1)`)\cr
22
#' The method to break ties when selecting sets while optimizing and when selecting the best set.
3-
#' Can be one of `n_features`, `first`, `random`.
4-
#' The option `n_features` (default) selects the feature set with the least features.
5-
#' If there are multiple best feature sets with the same number of features, the first one is selected.
6-
#' The `first` method returns the first added best feature set.
3+
#' Can be `"least_features"` or `"random"`.
4+
#' The option `"least_features"` (default) selects the feature set with the least features.
5+
#' If there are multiple best feature sets with the same number of features, one is selected randomly.
76
#' The `random` method returns a random feature set from the best feature sets.
87
#' Ignored if multiple measures are used.

man/ArchiveFSelect.Rd

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/AutoFSelector.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/FSelectInstanceSingleCrit.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/auto_fselector.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fselect.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fsi.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)