+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ 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
docker run --name mlr3book \
-v $(pwd):/book \
-v $(pwd):/mlr3book_latest \
--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 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.
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

Expand Down
1 change: 1 addition & 0 deletions book/chapters/appendices/errata.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 10 additions & 9 deletions book/chapters/chapter4/hyperparameter_optimization.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -804,34 +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}
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()
```

Expand Down
2 changes: 2 additions & 0 deletions book/common/_setup.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions book/common/_utils.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载