Hyperparameters

ConfigSpace contains Float(), Integer() and Categorical() hyperparamters, each with their own customizability.

For Float() and Integer(), you will find their interface much the same, being able to take the same distributions and parameters.

A Categorical() can optionally take weights to define your own custom distribution over the discrete un-ordered choices. One can also pass ordered=True to make it an OrdinalHyperparameter.

These are all convenience functions that construct the more complex hyperparameter classes, e.g. UniformIntegerHyperparameter, which are the underlying complex types which make up the backbone of what’s possible. You may still use these complex classes without any functional difference.

Note

The Simple types, Integer, Float and Categorical are just simple functions that construct the more complex underlying types.

Example usages are shown below each.

Simple Types

Float

ConfigSpace.api.types.float.Float(name: str, bounds: tuple[float, float] | None = None, *, distribution: Uniform | None = None, default: float | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) UniformFloatHyperparameter[source]
ConfigSpace.api.types.float.Float(name: str, bounds: tuple[float, float] | None = None, *, distribution: Normal, default: float | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) NormalFloatHyperparameter
ConfigSpace.api.types.float.Float(name: str, bounds: tuple[float, float] | None = None, *, distribution: Beta, default: float | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) BetaFloatHyperparameter

Create a FloatHyperparameter.

# Uniformly distributed
Float("a", (1, 10))
Float("a", (1, 10), distribution=Uniform())

# Normally distributed at 2 with std 3
Float("b", distribution=Normal(2, 3))
Float("b", (0, 5), distribution=Normal(2, 3))  # ... bounded

# Beta distributed with alpha 1 and beta 2
Float("c", distribution=Beta(1, 2))
Float("c", (0, 3), distribution=Beta(1, 2))  # ... bounded

# Give it a default value
Float("a", (1, 10), default=4.3)

# Sample on a log scale
Float("a", (1, 100), log=True)

# Quantized into three brackets
Float("a", (1, 10), q=3)

# Add meta info to the param
Float("a", (1.0, 10), meta={"use": "For counting chickens"})

Note

Float is actually a function, please use the corresponding return types if doing an isinstance(param, type) check and not Float.

Parameters:
  • name (str) – The name to give to this hyperparameter

  • bounds (tuple[float, float] | None = None) – The bounds to give to the float. Note that by default, this is required for Uniform distribution, which is the default distribution

  • distribution (Uniform | Normal | Beta, = Uniform) – The distribution to use for the hyperparameter. See above

  • default (float | None = None) – The default value to give to the hyperparameter.

  • q (float | None = None) –

    The quantization factor, must evenly divide the boundaries.

    Note

    Quantization points act are not equal and require experimentation to be certain about

  • log (bool = False) – Whether to this parameter lives on a log scale

  • meta (dict | None = None) – Any meta information you want to associate with this parameter

Returns:

Returns the corresponding hyperparameter type

Return type:

UniformFloatHyperparameter | NormalFloatHyperparameter | BetaFloatHyperparameter

Integer

ConfigSpace.api.types.integer.Integer(name: str, bounds: tuple[int, int] | None = None, *, distribution: Uniform | None = None, default: int | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) UniformIntegerHyperparameter[source]
ConfigSpace.api.types.integer.Integer(name: str, bounds: tuple[int, int] | None = None, *, distribution: Normal, default: int | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) NormalIntegerHyperparameter
ConfigSpace.api.types.integer.Integer(name: str, bounds: tuple[int, int] | None = None, *, distribution: Beta, default: int | None = None, q: int | None = None, log: bool = False, meta: dict | None = None) BetaIntegerHyperparameter

Create an IntegerHyperparameter.

# Uniformly distributed
Integer("a", (1, 10))
Integer("a", (1, 10), distribution=Uniform())

# Normally distributed at 2 with std 3
Integer("b", distribution=Normal(2, 3))
Integer("b", (0, 5), distribution=Normal(2, 3))  # ... bounded

# Beta distributed with alpha 1 and beta 2
Integer("c", distribution=Beta(1, 2))
Integer("c", (0, 3), distribution=Beta(1, 2))  # ... bounded

# Give it a default value
Integer("a", (1, 10), default=4)

# Sample on a log scale
Integer("a", (1, 100), log=True)

# Quantized into three brackets
Integer("a", (1, 10), q=3)

