Configuration Spaces

Configuration spaces define the hyperparameter search space for optimization. FCVOpt uses a thin wrapper around ConfigSpace library.

Basic Usage

from fcvopt.configspace import ConfigurationSpace
from ConfigSpace import Float, Integer

# Manual configuration space definition
config_space = ConfigurationSpace()
config.add([
   Integer('n_estimators', bounds=(50, 1000), log=True),
   Integer('max_depth', bounds=(1, 15), log=True),
   Float('max_features', bounds=(0.01, 1.0), log=True),
   Integer('min_samples_split', bounds=(2, 200), log=True)
])

API Reference

class fcvopt.configspace.ConfigurationSpace(name=None, seed=None, meta=None, *, space=None)[source]

Extended ConfigurationSpace for FCVOpt optimizers.

This is a wrapper around ConfigSpace.ConfigurationSpace that provides additional utilities for hyperparameter optimization in FCVOpt:

  • Reconstructing a ConfigSpace.Configuration from a numeric array via get_conf_from_array().

  • Generating Latin Hypercube samples of configurations

Example

from fcvopt.configspace import ConfigurationSpace
from ConfigSpace import Float, Integer

config = ConfigurationSpace(seed=1234)
config.add([ # add two hyperparameters
    Float('x1', lower=0.0, upper=1.0),
    Integer('x2', lower=1, upper=10),
])

# generate a random latin hypercube sample of size 5
samples_list = config.latinhypercube_sample(size=5)

# convert the list of configurations to a numpy array with scaled values
samples_array = np.array([conf.get_array() for conf in samples_list])

# convert a numeric array back to a Configuration object
conf = config.get_conf_from_array(samples_array[0])
classmethod from_serialized_dict(serialized_dict)[source]

Reconstruct a ConfigurationSpace from a serialized dictionary.

Parameters:

serialized_dict (dict) – Dictionary containing serialized configuration space.

Returns:

Reconstructed configuration space.

Return type:

ConfigurationSpace

generate_indices()[source]

deprecated since 0.4.0

Return type:

None

get_conf_from_array(x)[source]

Convert a numeric array into a Configuration object.

Parameters:

x (np.ndarray) – 1D array of length ndim containing numeric values. For categorical hyperparameters, the array value is rounded to the nearest integer index of the category.

Returns:

A configuration mapping hyperparameter names to values.

Return type:

CS.Configuration

latinhypercube_sample(size)[source]

Generate a Latin hypercube sample over the numerical inputs.

Note

Binary values categorical inputs are supported while general categorical inputs are not.

Parameters:

size (int) – Number of configurations to sample.

Returns:

List of sampled configurations of length size.

Return type:

List[CS.Configuration]

Raises:

ValueError – If the configuration space contains categorical parameters.