Learn R Programming

paradox (version 0.3.0)

ParamSet: ParamSet

Description

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

Arguments

S3 methods and type converters

  • 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

Active bindings

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?

Methods

Public methods

Method new()

Creates a new instance of this R6 class.

Usage

ParamSet$new(params = named_list())

Arguments

params

(list()) List of Param, named with their respective ID. Parameters are cloned.

Method add()

Adds a single param or another set to this set, all params are cloned.

Usage

ParamSet$add(p)

Arguments

p

(Param | ParamSet).

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, is_bounded = NULL, tags = NULL)

Arguments

class

(character()).

is_bounded

(logical(1)).

tags

(character()).

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, is_bounded = NULL, tags = NULL)

Arguments

class

(character()).

is_bounded

(logical(1)).

tags

(character()).

Returns

Named list().

Method subset()

Changes the current set to the set of passed IDs.

Usage

ParamSet$subset(ids)

Arguments

ids

(character()).

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.

Usage

ParamSet$check(xs)

Arguments

xs

(named list()).

Returns

If successful TRUE, if not a string with the 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.

Usage

ParamSet$test(xs)

Arguments

xs

(named list()).

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.

Usage

ParamSet$assert(xs, .var.name = vname(xs))

Arguments

xs

(named list()).

.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 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 be set to NA in xdt.

Usage

ParamSet$check_dt(xdt)

Arguments

xdt

(data.table::data.table).

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)

Arguments

xdt

(data.table::data.table).

Returns

If successful TRUE, if not FALSE.

Method assert_dt()

checkmate-like assert-function (s. $check_dt()).

Usage

ParamSet$assert_dt(xdt, .var.name = vname(xdt))

Arguments

xdt

(data.table::data.table).

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

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)

Arguments

id

(character(1)).

on

(character(1)).

cond

(Condition).

Method format()

Helper for print outputs.

Usage

ParamSet$format()

Method print()

Printer.

Usage

ParamSet$print(
  ...,
  hide_cols = c("nlevels", "is_bounded", "special_vals", "tags", "storage_type")
)

Arguments

...

(ignored).

hide_cols

(character()) Which fields should not be printed? Default is "nlevels", "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

Run this code
# 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