| ParamSet {paradox} | R Documentation |
ParamSet
Description
An object representing the space of possible parametrizations of a function or another object.
ParamSets 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.
ParamSets 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.tablerepresentation 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.tablerepresenting the combinedDomainobjects used to construct theParamSet. Used for internal purpuses. Its use by external code is deprecated.domains(named
listofDomain) List ofDomainobjects 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 theParamSetempty? Named with parameter IDs.has_trafo(
logical(1))
Whether atrafofunction is present, in parameters or inextra_trafo.has_extra_trafo(
logical(1))
Whetherextra_trafois set.has_deps(
logical(1))
Whether the parameter dependencies are presenthas_constraint(
logical(1))
Whether parameter constraint is set.all_numeric(
logical(1))
IsTRUEif all parameters arep_dbl()orp_int().all_categorical(
logical(1))
IsTRUEif all parameters arep_fct()andp_lgl().all_bounded(
logical(1))
IsTRUEif all parameters are bounded.class(named
character())
Classes of contained parameters. Named with parameter IDs.lower(named
double())
Lower bounds of numeric parameters (NAfor non-numerics). Named with parameter IDs.upper(named
double())
Upper bounds of numeric parameters (NAfor non-numerics). Named with parameter IDs.levels(named
list()ofcharacter)
Allowed levels of categorical parameters (NULLfor 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())
Whethertrafois set for any parameter.is_logscale(
logical())
Whethertrafowas set tologscaleduring construction.
Note that this only refers to thelogscaleflag set during construction, e.g.p_dbl(logscale = TRUE). If the parameter was set to logscale manually, e.g. throughp_dbl(trafo = exp), thisis_logscalewill beFALSE.nlevels(named
integer())
Number of distinct levels of parameters.Inffor 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 parameterxhavingdepends = y == 0ifyis 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_trafoofselfis used, not theextra_trafoof theParamSetgiven in theparam_setargument. In almost all cases, the defaultparam_set = selfshould 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 thatxsatisfies the bounds and types given by thisParamSet. Should beTRUEunless 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 thatxsatisfies the bounds and types given by thisParamSet. Should beTRUEunless 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 thetolerancearguments ofp_dbl()andp_int()) . IfsanitizeisTRUE, the additional effect is that, should checks pass, the sanitized values ofxsare 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 thetolerancearguments ofp_dbl()andp_int()) . IfsanitizeisTRUE, the additional effect is thatxsis 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
xdtcheck_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
xdtcheck_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$constraintfunction.
Returns
ParamSet.
Method subspaces()
Create new one-dimensional ParamSets for each dimension.
Usage
ParamSet$subspaces(ids = private$.params$id)
Arguments
ids(
character())
IDs for which to createParamSets. 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 ofTuneTokenobjects 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
deepWhether 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"))