A set of Param objects.
Please note that when creating a set or adding to it, the parameters of the
resulting set have to be uniquely named with IDs with valid R names.
The set also contains a member variable values
which can be used to store an active configuration / or to partially fix
some parameters to constant values (regarding subsequent sampling or generation of designs).
as.data.table()
ParamSet -> data.table::data.table()
Compact representation as datatable. Col types are:
id: character
lower, upper: double
levels: list col, with NULL elements
special_vals: list col of list
is_bounded: logical
default: list col, with NULL elements
storage_type: character
tags: list col of character vectors
params
(named list()
)
List of Param, named with their respective ID.
deps
(data.table::data.table()
)
Table has cols id
(character(1)
) and on
(character(1)
) and cond
(Condition).
Lists all (direct) dependency parents of a param, through parameter IDs.
Internally created by a call to add_dep
.
Settable, if you want to remove dependencies or perform other changes.
set_id
(character(1)
)
ID of this param set. Default ""
. Settable.
length
(integer(1)
)
Number of contained Params.
is_empty
(logical(1)
)
Is the ParamSet
empty?
class
(named character()
)
Classes of contained parameters, named with parameter IDs.
lower
(named double()
)
Lower bounds of parameters (NA
if parameter is not numeric).
Named with parameter IDs.
upper
(named double()
)
Upper bounds of parameters (NA
if parameter is not numeric).
Named with parameter IDs.
levels
(named list()
)
List of character vectors of allowed categorical values of contained parameters.
NULL
if the parameter is not categorical.
Named with parameter IDs.
nlevels
(named integer()
)
Number of categorical levels per parameter, Inf
for double parameters or unbounded integer parameters.
Named with param IDs.
is_bounded
(named logical()
)
Do all parameters have finite bounds?
Named with parameter IDs.
special_vals
(named list()
of list()
)
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.
tags
(named list()
of character()
)
Can be used to group and subset parameters.
Named with parameter IDs.
storage_type
(character()
)
Data types of parameters when stored in tables.
Named with parameter IDs.
is_number
(named logical()
)
Position is TRUE for ParamDbl and ParamInt.
Named with parameter IDs.
is_categ
(named logical()
)
Position is TRUE for ParamFct and ParamLgl.
Named with parameter IDs.
trafo
(function(x, param_set)
)
Transformation function. Settable.
User has to pass a function(x, param_set)
, of the form
(named list()
, ParamSet) -> named list()
.
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.
has_trafo
(logical(1)
)
Has the set a trafo
function?
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.
has_deps
(logical(1)
)
Has the set parameter dependencies?
new()
Creates a new instance of this R6 class.
ParamSet$new(params = named_list())
params
(list()
)
List of Param, named with their respective ID.
Parameters are cloned.
add()
Adds a single param or another set to this set, all params are cloned.
ParamSet$add(p)
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.
ParamSet$ids(class = NULL, is_bounded = NULL, tags = NULL)
class
(character()
).
is_bounded
(logical(1)
).
tags
(character()
).
character()
.
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.
ParamSet$get_values(class = NULL, is_bounded = NULL, tags = NULL)
class
(character()
).
is_bounded
(logical(1)
).
tags
(character()
).
Named list()
.
subset()
Changes the current set to the set of passed IDs.
ParamSet$subset(ids)
ids
(character()
).
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
.
ParamSet$check(xs)
xs
(named list()
).
If successful TRUE
, if not a string with the error message.
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
.
ParamSet$test(xs)
xs
(named list()
).
If successful TRUE
, if not FALSE
.
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
.
ParamSet$assert(xs, .var.name = vname(xs))
xs
(named list()
).
.var.name
(character(1)
)
Name of the checked object to print in error messages.
Defaults to the heuristic implemented in vname.
If successful xs
invisibly, if not an error message.
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 be set to NA
in xdt
.
ParamSet$check_dt(xdt)
xdt
If successful TRUE
, if not a string with the error message.
test_dt()
checkmate-like test-function (s. $check_dt()
).
ParamSet$test_dt(xdt)
xdt
If successful TRUE
, if not FALSE
.
assert_dt()
checkmate-like assert-function (s. $check_dt()
).
ParamSet$assert_dt(xdt, .var.name = vname(xdt))
xdt
.var.name
(character(1)
)
Name of the checked object to print in error messages.
Defaults to the heuristic implemented in vname.
If successful xs
invisibly, if not an error message.
add_dep()
Adds a dependency to this set, so that param id
now depends on param on
.
ParamSet$add_dep(id, on, cond)
id
(character(1)
).
on
(character(1)
).
cond
(Condition).
format()
Helper for print outputs.
ParamSet$format()
print()
Printer.
ParamSet$print( ..., hide_cols = c("nlevels", "is_bounded", "special_vals", "tags", "storage_type") )
...
(ignored).
hide_cols
(character()
)
Which fields should not be printed? Default is "nlevels"
,
"is_bounded"
, "special_vals"
, "tags"
, and "storage_type"
.
clone()
The objects of this class are cloneable with this method.
ParamSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
# NOT RUN {
ps = ParamSet$new(
params = list(
ParamDbl$new("d", lower = -5, upper = 5, default = 0),
ParamFct$new("f", levels = letters[1:3])
)
)
ps$trafo = function(x, param_set) {
x$d = 2^x$d
return(x)
}
ps$add(ParamInt$new("i", lower = 0L, upper = 16L))
ps$check(list(d = 2.1, f = "a", i = 3L))
# }
Run the code above in your browser using DataLab