From a116c67317cd2df61a30d9ae3be2ad4cc80fe013 Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 13 Oct 2025 11:42:18 +0200 Subject: [PATCH 1/7] fix here paths --- book/chapters/chapter1/introduction_and_overview.qmd | 4 ++++ book/common/_setup.qmd | 2 ++ book/common/_utils.qmd | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/book/chapters/chapter1/introduction_and_overview.qmd b/book/chapters/chapter1/introduction_and_overview.qmd index ccf4778ef..3b64d453a 100644 --- a/book/chapters/chapter1/introduction_and_overview.qmd +++ b/book/chapters/chapter1/introduction_and_overview.qmd @@ -3,6 +3,10 @@ aliases: - "/introduction_and_overview.html" --- +```{r} +remotes::install_github("mlr-org/mlr3extralearners") +``` + # Introduction and Overview {#sec-introduction} {{< include ../../common/_setup.qmd >}} diff --git a/book/common/_setup.qmd b/book/common/_setup.qmd index 83dc88d09..c1856562e 100644 --- a/book/common/_setup.qmd +++ b/book/common/_setup.qmd @@ -14,6 +14,8 @@ lgr::get_logger("mlr3oml")$set_threshold("warn") igraph::igraph_options(vertex.label.color = "black") +here::i_am("book/common/_setup.qmd") + options(width = 73, digits = 4) # https://github.com/mlr-org/miesmuschel/blob/master/R/zzz.R diff --git a/book/common/_utils.qmd b/book/common/_utils.qmd index 6091ccde9..01588e44f 100644 --- a/book/common/_utils.qmd +++ b/book/common/_utils.qmd @@ -40,12 +40,12 @@ citeas = function(chaptitle) { %s. (2024). %s. In Bischl B, Sonabend R, Kotthoff L, Lang M, (Eds.), *Applied Machine Learning Using mlr3 in R*. CRC Press. https://mlr3book.mlr-org.com/%s.', authors_short, chaptitle, chaphtml) tex = sprintf(' - @incollection{citekey, - author = "%s", + @incollection{citekey, + author = "%s", title = "%s", booktitle = "Applied Machine Learning Using {m}lr3 in {R}", publisher = "CRC Press", year = "2024", - editor = "Bernd Bischl and Raphael Sonabend and Lars Kotthoff and Michel Lang", + editor = "Bernd Bischl and Raphael Sonabend and Lars Kotthoff and Michel Lang", url = "https://mlr3book.mlr-org.com/%s" }', paste0(authors, collapse = " and "), chaptitle, chaphtml) From 32837e3427a982417031fe3dba0051087467b4ee Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 13 Oct 2025 11:43:32 +0200 Subject: [PATCH 2/7] ... --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ac91728b..0a07f72d0 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ You can read the rendered version of the book in either: To render the book yourself, follow these steps: 1. Clone this repository (https://github.com/mlr-org/mlr3book.git) and navigate to the `mlr3book` directory. -2. Pull the docker image `docker pull mlrorgdocker/mlr3-book`. +2. Pull the docker image `docker pull mlrorg/mlr3-book`. 3. Preview the book with ```bash @@ -29,13 +29,14 @@ docker run --name mlr3book \ -v $(pwd):/book \ --rm \ -p 8888:8888 \ - mlrorg/mlr3-book quarto preview book/book --port 8888 --host 0.0.0.0 --no-browser + mlrorg/mlr3-book quarto preview book --port 8888 --host 0.0.0.0 --no-browser ``` This command mounts your current directory into the docker container, allowing quarto to render the book and serve it on port 8888. Access the preview at `http://0.0.0.0:8888`. Make your changes locally and preview them with the above command. +Add `--cache-refresh` to the command to refresh the cache. Once you are happy with your changes, open a pull request. The pull request will include a preview of your changes From 215a9d3dca3a25018194300afe1e9d1682fbacad Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 13 Oct 2025 11:45:37 +0200 Subject: [PATCH 3/7] ... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a07f72d0..2a703c153 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ To render the book yourself, follow these steps: ```bash docker run --name mlr3book \ - -v $(pwd):/book \ + -v $(pwd)/book:/book \ --rm \ -p 8888:8888 \ mlrorg/mlr3-book quarto preview book --port 8888 --host 0.0.0.0 --no-browser From 3a63ae04079a57cea821e45a0d780a67e89c9466 Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 13 Oct 2025 12:15:07 +0200 Subject: [PATCH 4/7] ... --- README.md | 4 ++-- book/chapters/chapter4/hyperparameter_optimization.qmd | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a703c153..484d10d85 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ To render the book yourself, follow these steps: ```bash docker run --name mlr3book \ - -v $(pwd)/book:/book \ + -v $(pwd):/mlr3book_latest \ --rm \ -p 8888:8888 \ - mlrorg/mlr3-book quarto preview book --port 8888 --host 0.0.0.0 --no-browser + mlrorg/mlr3-book quarto preview mlr3book_latest/book --port 8888 --host 0.0.0.0 --no-browser ``` This command mounts your current directory into the docker container, allowing quarto to render the book and serve it on port 8888. diff --git a/book/chapters/chapter4/hyperparameter_optimization.qmd b/book/chapters/chapter4/hyperparameter_optimization.qmd index 14207a73e..230243ecd 100644 --- a/book/chapters/chapter4/hyperparameter_optimization.qmd +++ b/book/chapters/chapter4/hyperparameter_optimization.qmd @@ -830,6 +830,7 @@ search_space$trafo(list(num_layers = 4, num_nodes_per_layer = 12)) Even though this transformation looks complex, it only affects one of the hyperparameters (and does not need access to others), so we could include it in the learner using `to_tune()` by passing the whole `ParamSet` object: ```{r hyperparameter_optimization-049} +library(mlr3extralearners) learner = lrn("surv.coxtime") learner$param_set$set_values(num_nodes = to_tune(search_space)) learner$param_set$search_space() From 65db386326164dc76b7fbbf7182242075c796c3a Mon Sep 17 00:00:00 2001 From: be-marc Date: Tue, 14 Oct 2025 12:40:13 +0200 Subject: [PATCH 5/7] torch --- .../chapter4/hyperparameter_optimization.qmd | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/book/chapters/chapter4/hyperparameter_optimization.qmd b/book/chapters/chapter4/hyperparameter_optimization.qmd index 230243ecd..b21f22229 100644 --- a/book/chapters/chapter4/hyperparameter_optimization.qmd +++ b/book/chapters/chapter4/hyperparameter_optimization.qmd @@ -804,35 +804,35 @@ search_space = ps( ``` In other cases, we may need to tune two or more 'pseudoparameters' that do not exist in our learner's parameter set but are required to tune a vector parameter. -For example, say we want to tune the architecture of a `r index('neural network')`, in which we need to decide the number of layers and the number of nodes in each layer, this is the case in the `num_nodes` hyperparameter in `lrn("surv.coxtime")` (we use this learner as it provides a useful template for this sort of transformation, interested readers can read about survival analysis in @sec-survival). -In this case, the learner expects a vector where each element of the vector corresponds to the number of nodes in a layer and the length of the vector is the number of layers. +For example, say we want to tune the architecture of a `r index('neural network')`, in which we need to decide the number of layers and the number of nodes in each layer, this is the case in the `neurons` hyperparameter in `lrn("classif.mlp")` from the `mlr3torch` package. +In this case, the learner expects a vector where each element of the vector corresponds to the number of neurons in a layer and the length of the vector is the number of layers. We could then tune this as follows: ```{r hyperparameter_optimization-047} search_space = ps( num_layers = p_int(lower = 1, upper = 20), - num_nodes_per_layer = p_int(4, 64), + num_neurons_per_layer = p_int(4, 64), .extra_trafo = function(x, param_set) { - x$num_nodes = rep(x$num_nodes_per_layer, x$num_layers) + x$neurons= rep(x$num_neurons_per_layer, x$num_layers) x$num_layers = NULL - x$num_nodes_per_layer = NULL + x$num_neurons_per_layer = NULL x } ) ``` -Here we are tuning the pseudo-parameter `num_layers` between `1` and `20`, then tuning the pseudo-parameter `num_nodes_per_layer` between `4` and `64`, then combining these into a vector called `num_nodes` (the real hyperparameter) and removing the pseudo-parameters. +Here we are tuning the pseudo-parameter `num_layers` between `1` and `20`, then tuning the pseudo-parameter `num_neurons_per_layer` between `4` and `64`, then combining these into a vector called `neurons` (the real hyperparameter) and removing the pseudo-parameters. ```{r hyperparameter_optimization-048} -search_space$trafo(list(num_layers = 4, num_nodes_per_layer = 12)) +search_space$trafo(list(num_layers = 4, num_neurons_per_layer = 12)) ``` Even though this transformation looks complex, it only affects one of the hyperparameters (and does not need access to others), so we could include it in the learner using `to_tune()` by passing the whole `ParamSet` object: ```{r hyperparameter_optimization-049} -library(mlr3extralearners) -learner = lrn("surv.coxtime") -learner$param_set$set_values(num_nodes = to_tune(search_space)) +library(mlr3torch) +learner = lrn("classif.mlp") +learner$param_set$set_values(neurons = to_tune(search_space)) learner$param_set$search_space() ``` From 6c60be1bc562c93b15217043b813c52accc0275e Mon Sep 17 00:00:00 2001 From: be-marc Date: Tue, 14 Oct 2025 12:41:43 +0200 Subject: [PATCH 6/7] ... --- book/chapters/appendices/errata.qmd | 1 + 1 file changed, 1 insertion(+) diff --git a/book/chapters/appendices/errata.qmd b/book/chapters/appendices/errata.qmd index 11df3b899..86b059335 100644 --- a/book/chapters/appendices/errata.qmd +++ b/book/chapters/appendices/errata.qmd @@ -26,6 +26,7 @@ This appendix lists changes to the online version of this book to chapters inclu * Renamed `TuningInstanceMultiCrit` to `TuningInstanceBatchMultiCrit`. * Renamed `Tuner` to `TunerBatch`. * Replaced reference to `Param` with `Domain`. +* Replace `lrn("surv.coxtime")` with `lrn("classif.mlp")`. ## 5. Advanced Tuning Methods and Black Box Optimization From e79eb4657d8096a877f40d66922ae539e45547ca Mon Sep 17 00:00:00 2001 From: be-marc Date: Tue, 14 Oct 2025 18:06:18 +0200 Subject: [PATCH 7/7] ... --- book/chapters/chapter1/introduction_and_overview.qmd | 4 ---- 1 file changed, 4 deletions(-) diff --git a/book/chapters/chapter1/introduction_and_overview.qmd b/book/chapters/chapter1/introduction_and_overview.qmd index 3b64d453a..ccf4778ef 100644 --- a/book/chapters/chapter1/introduction_and_overview.qmd +++ b/book/chapters/chapter1/introduction_and_overview.qmd @@ -3,10 +3,6 @@ aliases: - "/introduction_and_overview.html" --- -```{r} -remotes::install_github("mlr-org/mlr3extralearners") -``` - # Introduction and Overview {#sec-introduction} {{< include ../../common/_setup.qmd >}}