Type: | Package |
Title: | Define and Work with Parameter Spaces for Complex Algorithms |
Version: | 1.0.1 |
Description: | 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. |
License: | LGPL-3 |
URL: | https://paradox.mlr-org.com, https://github.com/mlr-org/paradox |
BugReports: | https://github.com/mlr-org/paradox/issues |
Imports: | backports, checkmate, data.table, methods, mlr3misc (≥ 0.9.4), R6 |
Suggests: | rmarkdown, mlr3learners, e1071, knitr, lhs, spacefillr, testthat |
Encoding: | UTF-8 |
Config/testthat/edition: | 3 |
Config/testthat/parallel: | false |
NeedsCompilation: | no |
RoxygenNote: | 7.3.2 |
VignetteBuilder: | knitr |
Collate: | 'Condition.R' 'Design.R' 'Domain.R' 'Domain_methods.R' 'NoDefault.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' 'default_values.R' 'generate_design_grid.R' 'generate_design_lhs.R' 'generate_design_random.R' 'generate_design_sobol.R' 'helper.R' 'ps.R' 'ps_replicate.R' 'ps_union.R' 'reexports.R' 'to_tune.R' 'zzz.R' |
Packaged: | 2024-07-09 11:25:23 UTC; user |
Author: | Michel Lang |
Maintainer: | Martin Binder <mlr.developer@mb706.com> |
Repository: | CRAN |
Date/Publication: | 2024-07-09 13:10:02 UTC |
paradox: Define and Work with Parameter Spaces for Complex Algorithms
Description
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.
Author(s)
Maintainer: Martin Binder mlr.developer@mb706.com
Authors:
Michel Lang michellang@gmail.com (ORCID)
Bernd Bischl bernd_bischl@gmx.net (ORCID)
Jakob Richter jakob1richter@gmail.com (ORCID)
Xudong Sun smilesun.east@gmail.com (ORCID)
Other contributors:
Marc Becker marcbecker@posteo.de (ORCID) [contributor]
See Also
Useful links:
Report bugs at https://github.com/mlr-org/paradox/issues
Design of Configurations
Description
A lightweight wrapper around a ParamSet and a data.table::data.table()
, where the
latter is a design of configurations produced from the former - e.g.,
by calling a generate_design_grid()
or by sampling.
Public fields
param_set
(ParamSet).
data
(
data.table::data.table()
)
Storeddata
.
Methods
Public methods
Method new()
Creates a new instance of this R6 class.
Usage
Design$new(param_set, data, remove_dupl)
Arguments
param_set
(ParamSet).
data
(
data.table::data.table()
)
Storeddata
.remove_dupl
(
logical(1)
)
Remove duplicates?
Method format()
Helper for print outputs.
Usage
Design$format(...)
Arguments
...
(ignored).
Method print()
Printer.
Usage
Design$print(...)
Arguments
...
(ignored).
Method transpose()
Converts data
into a list of lists of row-configurations,
possibly removes NA
entries of inactive parameter values due to unsatisfied dependencies,
and possibly calls the trafo
function of the ParamSet.
Usage
Design$transpose(filter_na = TRUE, trafo = TRUE)
Arguments
filter_na
(
logical(1)
)
ShouldNA
entries of inactive parameter values due to unsatisfied dependencies be removed?trafo
(
logical(1)
)
Should thetrafo
function of the ParamSet be called?
Method clone()
The objects of this class are cloneable with this method.
Usage
Design$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Domain: Parameter Range without an Id
Description
A Domain
object is a representation of a single dimension of a ParamSet
. Domain
objects are used to construct
ParamSet
s, either through the ps()
short form, through the ParamSet
constructor itself,
or through the ParamSet
$search_space()
mechanism (see
to_tune()
).
For each of the basic parameter classes ("ParamInt"
, "ParamDbl"
, "ParamLgl"
, "ParamFct"
, and "ParamUty"
) there is a function constructing a Domain
object
(p_int()
, p_dbl()
, p_lgl()
, p_fct()
, p_uty()
). They each have fitting construction arguments that control their
bounds and behavior.
Domain
objects are representations of parameter ranges and are intermediate objects to be used in short form
constructions in to_tune()
and ps()
. Because of their nature, they should not be modified by the user, once constructed.
The Domain
object's internals are subject to change and should not be relied upon.
Usage
p_dbl(
lower = -Inf,
upper = Inf,
special_vals = list(),
default = NO_DEF,
tags = character(),
tolerance = sqrt(.Machine$double.eps),
depends = NULL,
trafo = NULL,
logscale = FALSE,
init,
aggr = NULL,
in_tune_fn = NULL,
disable_in_tune = NULL
)
p_fct(
levels,
special_vals = list(),
default = NO_DEF,
tags = character(),
depends = NULL,
trafo = NULL,
init,
aggr = NULL,
in_tune_fn = NULL,
disable_in_tune = NULL
)
p_int(
lower = -Inf,
upper = Inf,
special_vals = list(),
default = NO_DEF,
tags = character(),
tolerance = sqrt(.Machine$double.eps),
depends = NULL,
trafo = NULL,
logscale = FALSE,
init,
aggr = NULL,
in_tune_fn = NULL,
disable_in_tune = NULL
)
p_lgl(
special_vals = list(),
default = NO_DEF,
tags = character(),
depends = NULL,
trafo = NULL,
init,
aggr = NULL,
in_tune_fn = NULL,
disable_in_tune = NULL
)
p_uty(
custom_check = NULL,
special_vals = list(),
default = NO_DEF,
tags = character(),
depends = NULL,
trafo = NULL,
repr = substitute(default),
init,
aggr = NULL,
in_tune_fn = NULL,
disable_in_tune = NULL
)
Arguments
lower |
( |
upper |
( |
special_vals |
( |
default |
( |
tags |
(
|
tolerance |
( |
depends |
( |
trafo |
( |
logscale |
( |
init |
( |
aggr |
( |
in_tune_fn |
( |
disable_in_tune |
(named |
levels |
( |
custom_check |
( |
repr |
( |
Details
Although the levels
values of a constructed p_fct()
will always be character
-valued, the p_fct
function admits
a levels
argument that goes beyond this:
Besides a character
vector, any atomic vector or list (optionally named) may be given. (If the value is a list
that is not named, the names are inferred using as.character()
on the values.) The resulting Domain
will
correspond to a range of values given by the names of the levels
argument with a trafo
that maps the character
names to the arbitrary values of the levels
argument.
Value
A Domain
object.
See Also
Other ParamSet construction helpers:
ps()
,
to_tune()
Examples
params = ps(
unbounded_integer = p_int(),
bounded_double = p_dbl(0, 10),
half_bounded_integer = p_dbl(1),
half_bounded_double = p_dbl(upper = 1),
double_with_trafo = p_dbl(-1, 1, trafo = exp),
extra_double = p_dbl(0, 1, special_vals = list("xxx"), tags = "tagged"),
factor_param = p_fct(c("a", "b", "c")),
factor_param_with_implicit_trafo = p_fct(list(a = 1, b = 2, c = list()))
)
print(params)
params$trafo(list(
bounded_double = 1,
double_with_trafo = 1,
factor_param = "c",
factor_param_with_implicit_trafo = "c"
))
# logscale:
params = ps(x = p_dbl(1, 100, logscale = TRUE))
# The ParamSet has bounds log(1) .. log(100):
print(params)
# When generating a equidistant grid, it is equidistant within log values
grid = generate_design_grid(params, 3)
print(grid)
# But the values are on a log scale with desired bounds after trafo
print(grid$transpose())
# Integer parameters with logscale are `p_dbl()`s pre-trafo
params = ps(x = p_int(0, 10, logscale = TRUE))
print(params)
grid = generate_design_grid(params, 4)
print(grid)
# ... but get transformed to integers.
print(grid$transpose())
# internal tuning
param_set = ps(
iters = p_int(0, Inf, tags = "internal_tuning", aggr = function(x) round(mean(unlist(x))),
in_tune_fn = function(domain, param_vals) {
stopifnot(domain$lower <= 1)
stopifnot(param_vals$early_stopping == TRUE)
domain$upper
},
disable_in_tune = list(early_stopping = FALSE)),
early_stopping = p_lgl()
)
param_set$set_values(
iters = to_tune(upper = 100, internal = TRUE),
early_stopping = TRUE
)
param_set$convert_internal_search_space(param_set$search_space())
param_set$aggr_internal_tuned_values(
list(iters = list(1, 2, 3))
)
param_set$disable_internal_tuning("iters")
param_set$values$early_stopping
Extra data type for "no default value"
Description
Special new data type for no-default. Not often needed by the end-user, mainly internal.
-
NO_DEF
: Singleton object for type, used inDomain
when no default is given. -
is_nodefault()
: Is an object the 'no default' object?
ParamSet
Description
An object representing the space of possible parametrizations of a function or another object.
ParamSet
s are used on the side of objects being parameterized, where they function as a configuration space determining the set of possible configurations accepted by these objects.
They can also be used to specify search spaces for optimization, indicating the set of legal configurations to try out.
It is often convenient to generate search spaces from configuration spaces, which can be done using the $search_space()
method in combination with to_tune()
/ TuneToken
objects.
Individual dimensions of a ParamSet
are specified by Domain
objects, created as p_dbl()
, p_lgl()
etc.
The field $values
can be used to store an active configuration or to partially fix
some parameters to constant values – the precise effect can be determined by the object being parameterized.
Constructing a ParamSet
can be done using ParamSet$new()
in combination with a named list of Domain
objects.
This route is recommended when the set of dimensions (i.e. the members of this named list) is dynamically created, such as when the number of parameters is variable.
ParamSet
s can also be created using the ps()
shorthand, which is the recommended way when the set of parameters is fixed.
In practice, the majority of cases where a ParamSet
is created, the ps()
should be used.
S3 methods and type converters
-
as.data.table()
ParamSet
->data.table::data.table()
Compact representation as datatable. Col types are:
id: character
class: character
lower, upper: numeric
levels: list col, with NULL elements
nlevels: integer valued numeric
is_bounded: logical
special_vals: list col of list
default: list col
storage_type: character
tags: list col of character vectors
Public fields
assert_values
(
logical(1)
)
Should values be checked for validity during assigment to active binding$values
? Default isTRUE
, only switch this off if you know what you are doing.
Active bindings
data
(
data.table
)data.table
representation of theParamSet
.values
(named
list()
)
Currently set / fixed parameter values. Settable, and feasibility of values will be checked when you set them. You do not have to set values for all parameters, but only for a subset. When you set values, all previously set values will be unset / removed.tags
(named
list()
ofcharacter()
)
Can be used to group and subset parameters. Named with parameter IDs.params
(named
list()
)
data.table
representing the combinedDomain
objects used to construct theParamSet
. Used for internal purpuses. Its use by external code is deprecated.domains
(named
list
ofDomain
) List ofDomain
objects that could be used to initialize thisParamSet
.extra_trafo
(
function(x, param_set)
)
Transformation function. Settable. User has to pass afunction(x)
, of the form
(namedlist()
, ParamSet) -> namedlist()
.
The function is responsible to transform a feasible configuration into another encoding, before potentially evaluating the configuration with the target algorithm. For the output, not many things have to hold. It needs to have unique names, and the target algorithm has to accept the configuration. For convenience, the self-paramset is also passed in, if you need some info from it (e.g. tags). Is NULL by default, and you can set it to NULL to switch the transformation off.constraint
(
function(x)
)
Constraint function. Settable. This function must evaluate a namedlist()
of values and determine whether it satisfies constraints, returning a scalarlogical(1)
value.deps
(
data.table::data.table()
)
Table has colsid
(character(1)
) andon
(character(1)
) andcond
(Condition). Lists all (direct) dependency parents of a param, through parameter IDs. Internally created by a call toadd_dep
. Settable, if you want to remove dependencies or perform other changes.length
(
integer(1)
)
Number of contained parameters.is_empty
(
logical(1)
)
Is theParamSet
empty? Named with parameter IDs.has_trafo
(
logical(1)
)
Whether atrafo
function is present, in parameters or inextra_trafo
.has_extra_trafo
(
logical(1)
)
Whetherextra_trafo
is set.has_deps
(
logical(1)
)
Whether the parameter dependencies are presenthas_constraint
(
logical(1)
)
Whether parameter constraint is set.all_numeric
(
logical(1)
)
IsTRUE
if all parameters arep_dbl()
orp_int()
.all_categorical
(
logical(1)
)
IsTRUE
if all parameters arep_fct()
andp_lgl()
.all_bounded
(
logical(1)
)
IsTRUE
if all parameters are bounded.class
(named
character()
)
Classes of contained parameters. Named with parameter IDs.lower
(named
double()
)
Lower bounds of numeric parameters (NA
for non-numerics). Named with parameter IDs.upper
(named
double()
)
Upper bounds of numeric parameters (NA
for non-numerics). Named with parameter IDs.levels
(named
list()
ofcharacter
)
Allowed levels of categorical parameters (NULL
for non-categoricals). Named with parameter IDs.storage_type
(
character()
)
Data types of parameters when stored in tables. Named with parameter IDs.special_vals
(named
list()
oflist()
)
Special values for all parameters. Named with parameter IDs.default
(named
list()
)
Default values of all parameters. If no default exists, element is not present. Named with parameter IDs.has_trafo_param
(
logical()
)
Whethertrafo
is set for any parameter.is_logscale
(
logical()
)
Whethertrafo
was set tologscale
during construction.
Note that this only refers to thelogscale
flag set during construction, e.g.p_dbl(logscale = TRUE)
. If the parameter was set to logscale manually, e.g. throughp_dbl(trafo = exp)
, thisis_logscale
will beFALSE
.nlevels
(named
integer()
)
Number of distinct levels of parameters.Inf
for double parameters or unbounded integer parameters. Named with param IDs.is_number
(named
logical()
)
Whether parameter isp_dbl()
orp_int()
. Named with parameter IDs.is_categ
(named
logical()
)
Whether parameter isp_fct()
orp_lgl()
. Named with parameter IDs.is_bounded
(named
logical()
)
Whether parameters have finite bounds. Named with parameter IDs.
Methods
Public methods
Method new()
Creates a new instance of this R6 class.
Usage
ParamSet$new(params = named_list(), allow_dangling_dependencies = FALSE)
Arguments
params
(named
list()
)
List ofDomain
, named with their respective ID.allow_dangling_dependencies
(
character(1)
)
Whether dependencies depending on parameters that are not present should be allowed. A parameterx
havingdepends = y == 0
ify
is not present would usually throw an error, but if dangling dependencies are allowed, the dependency is added regardless. This is mainly for internal use.
Method ids()
Retrieves IDs of contained parameters based on some filter criteria
selections, NULL
means no restriction.
Only returns IDs of parameters that satisfy all conditions.
Usage
ParamSet$ids(class = NULL, tags = NULL, any_tags = NULL)
Arguments
class
(
character()
)
Typically a subset of"ParamDbl"
,"ParamInt"
,"ParamFct"
,"ParamLgl"
,"ParamUty"
. Other classes are possible if implemented by 3rd party packages. Return only IDs of dimensions with the given class.tags
(
character()
). Return only IDs of dimensions that have all tags given in this argument.any_tags
(
character()
). Return only IDs of dimensions that have at least one of the tags given in this argument.
Returns
character()
.
Method get_values()
Retrieves parameter values based on some selections, NULL
means no
restriction and is equivalent to $values
.
Only returns values of parameters that satisfy all conditions.
Usage
ParamSet$get_values( class = NULL, tags = NULL, any_tags = NULL, type = "with_token", check_required = TRUE, remove_dependencies = TRUE )
Arguments
class
(
character()
). See$ids()
.tags
(
character()
). See$ids()
.any_tags
(
character()
). See$ids()
.type
(
character(1)
)
Return values"with_token"
(i.e. all values),check_required
(
logical(1)
)
Check if all required parameters are set?remove_dependencies
(
logical(1)
)
IfTRUE
, set values with dependencies that are not fulfilled toNULL
.
Returns
Named list()
.
Method set_values()
Allows to to modify (and overwrite) or replace the parameter values. Per default already set values are being kept unless new values are being provided.
Usage
ParamSet$set_values(..., .values = list(), .insert = TRUE)
Arguments
...
(any)
Named parameter values..values
(named
list()
)
Named list with parameter values. Names must not already appear in...
..insert
(
logical(1)
)
Whether to insert the values (old values are being kept, if not overwritten), or to replace all values. Default is TRUE.
Method trafo()
Perform transformation specified by the trafo
of Domain
objects, as well as the $extra_trafo
field.
Usage
ParamSet$trafo(x, param_set = self)
Arguments
x
(named
list()
|data.frame
)
The value(s) to be transformed.param_set
(
ParamSet
)
Passed toextra_trafo()
. Note that theextra_trafo
ofself
is used, not theextra_trafo
of theParamSet
given in theparam_set
argument. In almost all cases, the defaultparam_set = self
should be used.
Method aggr_internal_tuned_values()
Aggregate parameter values according to their aggregation rules.
Usage
ParamSet$aggr_internal_tuned_values(x)
Arguments
x
(named
list()
oflist()
s)
The value(s) to be aggregated. Names are parameter values. The aggregation function is selected based on the parameter.
Returns
(named list()
)
Method disable_internal_tuning()
Set the parameter values so that internal tuning for the selected parameters is disabled.
Usage
ParamSet$disable_internal_tuning(ids)
Arguments
ids
(
character()
)
The ids of the parameters for which to disable internal tuning.
Returns
Self
Method convert_internal_search_space()
Convert all parameters from the search space to parameter values using the transformation given by
in_tune_fn
.
Usage
ParamSet$convert_internal_search_space(search_space)
Arguments
search_space
(
ParamSet
)
The internal search space.
Returns
(named list()
)
Method test_constraint()
checkmate-like test-function. Takes a named list.
Return FALSE
if the given $constraint
is not satisfied, TRUE
otherwise.
Note this is different from satisfying the bounds or types given by the ParamSet
itself:
If x
does not satisfy these, an error will be thrown, given that assert_value
is TRUE
.
Usage
ParamSet$test_constraint(x, assert_value = TRUE)
Arguments
x
(named
list()
)
The value to test.assert_value
(
logical(1)
)
Whether to verify thatx
satisfies the bounds and types given by thisParamSet
. Should beTRUE
unless this was already checked before.
Returns
logical(1)
: Whether x
satisfies the $constraint
.
Method test_constraint_dt()
checkmate-like test-function. Takes a data.table
.
For each row, return FALSE
if the given $constraint
is not satisfied, TRUE
otherwise.
Note this is different from satisfying the bounds or types given by the ParamSet
itself:
If x
does not satisfy these, an error will be thrown, given that assert_value
is TRUE
.
Usage
ParamSet$test_constraint_dt(x, assert_value = TRUE)
Arguments
x
(
data.table
)
The values to test.assert_value
(
logical(1)
)
Whether to verify thatx
satisfies the bounds and types given by thisParamSet
. Should beTRUE
unless this was already checked before.
Returns
logical
: For each row in x
, whether it satisfies the $constraint
.
Method check()
checkmate-like check-function. Takes a named list.
A point x is feasible, if it configures a subset of params,
all individual param constraints are satisfied and all dependencies are satisfied.
Params for which dependencies are not satisfied should not be part of x
.
Constraints and dependencies are not checked when check_strict
is FALSE
.
Usage
ParamSet$check(xs, check_strict = TRUE, sanitize = FALSE)
Arguments
xs
(named
list()
).check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied.sanitize
(
logical(1)
)
Whether to move values that are slightly outside bounds to valid values. These values are accepted independent ofsanitize
(depending on thetolerance
arguments ofp_dbl()
andp_int()
) . Ifsanitize
isTRUE
, the additional effect is that, should checks pass, the sanitized values ofxs
are added to the result as attribute"sanitized"
.
Returns
If successful TRUE
, if not a string with an error message.
Method check_dependencies()
checkmate-like check-function. Takes a named list. Checks that all individual param dependencies are satisfied.
Usage
ParamSet$check_dependencies(xs)
Arguments
xs
(named
list()
).
Returns
If successful TRUE
, if not a string with an error message.
Method test()
checkmate-like test-function. Takes a named list.
A point x is feasible, if it configures a subset of params,
all individual param constraints are satisfied and all dependencies are satisfied.
Params for which dependencies are not satisfied should not be part of x
.
Constraints and dependencies are not checked when check_strict
is FALSE
.
Usage
ParamSet$test(xs, check_strict = TRUE)
Arguments
xs
(named
list()
).check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied.
Returns
If successful TRUE
, if not FALSE
.
Method assert()
checkmate-like assert-function. Takes a named list.
A point x is feasible, if it configures a subset of params,
all individual param constraints are satisfied and all dependencies are satisfied.
Params for which dependencies are not satisfied should not be part of x
.
Constraints and dependencies are not checked when check_strict
is FALSE
.
Usage
ParamSet$assert( xs, check_strict = TRUE, .var.name = vname(xs), sanitize = FALSE )
Arguments
xs
(named
list()
).check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied..var.name
(
character(1)
)
Name of the checked object to print in error messages.
Defaults to the heuristic implemented in vname.sanitize
(
logical(1)
)
Whether to move values that are slightly outside bounds to valid values. These values are accepted independent ofsanitize
(depending on thetolerance
arguments ofp_dbl()
andp_int()
) . Ifsanitize
isTRUE
, the additional effect is thatxs
is converted to within bounds.
Returns
If successful xs
invisibly, if not an error message.
Method check_dt()
checkmate-like check-function. Takes a data.table::data.table
where rows are points and columns are parameters.
A point x is feasible, if it configures a subset of params,
all individual param constraints are satisfied and all dependencies are satisfied.
Params for which dependencies are not satisfied should not be part of x
.
Constraints and dependencies are not checked when check_strict
is FALSE
.
Usage
ParamSet$check_dt(xdt, check_strict = TRUE)
Arguments
xdt
(data.table::data.table |
data.frame()
).check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied.
Returns
If successful TRUE
, if not a string with the error message.
Method test_dt()
checkmate-like test-function (s. $check_dt()
).
Usage
ParamSet$test_dt(xdt, check_strict = TRUE)
Arguments
xdt
check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied.
Returns
If successful TRUE
, if not FALSE
.
Method assert_dt()
checkmate-like assert-function (s. $check_dt()
).
Usage
ParamSet$assert_dt(xdt, check_strict = TRUE, .var.name = vname(xdt))
Arguments
xdt
check_strict
(
logical(1)
)
Whether to check that constraints and dependencies are satisfied..var.name
(
character(1)
)
Name of the checked object to print in error messages.
Defaults to the heuristic implemented in vname.
Returns
If successful xs
invisibly, if not, an error is generated.
Method qunif()
Map a matrix
or data.frame
of values between 0 and 1 to proportional values inside the feasible intervals of individual parameters.
Usage
ParamSet$qunif(x)
Arguments
x
(
matrix
|data.frame
)
Values to map. Column names must be a subset of the names of parameters.
Returns
data.table
.
Method get_domain()
get the Domain
object that could be used to create a given parameter.
Usage
ParamSet$get_domain(id)
Arguments
id
(
character(1)
).
Returns
Method subset()
Create a new ParamSet
restricted to the passed IDs.
Usage
ParamSet$subset( ids, allow_dangling_dependencies = FALSE, keep_constraint = TRUE )
Arguments
ids
(
character()
).allow_dangling_dependencies
(
logical(1)
)
Whether to allow subsets that cut across parameter dependencies. Dependencies that point to dropped parameters are kept (but will be "dangling", i.e. their"on"
will not be present).keep_constraint
(
logical(1)
)
Whether to keep the$constraint
function.
Returns
ParamSet
.
Method subspaces()
Create new one-dimensional ParamSet
s for each dimension.
Usage
ParamSet$subspaces(ids = private$.params$id)
Arguments
ids
(
character()
)
IDs for which to createParamSet
s. Defaults to all IDs.
Returns
named list()
of ParamSet
.
Method flatten()
Create a ParamSet
from this object, even if this object itself is not
a ParamSet
but e.g. a ParamSetCollection
.
Usage
ParamSet$flatten()
Method search_space()
Construct a ParamSet
to tune over. Constructed from TuneToken
in $values
, see to_tune()
.
Usage
ParamSet$search_space(values = self$values)
Arguments
values
(
named list
): optional named list ofTuneToken
objects to convert, in place of$values
.
Method add_dep()
Adds a dependency to this set, so that param id
now depends on param on
.
Usage
ParamSet$add_dep(id, on, cond, allow_dangling_dependencies = FALSE)
Arguments
id
(
character(1)
).on
(
character(1)
).cond
(Condition).
allow_dangling_dependencies
(
logical(1)
): Whether to allow dependencies on parameters that are not present.
Method format()
Helper for print outputs.
Usage
ParamSet$format()
Arguments
...
(ignored).
Method print()
Printer.
Usage
ParamSet$print( ..., hide_cols = c("levels", "is_bounded", "special_vals", "tags", "storage_type") )
Arguments
...
(ignored).
hide_cols
(
character()
)
Which fields should not be printed? Default is"levels"
,"is_bounded"
,"special_vals"
,"tags"
, and"storage_type"
.
Method clone()
The objects of this class are cloneable with this method.
Usage
ParamSet$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
pset = ParamSet$new(
params = list(
d = p_dbl(lower = -5, upper = 5, default = 0, trafo = function(x) 2^x),
f = p_fct(levels = letters[1:3])
)
)
# alternative, recommended way of construction in this case since the
# parameter list is not dynamic:
pset = ps(
d = p_dbl(lower = -5, upper = 5, default = 0, trafo = function(x) 2^x),
f = p_fct(levels = letters[1:3])
)
pset$check(list(d = 2.1, f = "a"))
pset$check(list(d = 2.1, f = "d"))
ParamSetCollection
Description
A collection of multiple ParamSet
objects.
The collection is basically a light-weight wrapper / container around references to multiple sets.
In order to ensure unique param names, every param in the collection is referred to with "<set_id>.<param_id>", where
<set_id>
is the name of the entry a givenParamSet
in the named list given during construction. Parameters fromParamSet
with empty (i.e.""
)set_id
are referenced directly. MultipleParamSet
s withset_id
""
can be combined, but their parameter names may not overlap to avoid name clashes.When you either ask for 'values' or set them, the operation is delegated to the individual, contained
ParamSet
references. The collection itself does not maintain avalues
state. This also implies that if you directly changevalues
in one of the referenced sets, this change is reflected in the collection.Dependencies: It is possible to currently handle dependencies
regarding parameters inside of the same set - in this case simply add the dependency to the set, best before adding the set to the collection
across sets, where a param from one set depends on the state of a param from another set - in this case add call
add_dep
on the collection.
If you call
deps
on the collection, you are returned a complete table of dependencies, from sets and across sets.
Super class
paradox::ParamSet
-> ParamSetCollection
Active bindings
deps
(
data.table::data.table()
)
Table has colsid
(character(1)
) andon
(character(1)
) andcond
(Condition). Lists all (direct) dependency parents of a param, through parameter IDs. Internally created by a call toadd_dep
. Settable, if you want to remove dependencies or perform other changes.extra_trafo
(
function(x, param_set)
)
Transformation function. Settable. User has to pass afunction(x)
, of the form
(namedlist()
, ParamSet) -> namedlist()
.
The function is responsible to transform a feasible configuration into another encoding, before potentially evaluating the configuration with the target algorithm. For the output, not many things have to hold. It needs to have unique names, and the target algorithm has to accept the configuration. For convenience, the self-paramset is also passed in, if you need some info from it (e.g. tags). Is NULL by default, and you can set it to NULL to switch the transformation off.constraint
(
function(x)
)
Constraint function. Settable. This function must evaluate a namedlist()
of values and determine whether it satisfies constraints, returning a scalarlogical(1)
value.sets
(named
list()
)
Read-onlylist
of ofParamSet
s contained in thisParamSetCollection
. This field provides direct references to theParamSet
objects.
Methods
Public methods
Inherited methods
paradox::ParamSet$add_dep()
paradox::ParamSet$aggr_internal_tuned_values()
paradox::ParamSet$assert()
paradox::ParamSet$assert_dt()
paradox::ParamSet$check()
paradox::ParamSet$check_dependencies()
paradox::ParamSet$check_dt()
paradox::ParamSet$format()
paradox::ParamSet$get_domain()
paradox::ParamSet$get_values()
paradox::ParamSet$ids()
paradox::ParamSet$print()
paradox::ParamSet$qunif()
paradox::ParamSet$search_space()
paradox::ParamSet$set_values()
paradox::ParamSet$subset()
paradox::ParamSet$subspaces()
paradox::ParamSet$test()
paradox::ParamSet$test_constraint()
paradox::ParamSet$test_constraint_dt()
paradox::ParamSet$test_dt()
paradox::ParamSet$trafo()
Method new()
Creates a new instance of this R6 class.
Usage
ParamSetCollection$new(sets, tag_sets = FALSE, tag_params = FALSE)
Arguments
sets
(named
list()
of ParamSet)
ParamSet objects are not cloned. Names are used as "set_id" for the naming scheme of delegated parameters.tag_sets
(
logical(1)
)
Whether to add tags of the form"set_<set_id>"
to each parameter originating from a givenParamSet
given with name<set_id>
.tag_params
(
logical(1)
)
Whether to add tags of the form"param_<param_id>"
to each parameter with original ID<param_id>
.
Method add()
Adds a ParamSet
to this collection.
Usage
ParamSetCollection$add(p, n = "", tag_sets = FALSE, tag_params = FALSE)
Arguments
p
(ParamSet).
n
(
character(1)
)
Name to use. Default""
.tag_sets
(
logical(1)
)
Whether to add tags of the form"set_<n>"
to the newly added parameters.tag_params
(
logical(1)
)
Whether to add tags of the form"param_<param_id>"
to each parameter with original ID<param_id>
.
Method disable_internal_tuning()
Set the parameter values so that internal tuning for the selected parameters is disabled.
Usage
ParamSetCollection$disable_internal_tuning(ids)
Arguments
ids
(
character()
)
The ids of the parameters for which to disable internal tuning.
Returns
Self
Method convert_internal_search_space()
Convert all parameters from the search space to parameter values using the transformation given by
in_tune_fn
.
Usage
ParamSetCollection$convert_internal_search_space(search_space)
Arguments
search_space
(
ParamSet
)
The internal search space.
Returns
(named list()
)
Method flatten()
Create a ParamSet
from this ParamSetCollection
.
Usage
ParamSetCollection$flatten()
Method clone()
The objects of this class are cloneable with this method.
Usage
ParamSetCollection$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Sampler Class
Description
This is the abstract base class for sampling objects like Sampler1D, SamplerHierarchical or SamplerJointIndep.
Public fields
param_set
(
ParamSet
)
Domain / support of the distribution we want to sample from.
Methods
Public methods
Method new()
Creates a new instance of this R6 class.
Note that this object is typically constructed via derived classes, e.g., Sampler1D.
Usage
Sampler$new(param_set)
Arguments
Method sample()
Sample n
values from the distribution.
Usage
Sampler$sample(n)
Arguments
n
(
integer(1)
).
Returns
Method format()
Helper for print outputs.
Usage
Sampler$format(...)
Arguments
...
(ignored).
Method print()
Printer.
Usage
Sampler$print(...)
Arguments
...
(ignored).
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
Sampler1D Class
Description
1D sampler, abstract base class for Sampler like Sampler1DUnif, Sampler1DRfun, Sampler1DCateg and Sampler1DNormal.
Super class
paradox::Sampler
-> Sampler1D
Active bindings
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Note that this object is typically constructed via derived classes,
e.g., Sampler1DUnif
.
Usage
Sampler1D$new(param)
Arguments
param
(
ParamSet
)
Domain / support of the distribution we want to sample from. Must be one-dimensional.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler1D$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
Sampler1DCateg Class
Description
Sampling from a discrete distribution, for a ParamSet
containing a single p_fct()
or p_lgl()
.
Super classes
paradox::Sampler
-> paradox::Sampler1D
-> Sampler1DCateg
Public fields
prob
(
numeric()
| NULL)
Numeric vector ofparam$nlevels
probabilities.
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
Sampler1DCateg$new(param, prob = NULL)
Arguments
param
(
ParamSet
)
Domain / support of the distribution we want to sample from. Must be one-dimensional.prob
(
numeric()
| NULL)
Numeric vector ofparam$nlevels
probabilities, which is uniform by default.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler1DCateg$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
Sampler1DNormal Class
Description
Normal sampling (potentially truncated) for p_dbl()
.
Super classes
paradox::Sampler
-> paradox::Sampler1D
-> paradox::Sampler1DRfun
-> Sampler1DNormal
Active bindings
mean
(
numeric(1)
)
Mean parameter of the normal distribution.sd
(
numeric(1)
)
SD parameter of the normal distribution.
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
Sampler1DNormal$new(param, mean = NULL, sd = NULL)
Arguments
param
(
ParamSet
)
Domain / support of the distribution we want to sample from. Must be one-dimensional.mean
(
numeric(1)
)
Mean parameter of the normal distribution. Default ismean(c(param$lower, param$upper)
.sd
(
numeric(1)
)
SD parameter of the normal distribution. Default is(param$upper - param$lower)/4
.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler1DNormal$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
Sampler1DRfun Class
Description
Arbitrary sampling from 1D RNG functions from R.
Super classes
paradox::Sampler
-> paradox::Sampler1D
-> Sampler1DRfun
Public fields
rfun
(
function()
)
Random number generator function.trunc
(
logical(1)
)
TRUE
enables naive rejection sampling, so we stay inside of [lower, upper].
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
Sampler1DRfun$new(param, rfun, trunc = TRUE)
Arguments
param
(
ParamSet
)
Domain / support of the distribution we want to sample from. Must be one-dimensional.rfun
(
function()
)
Random number generator function, e.g.rexp
to sample from exponential distribution.trunc
(
logical(1)
)
TRUE
enables naive rejection sampling, so we stay inside of [lower, upper].
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler1DRfun$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
Sampler1DUnif Class
Description
Uniform random sampler for arbitrary (bounded) parameters.
Super classes
paradox::Sampler
-> paradox::Sampler1D
-> Sampler1DUnif
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
Sampler1DUnif$new(param)
Arguments
param
(
ParamSet
)
Domain / support of the distribution we want to sample from. Must be one-dimensional.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sampler1DUnif$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
SamplerHierarchical
,
SamplerJointIndep
,
SamplerUnif
SamplerHierarchical Class
Description
Hierarchical sampling for arbitrary param sets with dependencies, where the user specifies 1D samplers per param.
Dependencies are topologically sorted, parameters are then sampled in topological order,
and if dependencies do not hold, values are set to NA
in the resulting data.table
.
Super class
paradox::Sampler
-> SamplerHierarchical
Public fields
samplers
(
list()
)
List ofSampler1D
objects that gives a Sampler for each dimension in theparam_set
.
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
SamplerHierarchical$new(param_set, samplers)
Arguments
Method clone()
The objects of this class are cloneable with this method.
Usage
SamplerHierarchical$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerJointIndep
,
SamplerUnif
SamplerJointIndep Class
Description
Create joint, independent sampler out of multiple other samplers.
Super class
paradox::Sampler
-> SamplerJointIndep
Public fields
samplers
(
list()
)
List ofSampler
objects.
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
SamplerJointIndep$new(samplers)
Arguments
samplers
(
list()
)
List ofSampler
objects.
Method clone()
The objects of this class are cloneable with this method.
Usage
SamplerJointIndep$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerUnif
SamplerUnif Class
Description
Uniform random sampling for an arbitrary (bounded) ParamSet. Constructs 1 uniform sampler per parameter, then passes them to SamplerHierarchical. Hence, also works for ParamSets sets with dependencies.
Super classes
paradox::Sampler
-> paradox::SamplerHierarchical
-> SamplerUnif
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
SamplerUnif$new(param_set)
Arguments
Method clone()
The objects of this class are cloneable with this method.
Usage
SamplerUnif$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other Sampler:
Sampler
,
Sampler1D
,
Sampler1DCateg
,
Sampler1DNormal
,
Sampler1DRfun
,
Sampler1DUnif
,
SamplerHierarchical
,
SamplerJointIndep
Assertions for Params and ParamSets
Description
Assertions for Params and ParamSets
Usage
assert_param_set(
param_set,
cl = NULL,
no_untyped = FALSE,
must_bounded = FALSE,
no_deps = FALSE
)
Arguments
param_set |
( |
cl |
( |
no_untyped |
( |
must_bounded |
( |
no_deps |
( |
Value
The checked object, invisibly.
Dependency Condition
Description
Condition object, to specify the condition in a dependency.
Usage
condition_test(cond, x)
condition_as_string(cond, lhs_chr = "x")
Condition(rhs, condition_format_string)
Arguments
cond |
( |
x |
( |
lhs_chr |
( |
rhs |
( |
condition_format_string |
( |
Functions
-
condition_test()
: Used internally. Tests whether a value satisfies a given condition. Vectorizes whenx
is atomic. -
condition_as_string()
: Used internally. Returns a string that represents the condition for pretty printing, in the form"<lhs> <relation> <rhs>"
, e.g."x == 3"
or"param %in% {1, 2, 10}"
.
Currently implemented simple conditions
-
CondEqual(rhs)
Value must be equal torhs
. -
CondAnyOf(rhs)
Value must be any value ofrhs
.
Extract Parameter Default Values
Description
Extract parameter default values.
Usage
default_values(x, ...)
## S3 method for class 'ParamSet'
default_values(x, ...)
Arguments
x |
( |
... |
(any) |
Value
list()
.
Check Value Validity
Description
checkmate-like check-function. Check whether a list of values is feasible in the domain.
A value is feasible if it is of the same storage_type
, inside of the bounds or element of
special_vals
. TuneToken
s are generally not accepted, so they should be filtered out
before the call, if present.
domain_check
will return TRUE
for accepted values, a character(1)
error message otherwise.
domain_test
will return TRUE
for accepted values, FALSE
otherwise.
domain_assert
will return the param
argument silently for accepted values, and throw an error message otherwise.
Usage
domain_check(param, values, internal = FALSE)
domain_assert(
param,
values,
internal = FALSE,
.var.name = checkmate::vname(param),
add = NULL
)
domain_test(param, values)
Arguments
param |
( |
values |
( |
internal |
( |
Value
If successful TRUE
, if not a string with the error message.
Whether a Given Domain is Bounded
Description
This should generally be TRUE
when lower
and upper
are given and finite, or when the nlevels
is finite, and FALSE
otherwise.
Usage
domain_is_bounded(param)
Arguments
param |
( |
Value
logical
.
Whether a Given Domain is Categorical
Description
This should generally be TRUE
for categorical Domain
s, such as p_fct()
or p_lgl()
, and FALSE
otherwise.
Usage
domain_is_categ(param)
Arguments
param |
( |
Value
logical
.
Whether a Given Domain is Numeric
Description
This should generally be TRUE
for discrete or continuous numeric Domain
s, and FALSE
otherwise.
Usage
domain_is_number(param)
Arguments
param |
( |
Value
logical
.
The Number of Levels of a Given Domain
Description
This should be the number of discrete possible levels for discrete type Domain
s such as p_int()
or p_fct()
, and
Inf
for continuous or untyped parameters.
Usage
domain_nlevels(param)
Arguments
param |
( |
Value
numeric
.
Transform a Numeric Value to a Sample
Description
Return a valid sample from the given Domain
, given a value from the interval [0, 1]
.
Usage
domain_qunif(param, x)
Arguments
param |
( |
x |
|
Value
any
– format depending on the Domain
.
Map to Acceptable Value
Description
Map values that are close enough to the given Domain
to values that are truly acceptable.
This is used to map numeric()
values that are close to but outside the acceptable interval to the interval bounds.
It is also used to convert integer-valued numeric
values to integer
values for p_int()
.
Usage
domain_sanitize(param, values)
Arguments
param |
( |
values |
( |
Value
any
– format depending on the Domain
.
Generate a Grid Design
Description
Generate a grid with a specified resolution in the parameter space. The resolution for categorical parameters is ignored, these parameters always produce a grid over all their valid levels. For number params the endpoints of the params are always included in the grid.
Usage
generate_design_grid(param_set, resolution = NULL, param_resolutions = NULL)
Arguments
param_set |
( |
resolution |
( |
param_resolutions |
(named |
Value
See Also
Other generate_design:
generate_design_lhs()
,
generate_design_random()
,
generate_design_sobol()
Examples
pset = ps(
ratio = p_dbl(lower = 0, upper = 1),
letters = p_fct(levels = letters[1:3])
)
generate_design_grid(pset, 10)
Generate a Space-Filling LHS Design
Description
Generate a space-filling design using Latin hypercube sampling. Dependent
parameters whose constraints are unsatisfied generate NA
entries in
their respective columns.
Usage
generate_design_lhs(param_set, n, lhs_fun = NULL)
Arguments
param_set |
( |
n |
( |
lhs_fun |
( |
Value
See Also
Other generate_design:
generate_design_grid()
,
generate_design_random()
,
generate_design_sobol()
Examples
pset = ps(
ratio = p_dbl(lower = 0, upper = 1),
letters = p_fct(levels = letters[1:3])
)
if (requireNamespace("lhs", quietly = TRUE)) {
generate_design_lhs(pset, 10)
}
Generate a Random Design
Description
Generates a design with randomly drawn points.
Internally uses SamplerUnif
, hence, also works for ParamSets with dependencies.
If dependencies do not hold, values are set to NA
in the resulting data.table.
Usage
generate_design_random(param_set, n)
Arguments
param_set |
( |
n |
( |
Value
See Also
Other generate_design:
generate_design_grid()
,
generate_design_lhs()
,
generate_design_sobol()
Examples
pset = ps(
ratio = p_dbl(lower = 0, upper = 1),
letters = p_fct(levels = letters[1:3])
)
generate_design_random(pset, 10)
Generate a Space-Filling Sobol Sequence Design
Description
Generate a space-filling design using a Sobol sequence. Dependent
parameters whose constraints are unsatisfied generate NA
entries in
their respective columns.
Uses spacefillr::generate_sobol_set.
Note that non determinism is achieved by sampling the seed argument via
sample(.Machine$integer.max, size = 1L)
.
Usage
generate_design_sobol(param_set, n)
Arguments
param_set |
( |
n |
( |
Value
See Also
Other generate_design:
generate_design_grid()
,
generate_design_lhs()
,
generate_design_random()
Examples
pset = ps(
ratio = p_dbl(lower = 0, upper = 1),
letters = p_fct(levels = letters[1:3])
)
if (requireNamespace("spacefillr", quietly = TRUE)) {
generate_design_sobol(pset, 10)
}
Construct a ParamSet using Short Forms
Description
The ps()
short form constructor uses Domain
objects (p_dbl
, p_fct
, ...) to construct ParamSet
s in a
succinct and readable way.
For more specifics also see the documentation of Domain
.
Usage
ps(
...,
.extra_trafo = NULL,
.constraint = NULL,
.allow_dangling_dependencies = FALSE
)
Arguments
... |
( |
.extra_trafo |
( |
.constraint |
( |
.allow_dangling_dependencies |
( |
Value
A ParamSet
object.
See Also
Other ParamSet construction helpers:
Domain()
,
to_tune()
Examples
pars = ps(
a = p_int(0, 10),
b = p_int(upper = 20),
c = p_dbl(),
e = p_fct(letters[1:3]),
f = p_uty(custom_check = checkmate::check_function)
)
print(pars)
pars = ps(
a = p_dbl(0, 1, trafo = exp),
b = p_dbl(0, 1, trafo = exp),
.extra_trafo = function(x, ps) {
x$c <- x$a + x$b
x
}
)
# See how the addition happens after exp()ing:
pars$trafo(list(a = 0, b = 0))
pars$values = list(
a = to_tune(ps(x = p_int(0, 1),
.extra_trafo = function(x, param_set) list(a = x$x)
)),
# make 'y' depend on 'x', but they are defined in different ParamSets
# Therefore we need to allow dangling dependencies here.
b = to_tune(ps(y = p_int(0, 1, depends = x == 1),
.extra_trafo = function(x, param_set) list(b = x$y),
.allow_dangling_dependencies = TRUE
))
)
pars$search_space()
Create a ParamSet by Repeating a Given ParamSet
Description
Repeat a ParamSet
a given number of times and thus create a larger ParamSet
.
By default, the resulting parameters are prefixed with the string "repX.", where
Xcounts up from 1. It is also possible to tag parameters by their original name and by their prefix, making grouped retrieval e.g. using
$get_values()' easier.
Usage
ps_replicate(
set,
times = length(prefixes),
prefixes = sprintf("rep%s", seq_len(times)),
tag_sets = FALSE,
tag_params = FALSE
)
Arguments
set |
|
times |
( |
prefixes |
( |
tag_sets |
( |
tag_params |
( |
Examples
pset = ps(
i = p_int(),
z = p_lgl()
)
ps_replicate(pset, 3)
ps_replicate(pset, prefixes = c("first", "last"))
pset$values = list(i = 1, z = FALSE)
psr = ps_replicate(pset, 2, tag_sets = TRUE, tag_params = TRUE)
# observe the effect of tag_sets, tag_params:
psr$tags
# note that values are repeated as well
psr$values
psr$set_values(rep1.i = 10, rep2.z = TRUE)
psr$values
# use `any_tags` to get subset of values.
# `any_tags = ` is preferable to `tags = `, since parameters
# could also have other tags. `tags = ` would require the
# selected params to have the given tags exclusively.
# get all values associated with the original parameter `i`
psr$get_values(any_tags = "param_i")
# get all values associated with the first repetition "rep1"
psr$get_values(any_tags = "set_rep1")
Create a ParamSet from a list of ParamSets
Description
This emulates ParamSetCollection$new(sets)
, except that the result is a flat ParamSet
, not a ParamSetCollection
.
The resulting object is decoupled from the input ParamSet
objects: Unlike ParamSetCollection
, changing $values
of
the resulting object will not change the input ParamSet
$values
by reference.
This emulates ParamSetCollection$new(sets)
, which in particular means that the resulting ParamSet
has all the Domain
s
from the input sets
, but some $id
s are changed: If the ParamSet
is given in sets
with a name, then the Domain
s will
have their <id>
changed to <name in "sets">.<id>
. This is also reflected in deps.
The c()
operator, applied to ParamSet
s, is a synony for ps_union()
.
Usage
ps_union(sets, tag_sets = FALSE, tag_params = FALSE)
Arguments
sets |
( |
tag_sets |
( |
tag_params |
( |
Examples
ps1 = ps(x = p_dbl())
ps1$values = list(x = 1)
ps2 = ps(y = p_lgl())
pu = ps_union(list(ps1, ps2))
# same as:
pu = c(ps1, ps2)
pu
pu$values
pu$values$x = 2
pu$values
# p1 is unchanged:
ps1$values
# Prefixes automatically created for named elements.
# This allows repeating components.
pu2 = c(one = ps1, two = ps1, ps2)
pu2
pu2$values
Create a ParamSet Collection
Description
Creates a ParamSetCollection
.
Usage
psc(...)
Arguments
... |
(any) |
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- data.table
Indicate that a Parameter Value should be Tuned
Description
to_tune()
creates a TuneToken
object which can be assigned to the $values
slot of a ParamSet
as an
alternative to a concrete value. This indicates that the value is not given directly but should be tuned using
bbotk or mlr3tuning. If the thus parameterized object
is invoked directly, without being wrapped by or given to a tuner, it will give an error.
The tuning range ParamSet
that is constructed from the TuneToken
values in a ParamSet
's $values
slot
can be accessed through the ParamSet$search_space()
method. This is done automatically by tuners if no tuning range
is given, but it is also possible to access the $search_space()
method, modify it further, and give the modified
ParamSet
to a tuning function (or do anything else with it, nobody is judging you).
A TuneToken
represents the range over which the parameter whose $values
slot it occupies should be tuned over. It
can be constructed via the to_tune()
function in one of several ways:
-
to_tune()
: Indicates a parameter should be tuned over its entire range. Only applies to finite parameters (i.e. discrete or bounded numeric parameters) -
to_tune(lower, upper, logscale)
: Indicates a numeric parameter should be tuned in the inclusive interval spanninglower
toupper
, possibly on a log scale iflogscale
is se toTRUE
. All parameters are optional, and the parameter's own lower / upper bounds are used without log scale, by default. Depending on the parameter, integer (if it is ap_int()
) or real values (if it is ap_dbl()
) are used.
lower
,upper
, andlogscale
can be given by position, except when only one of them is given, in which case it must be named to disambiguate from the following cases.
Whenlogscale
isTRUE
, then atrafo
is generated automatically that transforms to the given bounds. The bounds are log()'d pre-trafo (see examples). See thelogscale
argument ofDomain
functions for more info.
Note that "logscale" is not inherited from theDomain
that theTuneToken
belongs to! Defining a parameter withp_dbl(... logscale = TRUE)
will not automatically give theto_tune()
assigned to it log-scale. -
to_tune(levels)
: Indicates a parameter should be tuned through the given discrete values.levels
can be any named or unnamed atomic vector or list (although in the unnamed case it must be possible to construct a correspondingcharacter
vector with distinct values usingas.character
). -
to_tune(<Domain>)
: The givenDomain
object (constructed e.g. withp_int()
orp_fct()
) indicates the range which should be tuned over. The suppliedtrafo
function is used for parameter transformation. -
to_tune(<ParamSet>)
: The givenParamSet
is used to tune over a single dimension. This is useful for cases where a single evaluation-time parameter value (e.g.p_uty()
) is constructed from multiple tuner-visible parameters (which may not bep_uty()
). If not one-dimensional, the suppliedParamSet
should always contain a$extra_trafo
function, which must then always return alist
with a single entry.
The TuneToken
object's internals are subject to change and should not be relied upon. TuneToken
objects should
only be constructed via to_tune()
, and should only be used by giving them to $values
of a ParamSet
.
Usage
to_tune(..., internal = !is.null(aggr), aggr = NULL)
Arguments
... |
if given, restricts the range to be tuning over, as described above. |
internal |
( |
aggr |
( |
Value
A TuneToken
object.
See Also
Other ParamSet construction helpers:
Domain()
,
ps()
Examples
params = ps(
int = p_int(0, 10),
int_unbounded = p_int(),
dbl = p_dbl(0, 10),
dbl_unbounded = p_dbl(),
dbl_bounded_below = p_dbl(lower = 1),
fct = p_fct(c("a", "b", "c")),
uty1 = p_uty(),
uty2 = p_uty(),
uty3 = p_uty(),
uty4 = p_uty(),
uty5 = p_uty()
)
params$values = list(
# tune over entire range of `int`, 0..10:
int = to_tune(),
# tune over 2..7:
int_unbounded = to_tune(2, 7),
# tune on a log scale in range 1..10;
# recognize upper bound of 10 automatically, but restrict lower bound to 1:
dbl = to_tune(lower = 1, logscale = TRUE),
## This is equivalent to the following:
# dbl = to_tune(p_dbl(log(1), log(10), trafo = exp)),
# nothing keeps us from tuning a dbl over integer values
dbl_unbounded = to_tune(p_int(1, 10)),
# tune over values "a" and "b" only
fct = to_tune(c("a", "b")),
# tune over integers 2..8.
# ParamUty needs type information in form of p_xxx() in to_tune.
uty1 = to_tune(p_int(2, 8)),
# tune uty2 like a factor, trying 1, 10, and 100:
uty2 = to_tune(c(1, 10, 100)),
# tune uty3 like a factor. The factor levels are the names of the list
# ("exp", "square"), but the trafo will generate the values from the list.
# This way you can tune an objective that has function-valued inputs.
uty3 = to_tune(list(exp = exp, square = function(x) x^2)),
# tune through multiple parameters. When doing this, the ParamSet in tune()
# must have the trafo that generates a list with one element and the right
# name:
uty4 = to_tune(ps(
base = p_dbl(0, 1),
exp = p_int(0, 3),
.extra_trafo = function(x, param_set) {
list(uty4 = x$base ^ x$exp)
}
)),
# not all values need to be tuned!
uty5 = 100
)
print(params$values)
print(params$search_space())
# Change `$values` directly and generate new `$search_space()` to play around
params$values$uty3 = 8
params$values$uty2 = to_tune(c(2, 4, 8))
print(params$search_space())
# Notice how `logscale` applies `log()` to lower and upper bound pre-trafo:
params = ps(x = p_dbl())
params$values$x = to_tune(1, 100, logscale = TRUE)
print(params$search_space())
grid = generate_design_grid(params$search_space(), 3)
# The grid is equidistant within log-bounds pre-trafo:
print(grid)
# But the values are on a log scale scale with desired bounds after trafo:
print(grid$transpose())