Skip to content

Commit ca8123e

Browse files
authored
Merge pull request #752 from mlr-org/s3params_compat
check with new paradox
2 parents 044762e + 9c60738 commit ca8123e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+491
-398
lines changed

.github/workflows/dev-cmd-check.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# dev cmd check workflow of the mlr3 ecosystem v0.1.0
2+
# https://github.com/mlr-org/actions
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
12+
name: dev-check
13+
14+
jobs:
15+
check-package:
16+
runs-on: ${{ matrix.config.os }}
17+
18+
name: ${{ matrix.config.dev-package }}
19+
20+
env:
21+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
config:
27+
- {os: ubuntu-latest, r: 'release', dev-package: "mlr-org/bbotk', 'mlr-org/mlr3learners', 'mlr-org/paradox"}
28+
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- uses: r-lib/actions/setup-r@v2
33+
with:
34+
r-version: ${{ matrix.config.r }}
35+
36+
- uses: r-lib/actions/setup-r-dependencies@v2
37+
with:
38+
extra-packages: any::rcmdcheck
39+
needs: check
40+
41+
- name: Install dev versions
42+
run: pak::pkg_install(c('${{ matrix.config.dev-package }}'))
43+
shell: Rscript {0}
44+
45+
- uses: r-lib/actions/check-r-package@v2

