Cost Functions

class staliro.cost_func.CostFunc

The transformation from a Sample to a cost value.

This class is parameterized by two type variables, C and E. C is the type of the cost returned by this class and the value attribute in Result return value. E is the type of the annotation data in the extra attribute of the return value.

abstractmethod evaluate(inputs)

Evaluate the given Sample into a cost value.

Parameters:
  • sample – The sample to evaluate

  • inputs (Inputs[SampleT])

Returns:

The cost value associated with the sample and any provided annotation data

Return type:

Result[C, E]

@staliro.costfunc(f: Callable[[Inputs[S]], Result[T, E]]) CostFunc[T, E, S]
@staliro.costfunc(f: Callable[[Inputs[S]], T]) CostFunc[T, None, S]

Transform a python function into a CostFunc.

If the provided function returns any value other than a Result, the value will be wrapped in a Result with the extra field set to None. This decorator can be called with or without parentheses.

Parameters:

f (Callable[[Inputs[S]], Result[T, E] | T]) – The function to transform

Returns:

A cost function implementation wrapping the provided function

Return type:

CostFunc[T, E | None, S]