Skip to content

Commit d82f305

Browse files
committed
some more fixes
1 parent aa00fee commit d82f305

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

R/GraphLearner.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner,
246246
.extract_internal_valid_scores = function() {
247247
if (!private$.can_internal_tuning) return(NULL)
248248
ivs = unlist(map(pos_with_property(self$graph_model, "validation"), "internal_valid_scores"), recursive = FALSE)
249-
if (is.null(ivs) || !length(ivs)) return(named_list())
249+
if (!length(ivs)) return(named_list())
250250
ivs
251251
},
252252
deep_clone = function(name, value) {
@@ -349,21 +349,27 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner,
349349
#' @export
350350
#' @examples
351351
#' library(mlr3)
352-
#' # simple
352+
#'
353353
#' glrn = as_learner(po("pca") %>>% lrn("classif.debug"))
354354
#' set_validate(glrn, 0.3)
355355
#' glrn$validate
356356
#' glrn$graph$pipeops$classif.debug$learner$validate
357+
#'
357358
#' set_validate(glrn, NULL)
358359
#' glrn$validate
359360
#' glrn$graph$pipeops$classif.debug$learner$validate
361+
#'
362+
#' set_validate(glrn, 0.2, ids = "classif.debug")
363+
#' glrn$validate
364+
#' glrn$graph$pipeops$classif.debug$learner$validate
360365
set_validate.GraphLearner = function(learner, validate, ids = NULL, args_all = list(), args = list(), ...) {
361366
prev_validate_pos = map(pos_with_property(learner$graph$pipeops, "validation"), "validate")
362367
prev_validate = learner$validate
363368
on.exit({
364369
iwalk(prev_validate_pos, function(prev_val, poid) {
365370
# Here we don't call into set_validate() as this also does not ensure that we are able to correctly
366-
# reset the configuration to the previous state and is less transparent
371+
# reset the configuration to the previous state, is less transparent and might fail again
372+
# The error message informs the user about this though via the calling handlers below
367373
learner$graph$pipeops[[poid]]$validate = prev_val
368374
})
369375
learner$validate = prev_validate
@@ -379,7 +385,7 @@ set_validate.GraphLearner = function(learner, validate, ids = NULL, args_all = l
379385
}
380386

381387
if (is.null(ids)) {
382-
ids = learner$base_learner(recursive = 1, return_po = TRUE)$id
388+
ids = learner$base_learner(return_po = TRUE)$id
383389
} else {
384390
assert_subset(ids, ids(pos_with_property(learner$graph$pipeops, "validation")))
385391
}

R/PipeOpLearner.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
#' For each `PipeOp` it is then only possible to either use it (`"predefined"`) or not use it (`NULL`).
7171
#' Also see [`set_validate.GraphLearner`] for more information.
7272
#' * `internal_tuned_values` :: named `list()` or `NULL`\cr
73-
#' The internally tuned values if the wrapped `Learner`s supports internal tuning, `NULL` otherwise.
73+
#' The internally tuned values if the wrapped `Learner` supports internal tuning, `NULL` otherwise.
7474
#' * `internal_valid_scores` :: named `list()` or `NULL`\cr
75-
#' The internal validation scores if the wrapped `Learner`s supports internal validation, `NULL` otherwise.
75+
#' The internal validation scores if the wrapped `Learner` supports internal validation, `NULL` otherwise.
7676
#' @section Methods:
7777
#' Methods inherited from [`PipeOp`].
7878
#'
@@ -210,7 +210,7 @@ mlr_pipeops$add("learner", PipeOpLearner, list(R6Class("Learner", public = list(
210210
set_validate.PipeOpLearner = function(learner, validate, ...) {
211211
assert_po_validate(validate)
212212
on.exit({
213-
# also does not work in general (e.g. for AutoTuner) and is even less transparent
213+
# don't use set_validate(), as it also does not work in general and might fail again
214214
learner$validate = prev_validate
215215
})
216216
prev_validate = learner$validate

R/utils.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ dictionary_sugar_inc_mget = function(dict, .keys, ...) {
135135
objs
136136
}
137137

138-
learner_wrapping_pipeops = function(x) {
139-
if (inherits(x, "Graph")) {
140-
x = x$pipeops
141-
} else if (inherits(x, "GraphLearner")) {
142-
x = x$graph$pipeops
143-
} else {
144-
assert_list(x, types = "PipeOp")
145-
}
146-
147-
keep(x, function(po) inherits(po, "PipeOpLearner") || inherits(po, "PipeOpLearnerCV"))
148-
}
149-
150138
pos_with_property = function(x, property) {
151139
x = if (test_class(x, "GraphLearner")) {
152140
x$graph$pipeops

man/mlr3pipelines-package.Rd

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

man/mlr_pipeops_learner.Rd

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

man/set_validate.GraphLearner.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)