Skip to content

Commit

Permalink
compatibility with new paradox (#341)
Browse files Browse the repository at this point in the history
* check with new paradox

* paradox argument tag -> tags

* use new paradox syntax

* default xor required

* dev cmd check with paradox master

* news

* fix xgboost parameter test

* ...

---------

Co-authored-by: Sebastian Fischer <sebf.fischer@gmail.com>
  • Loading branch information
mb706 and sebffischer authored Feb 28, 2024
1 parent 5dd745b commit 5baa86a
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 68 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/devcmdcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# r cmd check workflow of the mlr3 ecosystem v0.3.1
# https://github.com/mlr-org/actions
on:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled'
required: false
default: false
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 4 * * 1'

name: Dev Check

jobs:
check-package:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.dev-package }}

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-20.04, r: 'release', dev-package: "mlr-org/paradox', 'mlr-org/mlr3learners', 'mlr-org/mlr3pipelines', 'mlr-org/mlr3cluster"}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
with:
limit-access-to-actor: true

- name: Install Python packages
run: |
pak::pkg_install('reticulate')
reticulate::install_miniconda(force = TRUE)
reticulate::use_condaenv('r-reticulate')
install.packages('keras')
reticulate::py_install("pytorch-cpu")
reticulate::py_install("tensorflow-cpu", pip = TRUE)
survivalmodels::install_pycox(pip = TRUE, install_torch = FALSE)
survivalmodels::install_keras(pip = TRUE, install_tensorflow = FALSE)
shell: Rscript {0}

- name: Install dev versions
run: pak::pkg_install(c('${{ matrix.config.dev-package }}'))
shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ learners (thanks to @bblodfon)
* Fix: `I` and `F` params from IBk learner are too interdependent (`I` can only be `TRUE` when `F` is `FALSE` and vice versa).
Combined them into one factor param `weight` that has two levels -- `I` and `F`.
* Fix: `U` must be `FALSE` for `S` to be tunable in J48 learner.
* Compatibility with upcoming 'paradox' release.

# mlr3extralearners 0.7.1

