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(). The named arguments tag_sets, tag_params, and postfix_names are also available in the c() operator, but need to be used with a preceding dot instead: .tag_sets, .tag_params, and .postfix_names.

Usage

ps_union(sets, tag_sets = FALSE, tag_params = FALSE, postfix_names = 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>⁠.

postfix_names

(logical(1))
Whether to use names in sets as postfixes, instead of prefixes. Default FALSE.

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

pu3 = c(one = ps1, two = ps1, ps2, .postfix_names = TRUE)
pu3



mlr-org/paradox documentation built on Feb. 1, 2025, 9:42 p.m.