Package website: release | dev
Universal Parameter Space Description and Tools.
::install_github("mlr-org/paradox") remotes
Create a simple ParamSet using all supported Parameter Types:
"int"
)"dbl"
)TRUE
or FALSE
("lgl"
)"fct"
)= ps(
pset 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:
generate_design_random(pset, 3)
#> <Design> with 3 rows:
#> z x flag methods
#> 1: 1 7.660348 FALSE b
#> 2: 3 8.809346 FALSE c
#> 3: 2 -9.088870 FALSE b
Generate LHS Design:
requireNamespace("lhs")
#> Loading required namespace: lhs
generate_design_lhs(pset, 3)
#> <Design> with 3 rows:
#> z x flag methods
#> 1: 1 -3.984673 TRUE b
#> 2: 2 7.938035 FALSE a
#> 3: 3 1.969783 TRUE c
Generate Grid Design:
generate_design_grid(pset, resolution = 2)
#> <Design> with 24 rows:
#> z x flag methods
#> 1: 1 -10 TRUE a
#> 2: 1 -10 TRUE b
#> 3: 1 -10 TRUE c
#> 4: 1 -10 FALSE a
#> 5: 1 -10 FALSE b
#> 6: 1 -10 FALSE c
#> 7: 1 10 TRUE a
#> [ reached getOption("max.print") -- omitted 18 rows ]
Properties of the parameters within the ParamSet
:
$ids()
pset#> [1] "z" "x" "flag" "methods"
$levels
pset#> $z
#> NULL
#>
#> $x
#> NULL
#>
#> $flag
#> [1] TRUE FALSE
#>
#> $methods
#> [1] "a" "b" "c"
$nlevels
pset#> z x flag methods
#> 3 Inf 2 3
$is_number
pset#> z x flag methods
#> TRUE TRUE FALSE FALSE
$lower
pset#> z x flag methods
#> 1 -10 NA NA
$upper
pset#> z x flag methods
#> 3 10 NA NA
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):
$test(list(z = 1, x = 1))
pset#> [1] TRUE
$test(list(z = -1, x = 1))
pset#> [1] FALSE
$check(list(z = -1, x = 1))
pset#> [1] "z: Element 1 is not >= 0.5"
$assert(list(z = -1, x = 1))
pset#> Error in pset$assert(list(z = -1, x = 1)): Assertion on 'list(z = -1, x = 1)' failed: z: Element 1 is not >= 0.5.
Transformations are functions with a fixed signature.
x
A named list of parameter valuesparam_set
the ParamSet
used to create the
designTransformations 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.
= ps(
pset z = p_int(lower = -3, upper = 3),
x = p_dbl(lower = 2^-3, upper = 2^3, logscale = TRUE)
)$extra_trafo = function(x, param_set) {
pset$z = 2^x$z
xreturn(x)
}= SamplerUnif$new(pset)
pset_smplr = pset_smplr$sample(2)
x = x$transpose()
xst
xst#> [[1]]
#> [[1]]$z
#> [1] 0.125
#>
#> [[1]]$x
#> [1] 0.6985067
#>
#>
#> [[2]]
#> [[2]]$z
#> [1] 0.5
#>
#> [[2]]$x
#> [1] 0.5795772
Further documentation can be found in the in-depth tutorial