larch.model.troubleshooting.chosen_but_zero_quantity#
- chosen_but_zero_quantity(model: NumbaModel, repair: Literal['?', '-', '!'] | None = None, verbose: int = 3)[source]#
Check if some observations are chosen but have zero quantity.
Alternatives that have zero quantity have utility values that end up as negative infinity, regardless of whether the alternative would otherwise be available. Due to the mathematical structure of how quantities are used in Larch, this situation is generally a result of a data problem, and not due to the current values of model parameters.
If even one observation is chosen but has zero quantity, the model log-likelihood will nominally be negative infinity regardless of the values of any other parameters. Note that some compute engines (e.g. JAX) may not actually return negative infinity log likelihoods due to clipping of extreme values.
- Parameters:
model (BaseModel) – The model to check.
repair ({'?', '-', '!'}) – How to repair the data. The minus (‘-’) will make alternatives with zero quantity not chosen (possibly leaving no chosen alternative). A question mark (‘?’) effects no repair, and simply emits a warning. An exclamation mark (‘!’) will raise an error if there are any conflicts.
verbose (int, default 3) – The number of example rows to list for each problem.
- Returns:
model (BaseModel) – The model with revised data
diagnosis (pd.DataFrame) – The number of bad instances, by alternative, and some example rows.
- Raises:
ValueError – If the repair is set to ‘!’ and there are any conflicts found.