Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mlr-org/paradox

ParamHelpers Next Generation
https://github.com/mlr-org/paradox

experimental-design hyperparameters mlr3 r r-package transformations

Last synced: 1 day ago
JSON representation

ParamHelpers Next Generation

Awesome Lists containing this project

README

        

---
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.

[![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/)

```{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)