culebra.solution.parameter_optimization.Species class

class Species(lower_bounds: Sequence[int | float], upper_bounds: Sequence[int | float], types: Sequence[Type[int] | Type[float]] | None = None, names: Sequence[str] | None = None)

Create a new species.

Parameters:
  • lower_bounds (Sequence of int or float values) – Lower bound for each parameter

  • upper_bounds (Sequence of int or float values) – Upper bound for each parameter

  • types (Sequence of type (int or float), optional) – Type of each parameter. All the parameters will be treated as float if omitted. Defaults to None

  • names (Sequence of str, optional) – Name of each parameter. Defaults to None

Raises:
  • TypeError – If any of the attributes is not a Sequence

  • ValueError – If the sequences have different lengths

  • ValueError – If the sequences are empty

  • ValueError – If the type of any bound does not match with its corresponding type in types

  • ValueError – If any lower bound is greater to or equal than its corresponding upper bound

  • ValueError – If any name is not an instance of str

  • ValueError – If there is any repeated name

Class methods

classmethod Species.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:

Properties

property Species.lower_bounds: Tuple[int | float, ...]

Get the lower bound for each parameter.

Type:

tuple of int or float values

property Species.upper_bounds: Tuple[int | float, ...]

Get the upper bound for each parameter.

Type:

tuple of int or float values

property Species.types: Tuple[Type[int] | Type[float], ...]

Get the type of each parameter.

Type:

tuple of int or float

property Species.names: Tuple[str, ...]

Get the name of each parameter.

Type:

tuple of str

property Species.num_params: int

Get the number of parameters to be optimized.

Type:

int

Methods

Species.save_pickle(filename: str) None

Pickle this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Species.is_member(sol: Solution) bool

Check if a solution meets the constraints imposed by the species.

Parameters:

sol (Solution) – The solution

Returns:

True if the solution belongs to the species. False otherwise

Return type:

bool