Skip to content

Params

IntParam

Bases: BaseParam

A class representing an integer parameter.

bounds property

Calculate and return the parameter's internal bounds for the optimization.

The bounds will be used as constraints for the internal representation (or actions) of the optimization algorithm about the parameter's value.

Returns:

Type Description
list[tuple[int, int]]

A list of tuples representing the bounds.

__init__(low, high, size=1)

Creates an IntParam that will suggest integer values during the optimization.

The parameter can be either an integer, or a list of integers, depending on the specified size. The values sampled by the optimization will be limited to the specified granularity, lower and upper bounds.

Parameters:

Name Type Description Default
low int

The lower bound of the suggested values.

required
high int

The upper bound of the suggested values.

required
size int

The size if the parameter shall be a list of integers. Default is 1.

1

Returns:

Name Type Description
IntParam None

An instance of the parameter with the specified properties.

Raises:

Type Description
ValueError

If low is not an integer, if high is not an integer that is greater than

Example:

param = IntParam(low=1, high=10, size=3) print(param) IntParam(low=1, high=10, size=3)

decode(actions)

Decode an action by the optimization problem to the value of the parameter.

Parameters:

Name Type Description Default
actions list[int]

A list of integers to map.

required

Returns:

Type Description
int | list[int]

The resulting integer value(s).

FloatParam

Bases: BaseParam

A class representing a float parameter.

bounds property

Calculate and return the parameter's internal bounds for the optimization.

The bounds will be used as constraints for the internal representation (or actions) of the optimization algorithm about the parameter's value

Returns:

Type Description
list[tuple[int, int]]

A list of tuples representing the bounds

__init__(low, high, size=1, n_steps=100, log=False)

Creates a FloatParam that will suggest float values during the optimization.

The parameter can either be a float, or a list of floats, depending on the specified size. The values sampled by the optimization will be limited to the specified granularity, lower and upper bounds.

Parameters:

Name Type Description Default
low float

The lower bound of the suggested values.

required
high float

The upper bound of the suggested values.

required
size int

The size if the parameter shall be a list of floats. Default is 1.

1
n_steps float

The number of steps between low and high. Default is 100.

100
log bool

A flag to indicate log-transformation. Default is False.

False

Returns:

Name Type Description
FloatParam None

An instance of the parameter with the specified properties.

Raises:

Type Description
ValueError

If low is not an float, if high is not an float that is greater than

Example:

param = FloatParam(low=1.0, high=10.0, size=3, n_steps=100) print(param) FloatParam(low=1.0, high=10.0, size=3, n_steps=100)

decode(actions)

Decodes an action by the optimization problem to the value of the parameter.

Returns:

Type Description
float | list[float]

The resulting float value(s).

CategoricalParam

Bases: BaseParam

A class representing a categorical parameter.

bounds property

Calculates and returns the parameter's internal bounds for optimization.

The bounds are used as constraints for the internal representation (or actions) of the optimization algorithm regarding the parameter's value.

Returns:

Type Description
list[tuple[int, int]]

A list of (lower_bound, upper_bound) tuples representing the bounds.

__init__(choices)

Creates a CategoricalParam that will suggest one of the choices during optimization.

Parameters:

Name Type Description Default
choices list[ChoiceType]

A list of possible choices for the parameter.

required

Raises:

Type Description
ValueError

Raises a ValueError if choices is not a list, or if the objects in the list

Example:

param = CategoricalParam(choices=["a", "b", "c"]) print(param) CategoricalParam(["a", "b", "c"])

Note

This parameter assumes an ordinal scale for the choices during optimization.

decode(actions)

Decodes an action from the optimization problem to the value of the parameter.

Parameters:

Name Type Description Default
actions list[int]

A list of integers to map.

required

Returns:

Type Description
ChoiceType | list[ChoiceType]

The resulting choice(s).

BaseParam

Bases: ABC

An abstract base class representing a parameter in an optimization problem.

This class defines the interface for parameters that suggest values during optimization. Subclasses must implement the bounds property and the map_to_value method to define how the parameter's bounds are calculated and how actions are mapped to parameter values for the objective function. The size attribute determines the dimensionality of the parameter.

bounds abstractmethod property

Abstract property to calculate and return the parameter's internal bounds.

The bounds are used as constraints for the optimization algorithm's internal representation of the parameter's value. Subclasses must implement this property to provide the specific bounds for the parameter, taking into account the size.

Returns:

Type Description
list[tuple[int, int]]

A list of tuples representing the bounds, where each tuple

list[tuple[int, int]]

contains the lower and upper bounds for a dimension. The length of the

list[tuple[int, int]]

list should match the size.

__init__(size=1)

Initializes a BaseParam instance.

Raises:

Type Description
ValueError

If size is not a positive integer.

decode(actions) abstractmethod

Abstract method to decode optimization actions as parameter values.

This method converts a list of integers (actions) into the corresponding parameter value(s). Subclasses must implement this method to define the specific mapping logic, considering the size.

Parameters:

Name Type Description Default
actions list[int]

A list of integers representing actions from the

required

Returns:

Type Description
bool | int | str | float | Callable | None | list

The resulting parameter value(s) corresponding to the given actions.

bool | int | str | float | Callable | None | list

Returns the value directly in case of self.size equals 1, a list of values else.