MyNixOS website logo
Description

Define and Work with Parameter Spaces for Complex Algorithms.

Define parameter spaces, constraints and dependencies for arbitrary algorithms, to program on such spaces. Also includes statistical designs and random samplers. Objects are implemented as 'R6' classes.

paradox

Package website: release | dev

Universal Parameter Space Description and Tools.

r-cmd-check CRAN Status StackOverflow Mattermost

Installation

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

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:

pset$ids()
#> [1] "z"       "x"       "flag"    "methods"
pset$levels
#> $z
#> NULL
#> 
#> $x
#> NULL
#> 
#> $flag
#> [1]  TRUE FALSE
#> 
#> $methods
#> [1] "a" "b" "c"
pset$nlevels
#>       z       x    flag methods 
#>       3     Inf       2       3
pset$is_number
#>       z       x    flag methods 
#>    TRUE    TRUE   FALSE   FALSE
pset$lower
#>       z       x    flag methods 
#>       1     -10      NA      NA
pset$upper
#>       z       x    flag methods 
#>       3      10      NA      NA

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):

pset$test(list(z = 1, x = 1))
#> [1] TRUE
pset$test(list(z = -1, x = 1))
#> [1] FALSE
pset$check(list(z = -1, x = 1))
#> [1] "z: Element 1 is not >= 0.5"
pset$assert(list(z = -1, x = 1))
#> 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

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.

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

Metadata

Version

1.0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows