Skip to contents

Translates a ParamSet into a Python ConfigSpace.ConfigurationSpace via reticulate. This function performs strict validation to ensure the ParamSet can be represented in ConfigSpace:

  • Defaults are optional. If a parameter has no default, ConfigSpace will auto-assign one (e.g. midpoint for numeric parameters, first level for categoricals).

Supported parameter mappings:

  • p_dbl(): Float / UniformFloatHyperparameter

  • p_int(): Integer / UniformIntegerHyperparameter

  • p_lgl(): Categorical (TRUE/FALSE)

  • p_fct(): Categorical

Dependency conditions (CondEqual, CondAnyOf) are preserved. Multiple conditions on the same child are combined using ConfigSpace.AndConjunction.

The function auto-detects old ConfigSpace API (ConfigSpace < 0.6.0) vs. new ConfigSpace API (ConfigSpace >= 0.6.0).

Usage

paramset_to_configspace(param_set, name = NULL)

Arguments

param_set

ParamSet
The parameter set to convert. Numeric parameters must define both lower and upper bounds.

name

character(1)
Optional name for the resulting ConfigurationSpace.

Value

A Python ConfigSpace.ConfigurationSpace object representing the given parameter set.

Examples

if (FALSE) { # \dontrun{
  param_set = ps(
    lr        = p_dbl(lower = 1e-5, upper = 1,   default = 0.01, tags = "train"),
    ntree     = p_int(lower = 10,   upper = 500, default = 100,  tags = c("train","tuning")),
    bootstrap = p_lgl(default = TRUE, tags = "train"),
    criterion = p_fct(levels = c("gini", "entropy", "other"), default = "gini", tags = "train"),
    extras    = p_fct(tags = "predict", default = "alpha",
                      levels = c("alpha","beta","gamma","delta","kappa","nu")),
    depending = p_lgl(tags = "train", default = TRUE,
                      depends = quote(criterion == "entropy" && extras %in% c("alpha","beta")))
  )
  cs = paramset_to_configspace(param_set, name = "demo")
} # }