choicedesign.criteria

Optimality criteria for discrete choice experimental designs.

Provides:

  • MNLModel — a pre-compiled MNL model used inside the optimisation loop.

  • _derr — D-error (D-efficient design criterion).

  • _db_derr — Db-error (Bayesian D-efficient, averaged over prior draws).

  • _aerr — A-error (average parameter variance).

  • _cerr — C-error (WTP variance via delta method).

  • _utility_balance — utility balance ratio.

Classes

MNLModel(V[, params])

Pre-compiled MNL model for efficient repeated evaluation.

class choicedesign.criteria.MNLModel(V: dict, params: List[Parameter] = None)

Pre-compiled MNL model for efficient repeated evaluation.

Symbolic differentiation of the utility functions with respect to each parameter is performed once at construction time. All subsequent calls (information matrix, probabilities, D-error) are pure NumPy operations, making this suitable for the inner loop of the swapping algorithm.

Parameters:
  • V (dict[int, Expression]) – Utility functions, e.g. {1: V1, 2: V2}.

  • params (list[Parameter], optional) – Ordered list of parameters. If None, extracted automatically from V via get_unique_params().

information_matrix(data: DataFrame) ndarray

Compute the MNL Fisher information matrix.

The information matrix is:

\[I_{kl} = \sum_n \left[ \sum_j P_{nj}\, x_{njk}\, x_{njl} - \left(\sum_j P_{nj}\, x_{njk}\right) \left(\sum_j P_{nj}\, x_{njl}\right) \right]\]

where \(x_{njk} = \partial V_j / \partial \beta_k\) at design row n.

Parameters:

data (pd.DataFrame) – Design matrix (rows = choice situations).

Return type:

np.ndarray, shape (K, K)

probabilities(data: DataFrame) ndarray

Return MNL choice probabilities.

Return type:

np.ndarray, shape (ncs, J)