symphony_dt.diagnostics¶
symphony_dt.diagnostics ¶
Convergence gates of the SYMPHONY v2 study, fixed in one place.
C2: max rank-normalised split R-hat at most 1.01 over the global parameters. C3: min bulk ESS at
least 400. At least four retained chains. A chain is excluded when its mean lp__ falls more than
5.0 within-chain standard deviations below the best chain. GateReport.converged derives from these
three verdicts and nothing else. Divergences, tree depth saturation, E-BFMI and tail ESS are
reported beside it.
The thresholds are module constants. A different threshold needs an explicit GateOverride with a
reason and an author; the override is written into the report, the manifest and a warning.
GateOverrideWarning ¶
GateOverride
dataclass
¶
An explicit, logged change to one or more gate thresholds.
A reason and an author are required. Every use issues a GateOverrideWarning and is recorded in the gate report and in the run manifest, so no threshold changes silently.
Validation: TESTED.
GateReport
dataclass
¶
The verdict of the convergence gates on one fit.
converged is derived from meets_c2, meets_c3 and meets_min_retained only.
Validation: VALIDATED design. The derivation matches the study's combine_fold.
meets_min_retained
property
¶
meets_min_retained: bool
At least the required number of retained chains.
lowest_ess ¶
lowest_ess(n: int = 5) -> list[tuple[str, float]]
Return the n global parameters with the lowest bulk ESS.
Validation: TESTED.
to_dict ¶
to_dict() -> dict[str, Any]
Return a JSON-serialisable record, in the layout of the study's fit record.
Validation: TESTED.
summary_lines ¶
summary_lines() -> list[str]
Return a short human-readable verdict.
Validation: TESTED.
is_global ¶
is_global(name: str) -> bool
Return True for a global parameter, False for sampler columns and per-participant blocks.
Validation: VALIDATED.
retained_chains ¶
retained_chains(
lp: ArrayLike, *, override: GateOverride | None = None
) -> dict[str, Any]
Apply the pre-declared chain-exclusion rule to lp, shaped (draws, chains).
Returns the decision and every number behind it, so a reader can apply another multiple to the same run without refitting.
Validation: VALIDATED. Equal to the study's sbc.retained_chains.
chain_id ¶
chain_id(csv_file: str | Path) -> int
Return the chain id of a CmdStan CSV file.
The id is the trailing _N of the file name. A one-chain run has no such suffix, because cmdstanpy names its
file without one, so the id = N line of the CmdStan header is read instead.
Validation: TESTED.
chain_csvs_in_order ¶
chain_csvs_in_order(
csv_files: Sequence[str | Path],
) -> list[str]
Sort chain CSV files by their chain id, never lexically.
Validation: VALIDATED. The id comes from chain_id, which also reads one-chain files.
summary_on_chains ¶
summary_on_chains(
csv_files: Sequence[str | Path],
keep: Sequence[int] | None = None,
) -> pd.DataFrame
Run CmdStan's own stansummary on a subset of chains and return its table.
The statistics are not re-implemented: rank-normalised split R-hat, bulk and tail ESS come from
the same binary fit.summary() calls, restricted to the retained chains.
Validation: VALIDATED.
read_sampler_columns ¶
read_sampler_columns(
csv_files: Sequence[str | Path],
) -> dict[str, np.ndarray]
Read lp__, divergent__, treedepth__ and energy__ from chain CSVs as (draws, chains) arrays.
Validation: TESTED.
e_bfmi ¶
e_bfmi(energy: ArrayLike) -> list[float]
Return the energy Bayesian fraction of missing information per chain.
energy is (draws, chains). Values below 0.3 suggest poor exploration.
Validation: TESTED.
assess_tables ¶
assess_tables(
lp: ArrayLike,
summary: DataFrame,
*,
override: GateOverride | None = None,
sampler: dict[str, ndarray] | None = None,
max_treedepth: int = 10,
) -> GateReport
Build a GateReport from an lp__ matrix and a stansummary table of the retained chains.
This is the computational core of assess, separated so it can be tested without CmdStan.
Validation: VALIDATED.
assess ¶
assess(
csv_files: Sequence[str | Path],
*,
override: GateOverride | None = None,
max_treedepth: int = 10,
) -> GateReport
Judge all chains of one fit together, as the study's combine_fold does.
Reads lp__ from every chain, applies the chain-exclusion rule, runs stansummary on the
retained chains and evaluates C2, C3 and the retained-chain count on the global parameters.
Validation: VALIDATED.