# Add meta info to the param
Integer("a", (1, 10), meta={"use": "For counting chickens"})

Note

Integer is actually a function, please use the corresponding return types if doing an isinstance(param, type) check and not Integer.

Parameters:
  • name (str) – The name to give to this hyperparameter

  • bounds (tuple[int, int] | None = None) – The bounds to give to the integer. Note that by default, this is required for Uniform distribution, which is the default distribution

  • distribution (Uniform | Normal | Beta, = Uniform) – The distribution to use for the hyperparameter. See above

  • default (int | None = None) – The default value to give to the hyperparameter.

  • q (int | None = None) –

    The quantization factor, must evenly divide the boundaries. Sampled values will be

        full range
    1    4    7    10
    |--------------|
    |    |    |    |  q = 3
    

    All samples here will then be in {1, 4, 7, 10}

    Note

    Quantization points act are not equal and require experimentation to be certain about

  • log (bool = False) – Whether to this parameter lives on a log scale

  • meta (dict | None = None) – Any meta information you want to associate with this parameter

Returns:

Returns the corresponding hyperparameter type

Return type:

UniformIntegerHyperparameter | NormalIntegerHyperparameter | BetaIntegerHyperparameter

Categorical

ConfigSpace.api.types.categorical.Categorical(name: str, items: Sequence[str | int | float], *, default: T | None = None, weights: Sequence[float] | None = None, ordered: typing_extensions.Literal[False], meta: dict | None = None) CategoricalHyperparameter[source]
ConfigSpace.api.types.categorical.Categorical(name: str, items: Sequence[str | int | float], *, default: T | None = None, weights: Sequence[float] | None = None, ordered: typing_extensions.Literal[True], meta: dict | None = None) OrdinalHyperparameter
ConfigSpace.api.types.categorical.Categorical(name: str, items: Sequence[str | int | float], *, default: T | None = None, weights: Sequence[float] | None = None, ordered: bool = False, meta: dict | None = None) CategoricalHyperparameter | OrdinalHyperparameter

Creates a Categorical Hyperparameter.

CategoricalHyperparameter’s can be used to represent a discrete choice. Optionally, you can specify that these values are also ordered in some manner, e.g. ["small", "medium", "large"].

# A simple categorical hyperparameter
c = Categorical("animals", ["cat", "dog", "mouse"])

# With a default
c = Categorical("animals", ["cat", "dog", "mouse"], default="mouse")

# Make them weighted
c = Categorical("animals", ["cat", "dog", "mouse"], weights=[0.1, 0.8, 3.14])

# Specify it's an OrdinalHyperparameter (ordered categories)
# ... note that you can't apply weights to an Ordinal
o = Categorical("size", ["small", "medium", "large"], ordered=True)

# Add some meta information for your own tracking
c = Categorical("animals", ["cat", "dog", "mouse"], meta={"use": "Favourite Animal"})

Note

Categorical is actually a function, please use the corresponding return types if doing an isinstance(param, type) check with either CategoricalHyperparameter and/or OrdinalHyperparameter.

Parameters:
  • name (str) – The name of the hyperparameter

  • items (Sequence[T],) –

    A list of items to put in the category. Note that there are limitations:

    • Can’t use None, use a string “None” instead and convert as required.

    • Can’t have duplicate categories, use weights if required.

  • default (T | None = None) – The default value of the categorical hyperparameter

  • weights (Sequence[float] | None = None) – The weights to apply to each categorical. Each item will be sampled according to these weights.

  • ordered (bool = False) – Whether the categorical is ordered or not. If True, this will return an OrdinalHyperparameter, otherwise it remain a CategoricalHyperparameter.

  • meta (dict | None = None) – Any additional meta information you would like to store along with the hyperparamter.

Distributions

These can be used as part of the distribution parameter for the basic Integer() and Float() functions.

class ConfigSpace.api.distributions.Beta(alpha, beta)[source]

Represents a beta distribution.

Parameters:
  • alpha (float) – The alpha parameter of a beta distribution

  • beta (float) – The beta parameter of a beta distribution

class ConfigSpace.api.distributions.Normal(mu, sigma)[source]

Represents a normal distribution.

Parameters:
  • mu (float) – The mean of the distribution

  • sigma (float) – The standard deviation of the float

class ConfigSpace.api.distributions.Uniform[source]

A uniform distribution.

Advanced Types

