transpose_to_model_dims#

pymc_marketing.pytensor_utils.transpose_to_model_dims(posterior, model_dims, *, sample_dims=('chain', 'draw'))[source]#

Return posterior with each variable’s dims in the order the model declares.

PyMC’s posterior predictive reads a variable’s values in storage order against the dims its model declares, so a variable stored as (channel, geo) for a model that declares (geo, channel) is read transposed, and silently so when the two axes have the same length. A variable whose non-sample dims are the declared dims in another order is transposed. Any other variable (one the model does not declare, or one over another set of dims) is left as given.

Parameters:
  • posterior (Dataset) – The draws to transpose.

  • model_dims (Mapping[str, Sequence[str | None]]) – The dims of each model variable, such as pm.Model.named_vars_to_dims.

  • sample_dims (tuple[str, ...]) – The dims that index draws. They stay in front, in their stored order.

Return type:

xr.Dataset

Returns:

posterior with every such variable in the model’s dim order, or posterior itself when every variable already is.