Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Add Parameter test and missing parameters (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc authored Mar 30, 2020
1 parent a7065fa commit d329bf6
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 9 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/paramtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
on:
push:
pull_request:
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master)
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 4 * * *"

name: Parameter Check

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

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: "release" }

env:
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
# we are not allowed to write to ~/.ccache on GH Actions
# setting some ccache options
CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }}
CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache
CCACHE_NOHASHDIR: true
CCACHE_SLOPPINESS: include_file_ctime
# make sure to run `tic::use_ghactions_deploy()` to set up deployment
id_rsa: ${{ secrets.id_rsa }}
# prevent rgl issues because no X11 display is available
RGL_USE_NULL: true

steps:
- uses: actions/checkout@v2

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

# set date/week for use in cache creation
# https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970
# - cache R packages daily
# - cache ccache weekly -> 'ccache' helps rebuilding the package cache faster
- name: "[Cache] Prepare daily timestamp for cache"
if: runner.os != 'Windows'
id: date
run: echo "::set-output name=date::$(date '+%d-%m')"

- name: "[Cache] Prepare weekly timestamp for cache"
if: runner.os != 'Windows'
id: datew
run: echo "::set-output name=datew::$(date '+%Y-%V')"

- name: "[Cache] Cache R packages"
if: runner.os != 'Windows'
uses: pat-s/[email protected]
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1

- name: "[Cache] Cache ccache"
if: runner.os != 'Windows'
uses: pat-s/[email protected]
with:
path: ${{ env.CCACHE_DIR}}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}}

# install ccache and write config file
- name: "[Linux] ccache"
if: runner.os == 'Linux'
run: |
sudo apt install ccache libcurl4-openssl-dev
mkdir -p ~/.R && echo -e 'CXX_STD = CXX14\n\nCC=ccache gcc -std=gnu99\nCXX=ccache g++\nCXX11=ccache g++ -std=gnu99\nCXX14=ccache g++ -std=gnu99\nC11=ccache g++\nC14=ccache g++\nFC=ccache gfortran\nF77=ccache gfortran' > $HOME/.R/Makevars
# for some strange Windows reason this step and the next one need to be decoupled
- name: "[Stage] Prepare"
run: |
Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')"
Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')"
- name: "[Stage] Install"
if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel'
run: Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"

- name: "[Stage] Parameter test"
run: |
R CMD INSTALL .
Rscript -e "remotes::install_github('mlr-org/mlr3@paramtest')"
Rscript -e "testthat::test_dir(system.file('paramtest', package = 'mlr3learners.mboost'))"
16 changes: 10 additions & 6 deletions R/LearnerClassifGAMBoost.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ LearnerClassifGAMBoost = R6Class("LearnerClassifGAMBoost",
ParamDbl$new(id = "nu", default = 0.1, tags = "train"),
ParamFct$new(id = "risk", default = "inbag",
levels = c("inbag", "oobag", "none"), tags = "train"),
ParamUty$new(id = "oobweights", default = NULL, tags = "train")
ParamUty$new(id = "oobweights", default = NULL, tags = "train"),
ParamLgl$new(id = "trace", default = FALSE, tags = "train"),
ParamUty$new(id = "stopintern", default = FALSE, tags = "train"),
ParamUty$new(id = "na.action", default = na.omit, tags = "train")
)
)
ps$add_dep("type", "family", CondEqual$new("Binomial"))
Expand Down Expand Up @@ -84,7 +87,7 @@ LearnerClassifGAMBoost = R6Class("LearnerClassifGAMBoost",
}

pars_gamboost$family = switch(pars_gamboost$family,
Binomial = invoke(mboost::Binomial, .args = pars_binomial),
Binomial = mlr3misc::invoke(mboost::Binomial, .args = pars_binomial),
AdaExp = mboost::AdaExp(),
AUC = mboost::AUC())

Expand All @@ -94,12 +97,12 @@ LearnerClassifGAMBoost = R6Class("LearnerClassifGAMBoost",
data[[task$target_names]] = factor(data[[task$target_names]], levs)
}

ctrl = invoke(mboost::boost_control, .args = pars_boost)
ctrl = mlr3misc::invoke(mboost::boost_control, .args = pars_boost)

# baselearner argument requires attached mboost package
withr::with_package("mboost", {
invoke(mboost::gamboost, formula = f, data = data, control = ctrl,
.args = pars_gamboost)
mlr3misc::invoke(mboost::gamboost, formula = f, data = data,
control = ctrl, .args = pars_gamboost)
})
},

