MaxDiffMixedLogit.predict_choices#
- MaxDiffMixedLogit.predict_choices(task_df, random_seed=None, new_respondents='error', draw_batch_size=None)[source]#
Fully generative (best, worst) simulation under a new task design.
Unlike
sample_posterior_predictive(), this method does not condition the worst softmax on the observed best pick. For each posterior draw, it:Computes per-task utilities from
beta_item_r(orbeta_item).Samples a best position from
softmax(U).Samples a worst position from
softmax(-U)with the sampled best position excluded.
The resulting
worst_pickis conditional on the freshly sampledbest_pick— the correct generative joint distribution.- Parameters:
- task_df
pd.DataFrame New long-format task data.
is_best/is_worstcolumns may be dummy values; they are ignored for prediction.- random_seed
RandomState, optional Seed for the numpy Generator used for new-respondent population draws and for sampling best / worst. The full output is deterministic given this seed, regardless of
draw_batch_size.- new_respondents{“error”, “population”}, default “error”
How to handle respondents in
task_dfthat were not in the training data, whenrandom_intercepts=True:"error"(default): raiseValueError."population": for each unknown respondent, draw a fresh respondent-level utility vector from the fitted population distributionNormal(beta_item, sigma_item)per posterior sample. This is the standard mixed-logit extrapolation to a brand-new customer.
Ignored when
random_intercepts=False(no respondent-level parameters exist).- draw_batch_size
int, optional If provided, compute the per-task utilities in chunks of this many posterior draws rather than materializing the full
(chain, draw, tasks, positions)tensor at once.Note
The per-respondent utility tensor
pred_beta_rof shape(chains, draws, n_respondents, items)is always fully allocated before batching.draw_batch_sizereduces only the per-task softmax tensor(chains, draw_batch, tasks, k_max). For large studies, peak memory is dominated by the per-respondent tensor, not by the per-task tensor.Output is bit-identical to the unbatched path for a given
random_seed.
- task_df
- Returns:
xr.Datasetposterior_predictive-shaped dataset withbest_pickandworst_pickvariables of shape(chain, draw, tasks)andp_best/p_worstof shape(chain, draw, tasks, positions).