Optimizers

class staliro.optimizers.ObjFunc(*args, **kwargs)

Representation of a function that can be optimized by an optimizer.

An objective function evaluates samples generated by the optimizer and returns a scalar cost value for each sample. The objective function is capable of evaluating one or more samples at once.

eval_sample(sample)

Evaluate a single sample.

Parameters:

sample (Iterable[float] | ndarray[tuple[Any, ...], dtype[Any]]) – The sample to evaluate

Returns:

The cost of the sample

Return type:

R

eval_samples(samples)

Evaluate a batch of samples.

Parameters:

samples (Iterable[Iterable[float] | ndarray[tuple[Any, ...], dtype[Any]]]) – A sequence of samples to evaluate

Returns:

The cost of each sample in the same order they were given

Return type:

Sequence[R]

class staliro.optimizers.Optimizer.Params(seed, budget, input_bounds)

The parameters for an optimization attempt.

Attribute seed:

The value to use to seed a random number generator for reproducibility

Attribute budget:

The maximum number of samples to evaluate

Attribute input_bounds:

The search range to for each input variable

Parameters:
class staliro.optimizers.Optimizer

An optimizer selects samples to be evaluated by the cost function.

This class is parameterized by two type variables, C and R. C is the type of the cost value that the optimizer expects to receive from the cost function, and R represents the type that the optimizer will return at the end of an optimization attempt.

abstractmethod optimize(func, params)

Evaluate samples and use the result to select more samples until the budget is reached.

The optimize method is responsible for generating samples that will be evaluated by the cost function into cost values that can be used to inform the selection of subsequent samples. In order to receive cost values, implementations must call either the eval_sample or eval_samples methods on the func value.

Parameters:
  • func (ObjFunc[C]) – The cost function to use for evaluating samples

  • params (Params) – The optimization parameters

Returns:

The cost value

Return type:

R

Implementations

class staliro.optimizers.UniformRandom(min_cost=None, max_cost=None)

Optimizer that samples the input space uniformly.

This optimizer will exhaust the sample budget unless the min_cost argument is provided. If a minimum cost is indicated then the optimizer will terminate early if a cost is found below that value.

Parameters:
  • min_cost (CT | None) – The minimum cost that will cause the optimize to terminate

  • max_cost (CT | None)

class staliro.optimizers.DualAnnealing(min_cost=None)

Optimizer implementing generalized simulated annealing.

The simulated annealing implementation is provided by the SciPy library dual_annealing function with the no_local_search parameter set to True. This optimizer will exhaust the sample budget unless the min_cost argument is provided in the constructor. If min_cost is provided, then the optimizer will exit if a cost value is found that is less than the value.

Parameters:

min_cost (float | None) – The minimum cost to use as a termination condition