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(sample)

Evaluate the given Sample into a cost value.

Parameters:

sample (Sample) – The sample to evaluate

Returns:

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

Return type:

Result[C, E]

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

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[[Sample], Result[T, E] | T]) – The function to transform

Returns:

A cost function implementation wrapping the provided function

Return type:

CostFunc[T, E | None]