aligned_posterior#

pymc_marketing.pytensor_utils.aligned_posterior(name, posterior_da, layout, *, sample_dims)[source]#

Return posterior_da laid out and checked against layout.

The layout comes from the posterior a graph was constructed with, so a variable is validated against its own construction geometry, not against the whole posterior.

Parameters:
  • name (str) – The posterior variable, named in the error.

  • posterior_da (DataArray) – The variable to lay out.

  • layout (VariableLayout) – The layout it was constructed with.

  • sample_dims (tuple[str, ...]) – The dims that index draws, such as ("chain", "draw") or ("sample",).

Return type:

xr.DataArray

Returns:

posterior_da with the sample dims first, then the layout’s dims in the layout’s order, each labeled dim in the layout’s label order.

Raises:

ValueError – If the dims differ, a dimension is labeled on one side only, a label set differs (or the layout’s labels are duplicated), or a non-sample length differs. The sample dimension may change length freely.