PyBNF ArviZ bridge (pybnf.inference_data)¶
The ArviZ InferenceData bridge (ADR-0055, issue #438 item 3).
from_pybnf maps a finished PyBNF MCMC run’s saved samples onto an
arviz.InferenceData, so PyBNF’s posterior output becomes first-class in
the ArviZ / bayesplot / loo ecosystem (trace / rank / forest / pair plots,
az.summary, az.compare). It is a format bridge, not new statistics:
PyBNF already runs the samplers, writes Results/samples.txt, and computes
rank-normalized split-R-hat + bulk/tail ESS (pybnf.diagnostics, ADR-0009).
Design (ADR-0055), in brief:
Source = the saved sample on disk.
Results/samples.txtis the thinned, post-burn-in posterior sample (written everysample_everyiterations after burn-in) – the same drawscredible*.txtand the histograms are built from. It is not the dense in-memory chaindiagnostics.txtis computed on, so ArviZ recomputing diagnostics here gives valid numbers on fewer draws: R-hat is comparable,az.essreads lower thandiagnostics.txtby design. A user wanting denser ArviZ diagnostics lowerssample_every. PyBNF’s own final R-hat/ESS are copied into the object’sattrsso nothing is lost.Posterior in sampling space. A log-scaled parameter is emitted in its sampling space (
log10/ln), the space the sampler moved in and the spacediagnostics.pyalready uses – so ArviZ’s diagnostics share PyBNF’s parameterization and Vehtari method. The variable is named<scale>_<name>(e.g.log10_k) so the space is explicit. Linear parameters are unchanged. Recovering each parameter’s scale needs the run’s free parameters: the auto-emit path passes the livevariables; the standalone path auto-discovers the.confcopied intoResults/and falls back to natural-space-with-a-warning if it cannot.Groups: ``posterior`` + ``sample_stats`` (``lp``), plus an optional ``log_likelihood``. When the run recorded the per-observation log-likelihood sidecar (
output_inference_dataset + a per-point likelihood objfunc, ADR-0056, #438 item 4), the bridge adds alog_likelihoodgroup soaz.loo/az.waic/az.comparework directly. Its values are genuine unweighted per-point log-densities (the complete, normalized familylog_density), not-score.priorandobserved_dataremain deferred.
arviz is an optional extra (pip install pybnf[arviz]), imported lazily so
core stays dependency-free (ADR-0019). Both arviz major lines are supported – the
classic 0.x InferenceData and the 1.x xarray-DataTree rewrite – since they
differ only in the one from_dict construction call (see _build_idata); the
extra is uncapped so installing the bridge never downgrades a user’s arviz.
- pybnf.inference_data.from_pybnf(source, *, config=None, variables=None)[source]¶
Build an
arviz.InferenceDatafrom a finished PyBNF MCMC run.- Parameters:
source – a
Results/directory, an output directory containingResults/, or asamples.txtfile. An Adaptive_MCMC (am) run’sResults/is read from its per-chainA_MCMC/Runs/params_<chain>.txtfiles (it writes no usablesamples.txt) – see_resolve_samples_path().config – optional path /
Configurationused to recover each parameter’s scale for sampling-space output. Ignored whenvariablesis given; auto-discovered fromsourcewhen both are None.variables – optional list of the run’s free parameters (the in-process auto-emit path passes these directly, so no config reload is needed).
- Returns:
an
InferenceDatawith aposteriorgroup (one variable per parameter, dimschainxdraw, log parameters in sampling space) and, for samplers that record it, asample_statsgroup carryinglp(the recorded log-posterior; omitted foram, which records draws only). When alog_likelihood.txtsidecar is present beside the samples (ADR-0056), alog_likelihoodgroup (variableyover anobs_idaxis) is added soaz.loo/az.waic/az.comparework directly.- Raises:
ImportError – if the optional
arvizextra is not installed.