R/LearnerAvg.R

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
LearnerClassifAvg = R6Class("LearnerClassifAvg", inherit = LearnerClassif,
5959
public = list(
6060
initialize = function(id = "classif.avg") {
61-
ps = ParamSet$new(params = list(
62-
ParamUty$new("measure", custom_check = check_class_or_character("MeasureClassif", mlr_measures), tags = "train"),
63-
ParamUty$new("optimizer", custom_check = check_optimizer, tags = "train"),
64-
ParamUty$new("log_level", tags = "train",
61+
ps = ps(
62+
measure = p_uty(custom_check = check_class_or_character("MeasureClassif", mlr_measures), tags = "train"),
63+
optimizer = p_uty(custom_check = check_optimizer, tags = "train"),
64+
log_level = p_uty(tags = "train",
6565
function(x) check_string(x) %check||% check_integerish(x))
66-
))
66+
)
6767
ps$values = list(measure = "classif.ce", optimizer = "nloptr", log_level = "warn")
6868
super$initialize(
6969
id = id,
@@ -132,12 +132,12 @@ LearnerClassifAvg = R6Class("LearnerClassifAvg", inherit = LearnerClassif,
132132
LearnerRegrAvg = R6Class("LearnerRegrAvg", inherit = LearnerRegr,
133133
public = list(
134134
initialize = function(id = "regr.avg") {
135-
ps = ParamSet$new(params = list(
136-
ParamUty$new("measure", custom_check = check_class_or_character("MeasureRegr", mlr_measures), tags = "train"),
137-
ParamUty$new("optimizer", custom_check = check_optimizer, tags = "train"),
138-
ParamUty$new("log_level", tags = "train",
135+
ps = ps(
136+
measure = p_uty(custom_check = check_class_or_character("MeasureRegr", mlr_measures), tags = "train"),
137+
optimizer = p_uty(custom_check = check_optimizer, tags = "train"),
138+
log_level = p_uty(tags = "train",
139139
function(x) check_string(x) %check||% check_integerish(x))
140-
))
140+
)
141141
ps$values = list(measure = "regr.mse", optimizer = "nloptr", log_level = "warn")
142142
super$initialize(
143143
id = id,
@@ -185,10 +185,9 @@ optimize_weights_learneravg = function(self, task, n_weights, data) {
185185
}
186186

187187
pars = self$param_set$get_values(tags = "train")
188-
ps = ParamSet$new(params = imap(data, function(x, n) {
189-
if (is.numeric(n)) n = paste0("w.", n)
190-
ParamDbl$new(id = n, lower = 0, upper = 1)
191-
}))
188+
pl = rep(list(p_dbl(0, 1)), length(data))
189+
names(pl) = names(data) %??% paste0("w.", seq_along(data))
190+
ps = do.call(ps, pl)
192191
optimizer = pars$optimizer
193192
if (inherits(optimizer, "character")) {
194193
optimizer = bbotk::opt(optimizer)
@@ -198,7 +197,7 @@ optimize_weights_learneravg = function(self, task, n_weights, data) {
198197
}
199198
measure = pars$measure
200199
if (is.character(measure)) measure = msr(measure)
201-
codomain = ParamSet$new(list(ParamDbl$new(id = measure$id, tags = ifelse(measure$minimize, "minimize", "maximize"))))
200+
codomain = do.call(paradox::ps, structure(list(p_dbl(tags = ifelse(measure$minimize, "minimize", "maximize"))), names = measure$id))
202201
objfun = bbotk::ObjectiveRFun$new(
203202
fun = function(xs) learneravg_objfun(xs, task = task, measure = measure, avg_weight_fun = self$weighted_average_prediction, data = data),
204203
domain = ps, codomain = codomain

R/PipeOp.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#'
3939
#' @section Construction:
4040
#' ```
41-
#' PipeOp$new(id, param_set = ParamSet$new(), param_vals = list(), input, output, packages = character(0), tags = character(0))
41+
#' PipeOp$new(id, param_set = ps(), param_vals = list(), input, output, packages = character(0), tags = character(0))
4242
#' ```
4343
#'
4444
#' * `id` :: `character(1)`\cr
@@ -236,7 +236,7 @@ PipeOp = R6Class("PipeOp",
236236
.result = NULL,
237237
tags = NULL,
238238

239-
initialize = function(id, param_set = ParamSet$new(), param_vals = list(), input, output, packages = character(0), tags = "abstract") {
239+
initialize = function(id, param_set = ps(), param_vals = list(), input, output, packages = character(0), tags = "abstract") {
240240
if (inherits(param_set, "ParamSet")) {
241241
private$.param_set = assert_param_set(param_set)
242242
private$.param_set_source = NULL
@@ -338,7 +338,7 @@ PipeOp = R6Class("PipeOp",
338338
id = function(val) {
339339
if (!missing(val)) {
340340
private$.id = val
341-
if (!is.null(private$.param_set)) {
341+
if (paradox_info$is_old && !is.null(private$.param_set)) {
342342
# private$.param_set may be NULL if it is constructed dynamically by active binding
343343
private$.param_set$set_id = val
344344
}
@@ -353,7 +353,7 @@ PipeOp = R6Class("PipeOp",
353353
} else {
354354
private$.param_set = sourcelist[[1]]
355355
}
356-
if (!is.null(self$id)) {
356+
if (paradox_info$is_old && !is.null(self$id)) {
357357
private$.param_set$set_id = self$id
358358
}
359359
}

R/PipeOpBoxCox.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ PipeOpBoxCox = R6Class("PipeOpBoxCox",
6565
inherit = PipeOpTaskPreproc,
6666
public = list(
6767
initialize = function(id = "boxcox", param_vals = list()) {
68-
ps = ParamSet$new(params = list(
69-
ParamLgl$new("standardize", default = TRUE, tags = c("train", "boxcox")),
70-
ParamDbl$new("eps", default = 0.001, lower = 0, tags = c("train", "boxcox")),
71-
ParamDbl$new("lower", tags = c("train", "boxcox")),
72-
ParamDbl$new("upper", tags = c("train", "boxcox"))
73-
))
68+
ps = ps(
69+
standardize = p_lgl(default = TRUE, tags = c("train", "boxcox")),
70+
eps = p_dbl(default = 0.001, lower = 0, tags = c("train", "boxcox")),
71+
lower = p_dbl(tags = c("train", "boxcox")),
72+
upper = p_dbl(tags = c("train", "boxcox"))
73+
)
7474
super$initialize(id, param_set = ps, param_vals = param_vals,
7575
packages = "bestNormalize", feature_types = c("numeric", "integer"))
7676
}

R/PipeOpBranch.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#' * `options` :: `numeric(1)` | `character`\cr
2020
#' If `options` is an integer number, it determines the number of
2121
#' output channels / options that are created, named `output1`...`output<n>`. The
22-
#' `$selection` parameter will then be a [`ParamInt`].
22+
#' `$selection` parameter will then be an integer.
2323
#' If `options` is a `character`, it determines the names of channels directly.
24-
#' The `$selection` parameter will then be a [`ParamFct`].
24+
#' The `$selection` parameter will then be factorial.
2525
#' * `id` :: `character(1)`\cr
2626
#' Identifier of resulting object, default `"branch"`.
2727
#' * `param_vals` :: named `list`\cr
@@ -90,14 +90,14 @@ PipeOpBranch = R6Class("PipeOpBranch",
9090
)
9191
if (is.numeric(options)) {
9292
options = round(options)
93-
param = ParamInt$new("selection", lower = 1L, upper = options, tags = c("train", "predict", "required"))
93+
param = p_int(lower = 1L, upper = options, tags = c("train", "predict", "required"))
9494
options = rep_suffix("output", options)
9595
initval = 1
9696
} else {
97-
param = ParamFct$new("selection", levels = options, tags = c("train", "predict", "required"))
97+
param = p_fct(options, tags = c("train", "predict", "required"))
9898
initval = options[1]
9999
}
100-
ps = ParamSet$new(params = list(param))
100+
ps = ps(selection = param)
101101
ps$values$selection = initval
102102
super$initialize(id, ps, param_vals,
103103
input = data.table(name = "input", train = "*", predict = "*"),

R/PipeOpChunk.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ PipeOpChunk = R6Class("PipeOpChunk",
6464
public = list(
6565
initialize = function(outnum, id = "chunk", param_vals = list()) {
6666
outnum = assert_int(outnum, lower = 1L)
67-
ps = ParamSet$new(params = list(
68-
ParamLgl$new("shuffle", tags = "train")
69-
))
67+
ps = ps(
68+
shuffle = p_lgl(tags = "train")
69+
)
7070
ps$values = list(shuffle = TRUE)
7171
super$initialize(id,
7272
param_set = ps, param_vals = param_vals,

R/PipeOpClassBalancing.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ PipeOpClassBalancing = R6Class("PipeOpClassBalancing",
104104

105105
public = list(
106106
initialize = function(id = "classbalancing", param_vals = list()) {
107-
ps = ParamSet$new(params = list(
108-
ParamDbl$new("ratio", lower = 0, upper = Inf, tags = "train"),
109-
ParamFct$new("reference",
110-
levels = c("all", "major", "minor", "nonmajor", "nonminor", "one"), tags = "train"),
111-
ParamFct$new("adjust",
112-
levels = c("all", "major", "minor", "nonmajor", "nonminor", "upsample", "downsample"), tags = "train"),
113-
ParamLgl$new("shuffle", tags = "train")
114-
))
107+
ps = ps(
108+
ratio = p_dbl(lower = 0, upper = Inf, tags = "train"),
109+
reference = p_fct(c("all", "major", "minor", "nonmajor", "nonminor", "one"), tags = "train"),
110+
adjust = p_fct(c("all", "major", "minor", "nonmajor", "nonminor", "upsample", "downsample"), tags = "train"),
111+
shuffle = p_lgl(tags = "train")
112+
)
115113
ps$values = list(ratio = 1, reference = "all", adjust = "all", shuffle = TRUE)
116114
super$initialize(id, param_set = ps, param_vals = param_vals, can_subset_cols = FALSE, task_type = "TaskClassif", tags = "imbalanced data")
117115
}

R/PipeOpClassWeights.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ PipeOpClassWeights = R6Class("PipeOpClassWeights",
7171

7272
public = list(
7373
initialize = function(id = "classweights", param_vals = list()) {
74-
ps = ParamSet$new(params = list(
75-
ParamDbl$new("minor_weight", lower = 0, upper = Inf, tags = "train")
76-
))
74+
ps = ps(
75+
minor_weight = p_dbl(lower = 0, upper = Inf, tags = "train")
76+
)
7777
ps$values = list(minor_weight = 1)
7878
super$initialize(id, param_set = ps, param_vals = param_vals, can_subset_cols = FALSE, task_type = "TaskClassif", tags = "imbalanced data")
7979
}

R/PipeOpColApply.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ PipeOpColApply = R6Class("PipeOpColApply",
9292
inherit = PipeOpTaskPreprocSimple,
9393
public = list(
9494
initialize = function(id = "colapply", param_vals = list()) {
95-
ps = ParamSet$new(params = list(
96-
ParamUty$new("applicator", custom_check = check_function, tags = c("train", "predict"))
97-
))
95+
ps = ps(
96+
applicator = p_uty(custom_check = check_function, tags = c("train", "predict"))
97+
)
9898
ps$values = list(applicator = identity)
9999
super$initialize(id, ps, param_vals = param_vals)
100100
}

R/PipeOpColRoles.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ PipeOpColRoles = R6Class("PipeOpColRoles",
5656
inherit = PipeOpTaskPreprocSimple,
5757
public = list(
5858
initialize = function(id = "colroles", param_vals = list()) {
59-
ps = ParamSet$new(params = list(
59+
ps = ps(
6060
# named list, each entry with a vector of roles
61-
ParamUty$new("new_role", tags = c("train", "predict"), custom_check = function(x) {
61+
new_role = p_uty(tags = c("train", "predict"), custom_check = function(x) {
6262
first_check = check_list(x, types = "character", any.missing = FALSE, min.len = 1L, names = "named")
6363
# return the error directly if this failed
6464
if (is.character(first_check)) {
@@ -69,7 +69,7 @@ PipeOpColRoles = R6Class("PipeOpColRoles",
6969
all_col_roles = unique(unlist(mlr3::mlr_reflections$task_col_roles))
7070
check_subset(unlist(x), all_col_roles[all_col_roles != "target"])
7171
})
72-
))
72+
)
7373
super$initialize(id, param_set = ps, param_vals = param_vals, can_subset_cols = FALSE)
7474
}
7575
),

R/PipeOpCollapseFactors.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ PipeOpCollapseFactors = R6Class("PipeOpCollapseFactors",
5959
inherit = PipeOpTaskPreprocSimple,
6060
public = list(
6161
initialize = function(id = "collapsefactors", param_vals = list()) {
62-
ps = ParamSet$new(params = list(
63-
ParamDbl$new("no_collapse_above_prevalence", 0, 1, tags = c("train", "predict")),
64-
ParamInt$new("target_level_count", 2, tags = c("train", "predict"))
65-
))
62+
ps = ps(
63+
no_collapse_above_prevalence = p_dbl(0, 1, tags = c("train", "predict")),
64+
target_level_count = p_int(2, tags = c("train", "predict"))
65+
)
6666
ps$values = list(no_collapse_above_prevalence = 1, target_level_count = 2)
6767
super$initialize(id, param_set = ps, param_vals = param_vals, feature_types = c("factor", "ordered"))
6868
}

R/PipeOpDateFeatures.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,20 @@ PipeOpDateFeatures = R6Class("PipeOpDateFeatures",
9898
inherit = PipeOpTaskPreprocSimple,
9999
public = list(
100100
initialize = function(id = "datefeatures", param_vals = list()) {
101-
ps = ParamSet$new(params = list(
102-
ParamLgl$new("keep_date_var", tags = c("train", "predict", "required")),
103-
ParamLgl$new("cyclic", tags = c("train", "predict", "required")),
104-
ParamLgl$new("year", tags = c("train", "predict", "datepart", "required")),
105-
ParamLgl$new("month", tags = c("train", "predict", "datepart", "required")),
106-
ParamLgl$new("week_of_year", tags = c("train", "predict", "datepart", "required")),
107-
ParamLgl$new("day_of_year", tags = c("train", "predict", "datepart", "required")),
108-
ParamLgl$new("day_of_month", tags = c("train", "predict", "datepart", "required")),
109-
ParamLgl$new("day_of_week", tags = c("train", "predict", "datepart", "required")),
110-
ParamLgl$new("hour", tags = c("train", "predict", "datepart", "required")),
111-
ParamLgl$new("minute", tags = c("train", "predict", "datepart", "required")),
112-
ParamLgl$new("second", tags = c("train", "predict", "datepart", "required")),
113-
ParamLgl$new("is_day", tags = c("train", "predict", "datepart", "required"))
114-
))
101+
ps = ps(
102+
keep_date_var = p_lgl(tags = c("train", "predict", "required")),
103+
cyclic = p_lgl(tags = c("train", "predict", "required")),
104+
year = p_lgl(tags = c("train", "predict", "datepart", "required")),
105+
month = p_lgl(tags = c("train", "predict", "datepart", "required")),
106+
week_of_year = p_lgl(tags = c("train", "predict", "datepart", "required")),
107+
day_of_year = p_lgl(tags = c("train", "predict", "datepart", "required")),
108+
day_of_month = p_lgl(tags = c("train", "predict", "datepart", "required")),
109+
day_of_week = p_lgl(tags = c("train", "predict", "datepart", "required")),
110+
hour = p_lgl(tags = c("train", "predict", "datepart", "required")),
111+
minute = p_lgl(tags = c("train", "predict", "datepart", "required")),
112+
second = p_lgl(tags = c("train", "predict", "datepart", "required")),
113+
is_day = p_lgl(tags = c("train", "predict", "datepart", "required"))
114+
)
115115
ps$values = list(keep_date_var = FALSE, cyclic = FALSE, year = TRUE,
116116
month = TRUE, week_of_year = TRUE, day_of_year = TRUE, day_of_month = TRUE,
117117
day_of_week = TRUE, hour = TRUE, minute = TRUE, second = TRUE, is_day = TRUE)

R/PipeOpEncode.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ PipeOpEncode = R6Class("PipeOpEncode",
8282
inherit = PipeOpTaskPreprocSimple,
8383
public = list(
8484
initialize = function(id = "encode", param_vals = list()) {
85-
ps = ParamSet$new(params = list(
86-
ParamFct$new("method", levels = c("one-hot", "treatment", "helmert", "poly", "sum"), tags = c("train", "predict"))
87-
))
85+
ps = ps(
86+
method = p_fct(levels = c("one-hot", "treatment", "helmert", "poly", "sum"), tags = c("train", "predict"))
87+
)
8888
ps$values = list(method = "one-hot")
8989
super$initialize(id, param_set = ps, param_vals = param_vals, packages = "stats", tags = "encode", feature_types = c("factor", "ordered"))
9090
}

R/PipeOpEncodeImpact.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ PipeOpEncodeImpact = R6Class("PipeOpEncodeImpact",
7777
inherit = PipeOpTaskPreprocSimple,
7878
public = list(
7979
initialize = function(id = "encodeimpact", param_vals = list()) {
80-
ps = ParamSet$new(params = list(
81-
ParamDbl$new("smoothing", 0, Inf, tags = c("train", "required")),
82-
ParamLgl$new("impute_zero", tags = c("train", "required"))
83-
))
80+
ps = ps(
81+
smoothing = p_dbl(0, Inf, tags = c("train", "required")),
82+
impute_zero = p_lgl(tags = c("train", "required"))
83+
)
8484
ps$values = list(smoothing = 1e-4, impute_zero = FALSE)
8585
super$initialize(id, param_set = ps, param_vals = param_vals, tags = "encode", feature_types = c("factor", "ordered"))
8686
}

R/PipeOpEncodeLmer.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ PipeOpEncodeLmer = R6Class("PipeOpEncodeLmer",
8888
inherit = PipeOpTaskPreprocSimple,
8989
public = list(
9090
initialize = function(id = "encodelmer", param_vals = list()) {
91-
ps = ParamSet$new(params = list(
92-
ParamLgl$new("fast_optim", tags = c("train", "required"))
93-
))
91+
ps = ps(
92+
fast_optim = p_lgl(tags = c("train", "required"))
93+
)
9494
ps$values = list(fast_optim = TRUE)
9595
super$initialize(id, param_set = ps, param_vals = param_vals, packages = c("lme4", "nloptr"), tags = "encode", feature_types = c("factor", "ordered"))
9696
}

R/PipeOpEnsemble.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @section Construction:
1111
#' Note: This object is typically constructed via a derived class, e.g. [`PipeOpClassifAvg`] or [`PipeOpRegrAvg`].
1212
#' ```
13-
#' PipeOpEnsemble$new(innum = 0, collect_multiplicity = FALSE, id, param_set = ParamSet$new(), param_vals = list(), packages = character(0), prediction_type = "Prediction")
13+
#' PipeOpEnsemble$new(innum = 0, collect_multiplicity = FALSE, id, param_set = ps(), param_vals = list(), packages = character(0), prediction_type = "Prediction")
1414
#' ```
1515
#'
1616
#' * `innum` :: `numeric(1)`\cr
@@ -82,9 +82,14 @@
8282
PipeOpEnsemble = R6Class("PipeOpEnsemble",
8383
inherit = PipeOp,
8484
public = list(
85-
initialize = function(innum = 0, collect_multiplicity = FALSE, id, param_set = ParamSet$new(), param_vals = list(), packages = character(0), prediction_type = "Prediction", tags = NULL) {
85+
initialize = function(innum = 0, collect_multiplicity = FALSE, id, param_set = ps(), param_vals = list(), packages = character(0), prediction_type = "Prediction", tags = NULL) {
8686
assert_integerish(innum, lower = 0)
87-
param_set$add(ParamUty$new("weights", custom_check = check_weights(innum), tags = "predict"))
87+
if (paradox_info$is_old) {
88+
paux = ps(weights = p_uty(check_weights(innum), tags = "predict"))
89+
param_set$add(paux$params$weights)
90+
} else {
91+
param_set = c(param_set, ps(weights = p_uty(check_weights(innum), tags = "predict")))
92+
}
8893
param_set$values$weights = 1
8994
inname = if (innum) rep_suffix("input", innum) else "..."
9095
intype = c("NULL", prediction_type)

0 commit comments

Comments
 (0)