Expand Down
20 changes: 9 additions & 11 deletions R/learner_Cubist_regr_cubist.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ LearnerRegrCubist = R6Class("LearnerRegrCubist",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
# FIXME:
param_set = ParamSet$new(
list(
ParamInt$new("committees", lower = 1L, upper = 100L, default = 1L, tags = c("train", "required")),
ParamLgl$new("unbiased", default = FALSE, tags = "train"),
ParamInt$new("rules", lower = 1L, default = 100L, tags = "train"),
ParamDbl$new("extrapolation", lower = 0, upper = 100, default = 100, tags = "train"),
ParamInt$new("sample", lower = 0L, default = 0L, tags = "train"),
ParamInt$new("seed", default = NO_DEF, tags = "train"),
ParamUty$new("label", default = "outcome", tags = "train"),
ParamInt$new("neighbors", lower = 0L, upper = 9L, default = 0L, tags = c("predict", "required"))
param_set = ps(
committees = p_int(lower = 1L, upper = 100L, tags = c("train", "required")),
unbiased = p_lgl(default = FALSE, tags = "train"),
rules = p_int(lower = 1L, default = 100L, tags = "train"),
extrapolation = p_dbl(lower = 0, upper = 100, default = 100, tags = "train"),
sample = p_int(lower = 0L, default = 0L, tags = "train"),
seed = p_int(default = NO_DEF, tags = "train"),
label = p_uty(default = "outcome", tags = "train"),
neighbors = p_int(lower = 0L, upper = 9L, tags = c("predict", "required"))
)
)
param_set$values$committees = 1L
param_set$values$neighbors = 0L

Expand Down
2 changes: 1 addition & 1 deletion R/learner_aorsf_surv_aorsf.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LearnerSurvAorsf = R6Class("LearnerSurvAorsf",
split_min_stat = p_dbl(default = NULL, special_vals = list(NULL), lower = 0, tags = "train"),
oobag_pred_type = p_fct(levels = c("none", "surv", "risk", "chf"), default = "surv", tags = "train"),
importance = p_fct(levels = c("none", "anova", "negate", "permute"), default = "anova", tags = "train"),
importance_max_pvalue = p_dbl(default = 0.01, lower = 0.0001, upper = .9999, tag = "train"),
importance_max_pvalue = p_dbl(default = 0.01, lower = 0.0001, upper = .9999, tags = "train"),
oobag_pred_horizon = p_dbl(default = NULL, special_vals = list(NULL), tags = "train", lower = 0),
oobag_eval_every = p_int(default = NULL, special_vals = list(NULL), lower = 1, tags = "train"),
attach_data = p_lgl(default = TRUE, tags = "train"),
Expand Down
2 changes: 1 addition & 1 deletion R/learner_lme4_classif_glmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LearnerClassifGlmer = R6Class("LearnerClassifGlmer",
initialize = function() {
action_levels = c("ignore", "warning", "message", "stop")
param_set = ps(
formula = p_uty(default = formula(), tags = c("train", "required"), custom_check = check_formula),
formula = p_uty(tags = c("train", "required"), custom_check = check_formula),
start = p_uty(default = NULL, tags = "train"),
verbose = p_int(default = 0, lower = 0, tags = "train"),
offset = p_uty(default = NULL, tags = "train"),
Expand Down
76 changes: 29 additions & 47 deletions R/learner_lme4_regr_lmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,120 +26,102 @@ LearnerRegrLmer = R6Class("LearnerRegrLmer",
initialize = function() {
action_levels = c("ignore", "warning", "message", "stop")

ps = ParamSet$new(list(
ps = ps(
# lmer gives a lot of freedom in the formula spec, so we ask
# for the formula directly. The formula *must* be set.
ParamUty$new(
id = "formula",
formula = p_uty(
tags = c("required", "train"),
default = formula(),
custom_check = check_formula
),
ParamLgl$new(id = "REML", tags = "train", default = TRUE),
ParamUty$new(id = "start", tags = "train", default = NULL),
ParamInt$new(id = "verbose", tags = "train", default = 0, lower = 0),
ParamUty$new(id = "offset", tags = "train", default = NULL),
ParamUty$new(id = "contrasts", tags = "train", default = NULL),
REML = p_lgl(tags = "train", default = TRUE),
start = p_uty(tags = "train", default = NULL),
verbose = p_int(tags = "train", default = 0, lower = 0),
offset = p_uty(tags = "train", default = NULL),
contrasts = p_uty(tags = "train", default = NULL),

# Params passed to lmerControl()
ParamFct$new(
id = "optimizer",
optimizer = p_fct(
levels = c("Nelder_Mead", "bobyqa", "nlminbwrap", "nloptwrap"),
default = "nloptwrap",
tags = "train"
),
ParamLgl$new(
id = "restart_edge",
restart_edge = p_lgl(
default = FALSE,
tags = "train"),
ParamDbl$new(
id = "boundary.tol",
boundary.tol = p_dbl(
default = 1e-5,
lower = 0,
tags = "train"
),
ParamLgl$new(
id = "calc.derivs",
calc.derivs = p_lgl(
default = TRUE,
tags = "train"),
# Input checks
ParamFct$new(
id = "check.nobs.vs.rankZ",
check.nobs.vs.rankZ = p_fct(
levels = action_levels,
default = "ignore",
tags = "train"),
ParamFct$new(
id = "check.nobs.vs.nlev",
check.nobs.vs.nlev = p_fct(
levels = action_levels,
default = "stop",
tags = "train"),
ParamFct$new(
id = "check.nlev.gtreq.5",
check.nlev.gtreq.5 = p_fct(
levels = action_levels,
default = "ignore",
tags = "train"),
ParamFct$new(
id = "check.nlev.gtr.1",
check.nlev.gtr.1 = p_fct(
levels = action_levels,
default = "stop",
tags = "train"),
ParamFct$new(
id = "check.nobs.vs.nRE",
check.nobs.vs.nRE = p_fct(
levels = action_levels,
default = "stop",
tags = "train"),
ParamFct$new(
id = "check.rankX",
check.rankX = p_fct(
levels = c(
"message+drop.cols", "silent.drop.cols", "warn+drop.cols",
"stop.deficient", "ignore"),
default = "message+drop.cols",
tags = "train"
),
ParamFct$new(
id = "check.scaleX",
check.scaleX = p_fct(
levels = c(
"warning", "stop", "silent.rescale",
"message+rescale", "warn+rescale", "ignore"),
default = "warning",
tags = "train"
),
ParamFct$new(
id = "check.formula.LHS",
check.formula.LHS = p_fct(
levels = action_levels,
default = "stop",
tags = "train"
),
# Convergence checks
ParamUty$new(
id = "check.conv.grad",
check.conv.grad = p_uty(
default = 'lme4::.makeCC("warning", tol = 2e-3, relTol = NULL)',
tags = "train"
),
ParamUty$new(
id = "check.conv.singular",
check.conv.singular = p_uty(
default = 'lme4::.makeCC(action = "message", tol = formals(lme4::isSingular)$tol)',
tags = "train"
),
ParamUty$new(
id = "check.conv.hess",
check.conv.hess = p_uty(
default = 'lme4::.makeCC(action = "warning", tol = 1e-6)',
tags = "train"
),
# Additional optimizer controls
ParamUty$new(
id = "optCtrl",
optCtrl = p_uty(
default = list(),
tags = "train"
),

# Prediction params
ParamUty$new(id = "newparams", default = NULL, tags = "predict"),
ParamUty$new(id = "re.form", default = NULL, tags = "predict"),
ParamLgl$new(id = "random.only", default = FALSE, tags = "predict"),
ParamLgl$new(id = "allow.new.levels", default = FALSE, tags = "predict"),
ParamUty$new(id = "na.action", default = "stats::na.pass", tags = "predict")
))
newparams = p_uty(default = NULL, tags = "predict"),
re.form = p_uty(default = NULL, tags = "predict"),
random.only = p_lgl(default = FALSE, tags = "predict"),
allow.new.levels = p_lgl(default = FALSE, tags = "predict"),
na.action = p_uty(default = "stats::na.pass", tags = "predict")
)

super$initialize(
id = "regr.lmer",
Expand Down
4 changes: 2 additions & 2 deletions R/learner_prioritylasso_classif_priority_lasso.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ LearnerClassifPriorityLasso = R6Class("LearnerClassifPriorityLasso",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
blocks = p_uty(default = NULL, tags = c("train", "required")),
type.measure = p_fct(default = "class", levels = c("class", "auc"), tags = c("train", "required")),
blocks = p_uty(tags = c("train", "required")),
type.measure = p_fct(levels = c("class", "auc"), tags = c("train", "required")),
max.coef = p_uty(default = NULL, tags = "train"),
block1.penalization = p_lgl(default = TRUE, tags = "train"),
lambda.type = p_fct(default = "lambda.min", levels = c("lambda.min", "lambda.1se"), tags = c("train", "predict")), #nolint
Expand Down
2 changes: 1 addition & 1 deletion R/learner_prioritylasso_regr_priority_lasso.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LearnerRegrPriorityLasso = R6Class("LearnerRegrPriorityLasso",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
blocks = p_uty(default = NULL, tags = c("train", "required")),
blocks = p_uty(tags = c("train", "required")),
max.coef = p_uty(default = NULL, tags = "train"),
block1.penalization = p_lgl(default = TRUE, tags = "train"),
lambda.type = p_fct(default = "lambda.min", levels = c("lambda.min", "lambda.1se"), tags = c("train", "predict")),
Expand Down
2 changes: 1 addition & 1 deletion R/learner_prioritylasso_surv_priority_lasso.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LearnerSurvPriorityLasso = R6Class("LearnerSurvPriorityLasso",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
blocks = p_uty(default = NULL, tags = c("train", "required")),
blocks = p_uty(tags = c("train", "required")),
max.coef = p_uty(default = NULL, tags = "train"),
block1.penalization = p_lgl(default = TRUE, tags = "train"),
lambda.type = p_fct(default = "lambda.min", levels = c("lambda.min", "lambda.1se"), tags = c("train", "predict")), #nolint
Expand Down
2 changes: 1 addition & 1 deletion R/learner_rsm_regr_rsm.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LearnerRegrRSM = R6Class("LearnerRegrRSM",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
modelfun = p_fct(default = "FO", levels = c("FO", "TWI", "SO"), tags = c("train", "required"))
modelfun = p_fct(levels = c("FO", "TWI", "SO"), tags = c("train", "required"))
)
param_set$values = list(modelfun = "FO")

Expand Down
2 changes: 1 addition & 1 deletion R/learner_survival_surv_parametric.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ LearnerSurvParametric = R6Class("LearnerSurvParametric",
robust = p_lgl(default = FALSE, tags = "train"),
score = p_lgl(default = FALSE, tags = "train"),
cluster = p_uty(tags = "train"),
discrete = p_lgl(default = FALSE, tags = c("required", "predict"))
discrete = p_lgl(tags = c("required", "predict"))
)

ps$values = list(discrete = FALSE, dist = "weibull", type = "aft")
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test_paramtest_xgboost_surv_xgboost.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
x = rvest::read_html("https://xgboost.readthedocs.io/en/latest/parameter.html")
x = rvest::html_elements(x, c("li", "p"))
x = rvest::html_text2(x)
xli = rvest::html_elements(x, "li")
xp = rvest::html_elements(x, "p")
x = c(rvest::html_text2(xli), rvest::html_text2(xp))
x = grep("default=", x, value = TRUE)
x = strsplit(x, split = " ")
x = mlr3misc::map_chr(x, function(x) x[1])
Expand Down

0 comments on commit 5baa86a

Please sign in to comment.