The full hyperparameters are exposed through the following API points.

Integer hyperparameters

These can all be constructed with the simple Integer() function and passing the corresponding distribution.

class ConfigSpace.hyperparameters.UniformIntegerHyperparameter

A uniformly distributed integer hyperparameter.

Its values are sampled from a uniform distribution with bounds lower and upper.

>>> from ConfigSpace import UniformIntegerHyperparameter
>>>
>>> UniformIntegerHyperparameter(name='u', lower=10, upper=100, log=False)
u, Type: UniformInteger, Range: [10, 100], Default: 55
Parameters:
  • name (str) – Name of the hyperparameter with which it can be accessed

  • lower (int) – Lower bound of a range of values from which the hyperparameter will be sampled

  • upper (int) – upper bound

  • default_value (int, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Defaults to False

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

Return type:

float

get_neighbors(value, rs, number=4, transform=False, std=0.2)

Get the neighbors of a value

Note

This assumes the value is in the unit-hypercube [0, 1]

Parameters:
  • value (float) – The value to get neighbors around. This assume the value has been converted to the [0, 1] range which can be done with _inverse_transform.

  • rs (RandomState) – The random state to use

  • number (int = 4) – How many neighbors to get

  • transform (bool = False) – Whether to transform this value from the unit cube, back to the hyperparameter’s specified range of values.

  • std (float = 0.2) – The std. dev. to use in the [0, 1] hypercube space while sampling for neighbors.

Returns:

Some number of neighbors centered around value.

Return type:

List[int]

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the hyperparameter in the hyperparameter space (the one specified by the user). For each hyperparameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) hyperparameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

class ConfigSpace.hyperparameters.NormalIntegerHyperparameter

A normally distributed integer hyperparameter.

Its values are sampled from a normal distribution \(\mathcal{N}(\mu, \sigma^2)\).

>>> from ConfigSpace import NormalIntegerHyperparameter
>>>
>>> NormalIntegerHyperparameter(name='n', mu=0, sigma=1, log=False)
n, Type: NormalInteger, Mu: 0 Sigma: 1, Default: 0
Parameters:
  • name (str) – Name of the hyperparameter with which it can be accessed

  • mu (int) – Mean of the distribution, from which hyperparameter is sampled

  • sigma (int, float) – Standard deviation of the distribution, from which hyperparameter is sampled

  • default_value (int, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Defaults to False

  • lower (int, float, optional) – Lower bound of a range of values from which the hyperparameter will be sampled

  • upper (int, float, optional) – Upper bound of a range of values from which the hyperparameter will be sampled

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the hyperparameter in the hyperparameter space (the one specified by the user). For each hyperparameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) hyperparameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

class ConfigSpace.hyperparameters.BetaIntegerHyperparameter

A beta distributed integer hyperparameter. The ‘lower’ and ‘upper’ parameters move the distribution from the [0, 1]-range and scale it appropriately, but the shape of the distribution is preserved as if it were in [0, 1]-range.

Its values are sampled from a beta distribution \(Beta(\alpha, \beta)\).

>>> from ConfigSpace import BetaIntegerHyperparameter
>>>
>>> BetaIntegerHyperparameter('b', alpha=3, beta=2, lower=1, upper=4, log=False)
b, Type: BetaInteger, Alpha: 3.0 Beta: 2.0, Range: [1, 4], Default: 3
Parameters:
  • name (str) – Name of the hyperparameter with which it can be accessed

  • alpha (int, float) – Alpha parameter of the distribution, from which hyperparameter is sampled

  • beta (int, float) – Beta parameter of the distribution, from which hyperparameter is sampled

  • lower (int, float) – Lower bound of a range of values from which the hyperparameter will be sampled

  • upper (int, float) – Upper bound of a range of values from which the hyperparameter will be sampled

  • default_value (int, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Defaults to False

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

get_neighbors(value, rs, number=4, transform=False, std=0.2)

Get the neighbors of a value

Note

This assumes the value is in the unit-hypercube [0, 1]

Parameters:
  • value (float) – The value to get neighbors around. This assume the value has been converted to the [0, 1] range which can be done with _inverse_transform.

  • rs (RandomState) – The random state to use

  • number (int = 4) – How many neighbors to get

  • transform (bool = False) – Whether to transform this value from the unit cube, back to the hyperparameter’s specified range of values.

  • std (float = 0.2) – The std. dev. to use in the [0, 1] hypercube space while sampling for neighbors.

Returns:

Some number of neighbors centered around value.

Return type:

List[int]

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the hyperparameter in the hyperparameter space (the one specified by the user). For each hyperparameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) hyperparameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