Expand All @@ -116,7 +119,8 @@ LearnerClassifGAMBoost = R6Class("LearnerClassifGAMBoost",
p = invoke(predict, self$model, newdata = newdata, type = "class")
PredictionClassif$new(task = task, response = p)
} else {
p = invoke(predict, self$model, newdata = newdata, type = "response")
p = mlr3misc::invoke(predict, self$model, newdata = newdata,
type = "response")
p = matrix(c(p, 1 - p), ncol = 2L, nrow = length(p))
colnames(p) = task$class_names
PredictionClassif$new(task = task, prob = p)
Expand Down
6 changes: 5 additions & 1 deletion R/LearnerClassifGLMBoost.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ LearnerClassifGLMBoost = R6Class("LearnerClassifGLMBoost",
ParamDbl$new(id = "nu", default = 0.1, tags = "train"),
ParamFct$new(id = "risk", default = "inbag",
levels = c("inbag", "oobag", "none"), tags = "train"),
ParamUty$new(id = "oobweights", default = NULL, tags = "train")
ParamUty$new(id = "oobweights", default = NULL, tags = "train"),
ParamLgl$new(id = "trace", default = FALSE, tags = "train"),
ParamUty$new(id = "stopintern", default = FALSE, tags = "train"),
ParamUty$new(id = "na.action", default = na.omit, tags = "train"),
ParamUty$new(id = "contrasts.arg", tags = "train")
)
)
ps$add_dep("link", "family", CondEqual$new("Binomial"))
Expand Down
5 changes: 4 additions & 1 deletion R/LearnerRegrGAMBoost.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ LearnerRegrGAMBoost = R6Class("LearnerRegrGAMBoost", inherit = LearnerRegr,
ParamDbl$new(id = "nu", default = 0.1, tags = "train"),
ParamFct$new(id = "risk", default = "inbag",
levels = c("inbag", "oobag", "none"), tags = "train"),
ParamUty$new(id = "oobweights", default = NULL, tags = "train")
ParamUty$new(id = "oobweights", default = NULL, tags = "train"),
ParamLgl$new(id = "trace", default = FALSE, tags = "train"),
ParamUty$new(id = "stopintern", default = FALSE, tags = "train"),
ParamUty$new(id = "na.action", default = na.omit, tags = "train")
)
)
ps$add_dep("oobweights", "risk", CondEqual$new("oobag"))
Expand Down
6 changes: 5 additions & 1 deletion R/LearnerRegrGLMBoost.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ LearnerRegrGLMBoost = R6Class("LearnerRegrGLMBoost", inherit = LearnerRegr,
ParamDbl$new(id = "nu", default = 0.1, tags = "train"),
ParamFct$new(id = "risk", default = "inbag",
levels = c("inbag", "oobag", "none"), tags = "train"),
ParamUty$new(id = "oobweights", default = NULL, tags = "train")
ParamUty$new(id = "oobweights", default = NULL, tags = "train"),
ParamLgl$new(id = "trace", default = FALSE, tags = "train"),
ParamUty$new(id = "stopintern", default = FALSE, tags = "train"),
ParamUty$new(id = "na.action", default = na.omit, tags = "train"),
ParamUty$new(id = "contrasts.arg", tags = "train")
)
)
ps$add_dep("oobweights", "risk", CondEqual$new("oobag"))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- badges: start -->
[![R CMD Check via {tic}](https://github.com/mlr3learners/mlr3learners.mboost/workflows/R%20CMD%20Check%20via%20{tic}/badge.svg?branch=master)](https://github.com/mlr3learners/mlr3learners.mboost/actions)
![Parameter Check](https://github.com/mlr3learners/mlr3learners.mboost/workflows/Parameter%20Check/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/mlr3learners/mlr3learners.mboost/branch/master/graph/badge.svg)](https://codecov.io/gh/mlr3learners/mlr3learners.mboost)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
<!-- badges: end -->
Expand Down
3 changes: 3 additions & 0 deletions inst/paramtest/helper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library(mlr3)
lapply(list.files(system.file("testthat", package = "mlr3"),
pattern = "helper_autotest", full.names = TRUE), source)
29 changes: 29 additions & 0 deletions inst/paramtest/test_paramtest_classif_gamboost.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(mlr3learners.mboost)

test_that("classif.gamboost", {
learner = lrn("classif.gamboost")
fun = mboost::gamboost
exclude = c(
"formula", # handled via mlr3
"data", # handled via mlr3
"weights", # handled via mlr3
"control", # handled to mboost::boost_control
"..." # not used
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTestresult$missing,"'", collapse = "\n")))
})

test_that("classif.gamboost_boost_control", {
learner = lrn("classif.gamboost")
fun = mboost::boost_control
exclude = c(
"center" # deprecated
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing,"'", collapse = "\n")))
})
29 changes: 29 additions & 0 deletions inst/paramtest/test_paramtest_classif_glmboost.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(mlr3learners.mboost)

test_that("classif.glmboost", {
learner = lrn("classif.glmboost")
fun = mboost:::glmboost.formula
exclude = c(
"formula", # handled via mlr3
"data", # handled via mlr3
"weights", # handled via mlr3
"control", # handled to mboost::boost_control
"..." # not used
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})

test_that("classif.glmboost_boost_control", {
learner = lrn("classif.glmboost")
fun = mboost::boost_control
exclude = c(
"center" # deprecated
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})
29 changes: 29 additions & 0 deletions inst/paramtest/test_paramtest_regr_gamboost.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(mlr3learners.mboost)

test_that("regr.gamboost", {
learner = lrn("regr.gamboost")
fun = mboost::gamboost
exclude = c(
"formula", # handled via mlr3
"data", # handled via mlr3
"weights", # handled via mlr3
"control", # handled to mboost::boost_control
"..." # not used
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})

test_that("regr.gamboost_boost_control", {
learner = lrn("regr.gamboost")
fun = mboost::boost_control
exclude = c(
"center" # deprecated
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})
29 changes: 29 additions & 0 deletions inst/paramtest/test_paramtest_regr_glmboost.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(mlr3learners.mboost)

test_that("regr.glmboost", {
learner = lrn("regr.glmboost")
fun = mboost:::glmboost.formula
exclude = c(
"formula", # handled via mlr3
"data", # handled via mlr3
"weights", # handled via mlr3
"control", # handled to mboost::boost_control
"..." # not used
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})

test_that("regr.glmboost_boost_control", {
learner = lrn("regr.glmboost")
fun = mboost::boost_control
exclude = c(
"center" # deprecated
)

ParamTest = run_paramtest(learner, fun, exclude)
expect_true(ParamTest, info = paste0("\nMissing parameters:\n",
paste0("- '", ParamTest$missing, "'", collapse = "\n")))
})

0 comments on commit d329bf6

Please sign in to comment.