-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
118 lines (89 loc) · 3.25 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
output: github_document
---
# paradox
Package website: [release](https://paradox.mlr-org.com/) | [dev](https://paradox.mlr-org.com/dev/)
Universal Parameter Space Description and Tools.
<!-- badges: start -->
[![r-cmd-check](https://github.com/mlr-org/paradox/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/paradox/actions/workflows/r-cmd-check.yml)
[![CRAN Status](https://www.r-pkg.org/badges/version/paradox)](https://CRAN.R-project.org/package=paradox)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
<!-- badges: end -->
```{r setup, include=FALSE}
set.seed(123)
knitr::opts_chunk$set(cache = FALSE, collapse = TRUE, comment = "#>")
options(datatable.print.class = FALSE, datatable.print.keys = FALSE)
library(paradox)
```
## Installation
```{r inst, eval=FALSE}
remotes::install_github("mlr-org/paradox")
```
## Usage
Create a simple ParamSet using all supported Parameter Types:
* integer numbers (`"int"`)
* real-valued numbers (`"dbl"`)
* truth values `TRUE` or `FALSE` (`"lgl"`)
* categorical values from a set of possible strings (`"fct"`)
* further types are only possible by using transformations.
```{r ps}
pset = ps(
z = p_int(lower = 1, upper = 3),
x = p_dbl(lower = -10, upper = 10),
flag = p_lgl(),
methods = p_fct(c("a","b","c"))
)
```
Draw random samples / create random design:
```{r pssample}
generate_design_random(pset, 3)
```
Generate LHS Design:
```{r pslhs}
requireNamespace("lhs")
generate_design_lhs(pset, 3)
```
Generate Grid Design:
```{r psgrid, R.options=list(max.print=30)}
generate_design_grid(pset, resolution = 2)
```
Properties of the parameters within the `ParamSet`:
```{r psprobs}
pset$ids()
pset$levels
pset$nlevels
pset$is_number
pset$lower
pset$upper
```
### Parameter Checks
Check that a parameter satisfies all conditions of a `ParamSet`, using `$test()` (returns `FALSE` on mismatch), `$check()` (returns error description on mismatch), and `$assert()` (throws error on mismatch):
```{r, error = TRUE}
pset$test(list(z = 1, x = 1))
pset$test(list(z = -1, x = 1))
pset$check(list(z = -1, x = 1))
pset$assert(list(z = -1, x = 1))
```
### Transformations
Transformations are functions with a fixed signature.
* `x` A named list of parameter values
* `param_set` the `ParamSet` used to create the design
Transformations can be used to change the distributions of sampled parameters.
For example, to sample values between $2^-3$ and $2^3$ in a $log_2$-uniform distribution, one can sample uniformly between -3 and 3 and exponentiate the random value inside the transformation.
Alternatively, `logscale = TRUE` can be set; in this case, `lower` and `upper` represent the values *after* the transformation.
```{r pstransscale}
pset = ps(
z = p_int(lower = -3, upper = 3),
x = p_dbl(lower = 2^-3, upper = 2^3, logscale = TRUE)
)
pset$extra_trafo = function(x, param_set) {
x$z = 2^x$z
return(x)
}
pset_smplr = SamplerUnif$new(pset)
x = pset_smplr$sample(2)
xst = x$transpose()
xst
```
Further documentation can be found in the [in-depth tutorial](https://paradox.mlr-org.com/dev/articles/indepth.html)