ps_union: Create a ParamSet from a list of ParamSets

View source: R/ps_union.R

ps_unionR Documentation

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 Domains from the input sets, but some ⁠$id⁠s are changed: If the ParamSet is given in sets with a name, then the Domains will have their ⁠<id>⁠ changed to ⁠<name in "sets">.<id>⁠. This is also reflected in deps.

The c() operator, applied to ParamSets, is a synony for ps_union().

Usage

ps_union(sets, tag_sets = FALSE, tag_params = FALSE)

Arguments

sets

(list of ParamSet)
This may be a named list, in which case non-empty names are prefixed to parameters in the corresponding ParamSet.

tag_sets

(logical(1))
Whether to add tags of the form "set_<set_id>" to each parameter originating from a given ParamSet given with name ⁠<name in "sets">⁠.

tag_params

(logical(1))
Whether to add tags of the form "param_<param_id>" to each parameter with original ID ⁠<param_id>⁠.

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


mlr-org/phng documentation built on April 22, 2024, 4:34 p.m.