bayesmith.bridge.arviz
Source-derived signatures and contracts. See the reference index for coverage and conventions.
Module contract
Optional ArviZ export: a posterior or predictive result, as an InferenceData.
ArviZ is an OPTIONAL dependency and this is an export-only seam (§0.8): nothing
in the core package imports it, and this module reads it only inside the
function, so ``import bayesmith.bridge.arviz`` stays cheap and succeeds even
where arviz is not installed. The export is a projection, not a re-judgement:
the NamedArrays a result already holds are reshaped and renamed into arviz's
groups, and no number is recomputed.
Group mapping:
posterior the latent draws
posterior_predictive the replicated draws (a PredictiveResult only)
log_likelihood the pointwise log density
observed_data the observed node data, the ``data`` half of
``observation_parts``
The draw axis a NamedArray carries is split into arviz's ``chain``/``draw``
axes when the result came from a chain, and stays a single ``draw`` axis when
it did not. A plated node keeps its plate name as an axis and a flat node
keeps its ``{name}_dim{i}`` axis, so the observation unit survives the
round-trip.to_inference_data
Defined in bayesmith.bridge.arviz, line 95.
to_inference_data(result: Any, *, graph: Graph, chain_shape: tuple[int, int] | None=None) -> AnyExport a posterior or predictive result into arviz's InferenceData.
ArviZ 1.x returns a ``DataTree``, which IS its InferenceData; the groups
are its children. The export is a thin projection: ``posterior`` holds the
latent draws, ``posterior_predictive`` the replicated draws,
``log_likelihood`` the pointwise log density, and ``observed_data`` the
observed node data.
Args:
result: a PosteriorResult or PredictiveResult.
graph: the model the result was produced from, read for the observed
data.
chain_shape: ``(num_chains, num_draws)`` to split the draw axis into
arviz's ``chain``/``draw`` axes. Defaults to the
``chain_shape`` a DrawsPosterior already carries, and to ``None``
(one flat draw axis) for a PredictiveResult unless the caller
supplies the source posterior's chain shape.