paradox

Package website: release | dev

Universal Parameter Space Description and Tools.

r-cmd-check CRAN Status StackOverflow Mattermost

set.seed(123)
knitr::opts_chunk$set(cache = FALSE, collapse = TRUE, comment = "#>")
options(datatable.print.class = FALSE, datatable.print.keys = FALSE)
library(paradox)

Installation

remotes::install_github("mlr-org/paradox")

Usage

Create a simple ParamSet using all supported Parameter Types:

ps = ParamSet$new(
  params = list(
    ParamInt$new(id = "z", lower = 1, upper = 3),
    ParamDbl$new(id = "x", lower = -10, upper = 10),
    ParamLgl$new(id = "flag"),
    ParamFct$new(id = "methods", levels = c("a","b","c"))
  )
)

Draw random samples / create random design:

generate_design_random(ps, 3)

Generate LHS Design:

requireNamespace("lhs")
generate_design_lhs(ps, 3)

Generate Grid Design:

generate_design_grid(ps, resolution = 2)

Properties of the parameters within the ParamSet:

ps$ids()
ps$levels
ps$nlevels
ps$is_number
ps$lower
ps$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):

ps$test(list(z = 1, x = 1))
ps$test(list(z = -1, x = 1))
ps$check(list(z = -1, x = 1))
ps$assert(list(z = -1, x = 1))

Transformations

Transformations are functions with a fixed signature.

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.

ps = ParamSet$new(
  params = list(
    ParamInt$new(id = "z", lower = -3, upper = 3),
    ParamDbl$new(id = "x", lower = 0, upper = 1)
  )
)
ps$trafo = function(x, param_set) {
  x$z = 2^x$z
  return(x)
}
ps_smplr = SamplerUnif$new(ps)
x = ps_smplr$sample(2)
xst = x$transpose()
xst

Further documentation can be found in the mlr3book.



mlr-org/phng documentation built on April 1, 2024, 2:06 a.m.