econirl.make_utility
- econirl.make_utility(fn, n_params, param_names=None, param_bounds=None, param_init=None)[source]
Factory function to create a Utility from a callable.
This is a convenience function equivalent to constructing CallableUtility directly.
- Parameters:
fn (Callable[[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], ndarray[tuple[Any, ...], dtype[floating]]], _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]]) – Utility function with signature (state, action, params) -> utility.
n_params (int) – Number of parameters.
param_names (list[str] | None) – Names of parameters. If None, uses [“theta_0”, “theta_1”, …].
param_bounds (tuple[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]] | None) – Optional (lower, upper) bounds tuple.
param_init (_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None) – Optional initial parameter values.
- Returns:
CallableUtility wrapping the provided function.
- Return type:
CallableUtility
Example
>>> def my_utility(state, action, params): ... return -params[0] * state >>> >>> utility = make_utility(my_utility, n_params=1, param_names=["cost"])