econirl.Utility

class econirl.Utility[source]

Bases: ABC

Abstract base class for utility functions.

A utility function maps (state, action, parameters) to a utility value. This is the core component that estimators optimize over.

Subclasses must implement: - n_params: Number of parameters - param_names: Names of parameters - __call__: Compute utility for given state, action, and parameters

Optional overrides: - param_bounds: Parameter bounds for optimization - param_init: Initial parameter values - matrix: Compute utility matrix (default uses __call__)

abstract property n_params: int

Number of utility parameters.

abstract property param_names: list[str]

Names of utility parameters in order.

property param_bounds: tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]

Lower and upper bounds for parameters.

Returns:

Tuple of (lower_bounds, upper_bounds), each of shape (n_params,). Default is (-inf, inf) for all parameters.

property param_init: ndarray[tuple[Any, ...], dtype[floating]]

Initial parameter values for optimization.

Returns:

Array of shape (n_params,) with initial values. Default is zeros.

matrix(n_states, params, n_actions=2)[source]

Compute utility matrix for all state-action pairs.

Parameters:
  • n_states (int) – Number of states (states are 0, 1, …, n_states-1).

  • params (ndarray[tuple[Any, ...], dtype[floating]]) – Parameter vector of shape (n_params,).

  • n_actions (int) – Number of actions (default 2 for binary choice).

Returns:

Utility matrix of shape (n_states, n_actions) where result[s, a] = u(s, a; params).

Return type:

ndarray[tuple[Any, …], dtype[floating]]