Choose a hyperparameter definition method
mainConfigSpace provides three ways to define hyperparameters, ranging from rapid prototyping to full library development customization:
- Inferred Hyperparameters: Define hyperparameters directly within the
ConfigurationSpaceconstructor using Python primitives (tuples or lists). Best for rapid prototyping or simple search spaces. - Simple Hyperparameters: Use convenience functions like
Integer(),Float(), andCategorical(). These are parameterized versions of the underlying types and are best for most use cases where you need to pass a search space to another library. - Direct Hyperparameters: Use the explicit hyperparameter classes (e.g.,
UniformIntegerHyperparameter). These offer the highest level of customization and are intended for library developers building on top of ConfigSpace.
Note: Integer, Float, and Categorical are convenience functions, not types. To perform isinstance checks, use the direct hyperparameter classes.
from ConfigSpace import ConfigurationSpace, Integer, Categorical, Float, UniformIntegerHyperparameter
# 1. Inferred (Prototyping)
cs_inferred = ConfigurationSpace({
"a": (0, 10), # Integer
"b": ["cat", "dog"], # Categorical
"c": (0.0, 1.0), # Float
})
# 2. Simple (Most use cases)
cs_simple = ConfigurationSpace({
"a": Integer("a", (0, 10), log=False),
"b": Categorical("b", ["cat", "dog"], ordered=True),
"c": Float("c", (1e-5, 1e2), log=True),
})
# 3. Direct (Library development)
cs_direct = ConfigurationSpace({
"a": UniformIntegerHyperparameter("a", lower=0, upper=10, log=False),
"b": CategoricalHyperparameter("b", choices=["cat", "dog"], default_value="dog"),
})