Float hyperparameters

These can all be constructed with the simple float() function and passing the corresponding distribution.

class ConfigSpace.hyperparameters.UniformFloatHyperparameter

A uniformly distributed float hyperparameter.

Its values are sampled from a uniform distribution with values from lower to upper.

>>> from ConfigSpace import UniformFloatHyperparameter
>>>
>>> UniformFloatHyperparameter('u', lower=10, upper=100, log = False)
u, Type: UniformFloat, Range: [10.0, 100.0], Default: 55.0
Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed

  • lower (int, float) – Lower bound of a range of values from which the hyperparameter will be sampled

  • upper (int, float) – Upper bound

  • default_value (int, float, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, float, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Default to False

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

Return type:

float

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the parameter in the original parameter space (the one specified by the user). For each parameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) parameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

class ConfigSpace.hyperparameters.NormalFloatHyperparameter

A normally distributed float hyperparameter.

Its values are sampled from a normal distribution \(\mathcal{N}(\mu, \sigma^2)\).

>>> from ConfigSpace import NormalFloatHyperparameter
>>>
>>> NormalFloatHyperparameter('n', mu=0, sigma=1, log=False)
n, Type: NormalFloat, Mu: 0.0 Sigma: 1.0, Default: 0.0
Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed

  • mu (int, float) – Mean of the distribution

  • sigma (int, float) – Standard deviation of the distribution

  • default_value (int, float, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, float, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Default to False

  • lower (int, float, optional) – Lower bound of a range of values from which the hyperparameter will be sampled

  • upper (int, float, optional) – Upper bound of a range of values from which the hyperparameter will be sampled

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

Return type:

float

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the parameter in the original parameter space (the one specified by the user). For each parameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) parameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

class ConfigSpace.hyperparameters.BetaFloatHyperparameter

A beta distributed float hyperparameter. The ‘lower’ and ‘upper’ parameters move the distribution from the [0, 1]-range and scale it appropriately, but the shape of the distribution is preserved as if it were in [0, 1]-range.

Its values are sampled from a beta distribution \(Beta(\alpha, \beta)\).

>>> from ConfigSpace import BetaFloatHyperparameter
>>>
>>> BetaFloatHyperparameter('b', alpha=3, beta=2, lower=1, upper=4, log=False)
b, Type: BetaFloat, Alpha: 3.0 Beta: 2.0, Range: [1.0, 4.0], Default: 3.0
Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed

  • alpha (int, float) – Alpha parameter of the normalized beta distribution

  • beta (int, float) – Beta parameter of the normalized beta distribution

  • lower (int, float) – Lower bound of a range of values from which the hyperparameter will be sampled. The Beta disribution gets scaled by the total range of the hyperparameter.

  • upper (int, float) – Upper bound of a range of values from which the hyperparameter will be sampled. The Beta disribution gets scaled by the total range of the hyperparameter.

  • default_value (int, float, optional) – Sets the default value of a hyperparameter to a given value

  • q (int, float, optional) – Quantization factor

  • log (bool, optional) – If True, the values of the hyperparameter will be sampled on a logarithmic scale. Default to False

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

get_max_density()

Returns the maximal density on the pdf for the parameter (so not the mode, but the value of the pdf on the mode).

Return type:

float

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the parameter in the original parameter space (the one specified by the user). For each parameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) parameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

Categorical Hyperparameter

This can be constructed with the simple form categorical() and setting ordered=False which is the default.

class ConfigSpace.hyperparameters.CategoricalHyperparameter

A categorical hyperparameter.

Its values are sampled from a set of values.

None is a forbidden value, please use a string constant instead and parse it in your own code, see here <https://github.com/automl/ConfigSpace/issues/159>_ for further details.

>>> from ConfigSpace import CategoricalHyperparameter
>>>
>>> CategoricalHyperparameter('c', choices=['red', 'green', 'blue'])
c, Type: Categorical, Choices: {red, green, blue}, Default: red
Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed

  • choices (list or tuple with str, float, int) – Collection of values to sample hyperparameter from

  • default_value (int, float, str, optional) – Sets the default value of the hyperparameter to a given value

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

  • weights (Sequence[int | float] | None = None) – List of weights for the choices to be used (after normalization) as probabilities during sampling, no negative values allowed

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the parameter in the original parameter space (the one specified by the user). For each parameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) parameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

