paradox v0.5.0

0

Monthly downloads

0th

Percentile

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.

Readme

paradox

Package website: release | dev

Universal Parameter Space Description and Tools.

tic 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.
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)
#> <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(ps, 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(ps, 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:

ps$ids()
#> [1] "z"       "x"       "flag"    "methods"
ps$levels
#> $z
#> NULL
#>
#> $x
#> NULL
#>
#> $flag
#> [1]  TRUE FALSE
#>
#> $methods
#> [1] "a" "b" "c"
ps$nlevels
#>       z       x    flag methods
#>       3     Inf       2       3
ps$is_number
#>       z       x    flag methods
#>    TRUE    TRUE   FALSE   FALSE
ps$lower
#>       z       x    flag methods
#>       1     -10      NA      NA
ps$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):

ps$test(list(z = 1, x = 1))
#> [1] TRUE
ps$test(list(z = -1, x = 1))
#> [1] FALSE
ps$check(list(z = -1, x = 1))
#> [1] "z: Element 1 is not >= 1"
ps$assert(list(z = -1, x = 1))
#> Error in ps$assert(list(z = -1, x = 1)): Assertion on 'list(z = -1, x = 1)' failed: z: Element 1 is not >= 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 23 and 23 in a log2-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
#> [[1]]
#> [[1]]$z
#> [1] 0.125
#>
#> [[1]]$x
#> [1] 0.4137243
#>
#>
#> [[2]]
#> [[2]]$z
#> [1] 0.5
#>
#> [[2]]$x
#> [1] 0.3688455

Further documentation can be found in the mlr3book.

Functions in paradox

Name Description
ParamInt Integer Parameter
ParamFct Factor Parameter
Condition Dependency Condition
NO_DEF Extra data type for "no default value"
ParamSet ParamSet
ParamDbl Numerical Parameter
Design Design of Configurations
ParamLgl Logical Parameter
Param Param Class
Sampler1D Sampler1D Class
ParamSetCollection ParamSetCollection
generate_design_random Generate a Random Design
Sampler1DUnif Sampler1DUnif Class
Sampler1DCateg Sampler1DCateg Class
assert_param Assertions for Params and ParamSets
as.data.table Re-export of as.data.table See data.table::as.data.table.
generate_design_grid Generate a Grid Design
SamplerJointIndep SamplerJointIndep Class
generate_design_lhs Generate a Space-Filling LHS Design
SamplerUnif SamplerUnif Class
Sampler1DNormal Sampler1DNormal Class
transpose transpose
Sampler1DRfun Sampler1DRfun Class
SamplerHierarchical SamplerHierarchical Class
paradox-package paradox: Define and Work with Parameter Spaces for Complex Algorithms
ParamUty Untyped Parameter
Sampler Sampler Class
No Results!

Last month downloads

Details

Type Package
License LGPL-3
URL https://paradox.mlr-org.com, https://github.com/mlr-org/paradox
BugReports https://github.com/mlr-org/paradox/issues
Encoding UTF-8
NeedsCompilation no
RoxygenNote 7.1.1
Collate 'Condition.R' 'Design.R' 'NoDefault.R' 'Param.R' 'ParamDbl.R' 'ParamFct.R' 'ParamInt.R' 'ParamLgl.R' 'ParamSet.R' 'ParamSetCollection.R' 'ParamUty.R' 'Sampler.R' 'Sampler1D.R' 'SamplerHierarchical.R' 'SamplerJointIndep.R' 'SamplerUnif.R' 'asserts.R' 'generate_design_grid.R' 'generate_design_lhs.R' 'generate_design_random.R' 'helper.R' 'reexports.R' 'zzz.R'
Packaged 2020-10-21 07:40:51 UTC; michel
Repository CRAN
Date/Publication 2020-10-21 20:30:02 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/paradox)](http://www.rdocumentation.org/packages/paradox)