to_uniform()

Creates a categorical parameter with equal weights for all choices This is used for the uniform configspace when sampling configurations in the local search in PiBO: https://openreview.net/forum?id=MMAeCXIa89

Returns:

An identical parameter as the original, except that all weights are uniform.

Return type:

CategoricalHyperparameter

Ordinal Hyperparameter

This can be constructed with the simple form categorical() and setting ordered=True.

class ConfigSpace.hyperparameters.OrdinalHyperparameter

An ordinal hyperparameter.

Its values are sampled form a sequence of values. The sequence of values from a ordinal hyperparameter is ordered.

None is a forbidden value, please use a string constant instead and parse it in your own code, see here for further details.

>>> from ConfigSpace import OrdinalHyperparameter
>>>
>>> OrdinalHyperparameter('o', sequence=['10', '20', '30'])
o, Type: Ordinal, Sequence: {10, 20, 30}, Default: 10
Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed.

  • sequence (list or tuple with (str, float, int)) – ordered collection of values to sample hyperparameter from.

  • default_value (int, float, str, optional) – Sets the default value of a hyperparameter to a given value.

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

check_default(default_value)

check if given default value is represented in the sequence. If there’s no default value we simply choose the first element in our sequence as default.

Parameters:

default_value (int | float | str | None) –

Return type:

int | float | str

check_order(val1, val2)

check whether value1 is smaller than value2.

Parameters:
  • val1 (int | str | float) –

  • val2 (int | str | float) –

Return type:

bool

get_neighbors(value, rs, number=0, transform=False)

Return the neighbors of a given value. Value must be in vector form. Ordinal name will not work.

Parameters:
  • value (int | str | float) –

  • rs (None) –

  • number (int) –

  • transform (bool) –

Return type:

List[str | float | int]

get_num_neighbors(value)

return the number of existing neighbors in the sequence

Parameters:

value (int | float | str) –

Return type:

int

get_order(value)

return the seuence position/order of a certain value from the sequence

Parameters:

value (int | float | str | None) –

Return type:

int

get_seq_order()

return the ordinal sequence as numeric sequence (according to the the ordering) from 1 to length of our sequence.

Return type:

ndarray

get_value(idx)

return the sequence value of a given order/position

Parameters:

idx (int) –

Return type:

int | str | float

has_neighbors()

check if there are neighbors or we’re only dealing with an one-element sequence

Return type:

bool

check if a certain value is represented in the sequence

Parameters:

value (int | float | str) –

Return type:

bool

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the hyperparameter in the original hyperparameter space (the one specified by the user). For each parameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) hyperparameter space. Only legal values return a positive probability density, otherwise zero. The OrdinalHyperparameter is treated as a UniformHyperparameter with regard to its probability density.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]

Constant

class ConfigSpace.hyperparameters.Constant

Representing a constant hyperparameter in the configuration space.

By sampling from the configuration space each time only a single, constant value will be drawn from this hyperparameter.

Parameters:
  • name (str) – Name of the hyperparameter, with which it can be accessed

  • value (str, int, float) – value to sample hyperparameter from

  • meta (Dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

Check whether the given value is a legal value for the vector representation of this hyperparameter.

Parameters:

value – the vector value to check

Returns:

True if the given value is a legal vector value, otherwise False

Return type:

bool

pdf(vector)

Computes the probability density function of the parameter in the original parameter space (the one specified by the user). For each hyperparameter type, there is also a method _pdf which operates on the transformed (and possibly normalized) parameter space. Only legal values return a positive probability density, otherwise zero.

Parameters:

vector (np.ndarray) – the (N, ) vector of inputs for which the probability density function is to be computed.

Returns:

Probability density values of the input vector

Return type:

np.ndarray(N, )

rvs(size=None, random_state=None)

scipy compatibility wrapper for _sample, allowing the hyperparameter to be used in sklearn API hyperparameter searchers, eg. GridSearchCV.

Parameters:
  • size (Optional[int]) –

  • random_state (Optional[Union[int, np.random, np.random.RandomState]]) –

Return type:

Union[float, np.ndarray]