Skip to content

Reports, plots and the command line

symphony_dt.report

Self-contained HTML reports from manifests, gate reports, scores and figures.

figure_to_html

figure_to_html(fig: Any, *, alt: str = 'figure') -> str

Return an tag embedding a matplotlib figure as base64 PNG.

Validation: TESTED.

html_report

html_report(
    manifests: Sequence[Mapping[str, Any]] = (),
    *,
    title: str = "symphony-dt report",
    gates: Mapping[str, Any] | None = None,
    scores: Mapping[str, Any] | None = None,
    figures: Sequence[tuple[str, Any]] = (),
    notes: Sequence[str] = (),
) -> str

Return one HTML page with run manifests, a gate verdict, score cells and figures.

Validation: TESTED.

write_html_report

write_html_report(
    path: str | Path,
    manifests: Sequence[Mapping[str, Any]] = (),
    **kwargs: Any,
) -> Path

Write html_report(...) to path and return the path.

Validation: TESTED.

symphony_dt.plots

Figures: trajectories with intervals, coverage by window, CRPS differences, ranks, PIT and effects.

Every function returns a matplotlib Axes and draws nothing outside it. Colours come from the colour-blind-safe Okabe-Ito palette.

plot_trajectory

plot_trajectory(
    dataset: Any,
    participant_id: str,
    *,
    forecast: Any = None,
    endpoint: str = "updrs3",
    ax: Any = None,
) -> Any

Plot one participant's observed scores and, optionally, forecast intervals after them.

forecast is a Forecast whose targets carry participant_id (fast route) or i and t.

Validation: TESTED.

plot_forecast

plot_forecast(
    forecast: Any,
    *,
    participant: int | None = None,
    ax: Any = None,
) -> Any

Plot central 50% and 95% forecast intervals against horizon, one colour per endpoint.

Validation: TESTED.

plot_coverage_by_window

plot_coverage_by_window(
    scores: Mapping[str, Any],
    *,
    level: str = "c95",
    ax: Any = None,
) -> Any

Plot interval coverage with bootstrap intervals per endpoint, window and method.

scores is FoldScores.scores or PooledScores.scores. The nominal level is drawn as a line.

Validation: TESTED.

plot_subgroup_calibration

plot_subgroup_calibration(
    result: Any,
    *,
    metric: str = "c95",
    endpoint: str | None = None,
    ax: Any = None,
) -> Any

Plot a calibration metric per subgroup level, with bootstrap intervals, for each method.

result is a SubgroupCalibration. Suppressed cells are left out. For coverage the nominal level is drawn as a line. endpoint selects one endpoint; by default the first one present.

Validation: TESTED.

plot_decision_curve

plot_decision_curve(
    result: Any,
    *,
    endpoint: str | None = None,
    ax: Any = None,
) -> Any

Plot net benefit against threshold probability for each strategy, with bootstrap bands.

result is a DecisionCurve. The references "all" and "none" are drawn as grey lines. A suppressed endpoint draws nothing. endpoint selects one endpoint; by default the first one.

Validation: TESTED.

plot_visit_plan

plot_visit_plan(plan: Any, *, ax: Any = None) -> Any

Plot expected variance reduction per unit cost against candidate visit time.

plan is a VisitPlan. Each set of assessed endpoints is one line, and the best option is ringed.

Validation: EXPERIMENTAL.

plot_recalibration

plot_recalibration(
    result: Any,
    *,
    endpoint: str | None = None,
    kind: str = "coverage",
    ax: Any = None,
) -> Any

Plot an endpoint's scores before and after recalibration, on the evaluation subset.

result is a RecalibrationResult. With kind="coverage", interval coverage is drawn against the nominal level, with bootstrap intervals and the diagonal of perfect calibration. With kind="pit", the PIT densities are drawn, where a flat line at one means calibration. A suppressed endpoint draws nothing. endpoint selects one endpoint; by default the first one.

Validation: TESTED.

plot_delta_adjustment

plot_delta_adjustment(
    result: Any,
    *,
    endpoint: str | None = None,
    summary: str = "mean",
    reference: float | None = None,
    ax: Any = None,
) -> Any

Plot a cohort summary against delta, one line per assessment time, with interval bands.

result is a DeltaAdjustment. summary is "mean" or "event_share"; the band is the central interval over draws. reference, when given, is drawn as a dashed line, so a tipping point shows where a curve crosses it. Suppressed cells draw nothing. endpoint defaults to the first one.

Validation: TESTED.

plot_prognostic_trial

plot_prognostic_trial(
    result: Any, *, ax: Any = None
) -> Any

Plot each estimator's effect estimate with its interval, against the simulated effect.

result is a PrognosticTrial. Each row is labelled with its variance ratio against the unadjusted estimate. The dashed line marks the effect added in the simulation.

Validation: TESTED.

plot_identifiability

plot_identifiability(result: Any, *, ax: Any = None) -> Any

Plot contraction per parameter, or contraction against the posterior z-score.

result is an IdentifiabilityReport. With z-scores, each parameter is a point and the flagged regions are shaded: contraction below the weak limit, and |z| above the z limit. Without them, contraction is drawn as one bar per parameter. Flagged parameters are drawn in vermillion.

Validation: TESTED.

plot_crps_differences

plot_crps_differences(
    scores: Mapping[str, Any], *, ax: Any = None
) -> Any

Plot paired CRPS differences (twin minus LOCF, twin minus LMM) with bootstrap intervals.

Negative values favour the twin.

Validation: TESTED.

plot_rank_histogram

plot_rank_histogram(
    ranks: Sequence[int],
    n_draws: int,
    *,
    bins: int = 20,
    level: float = 0.99,
    title: str = "",
    ax: Any = None,
) -> Any

Plot an SBC rank histogram with the binomial band of a uniform histogram.

Validation: TESTED.

plot_pit

plot_pit(
    pit: Sequence[float], *, bins: int = 10, ax: Any = None
) -> Any

Plot a PIT histogram; a flat histogram indicates calibrated predictive distributions.

Validation: TESTED.

plot_effects

plot_effects(
    draws: DataFrame | Mapping[str, Sequence[float]],
    *,
    names: Sequence[str] | None = None,
    ax: Any = None,
) -> Any

Plot posterior medians with 50% and 95% intervals for named parameters (a forest plot).

Validation: TESTED.

save_figure

save_figure(
    fig: Any,
    path: str | Any,
    formats: Sequence[str] = ("png", "pdf", "svg"),
    dpi: int = 200,
) -> list[str]

Save a figure in several formats at once and return the written paths.

path is given without suffix; each format adds its own.

Validation: TESTED.

plot_profile

plot_profile(profile: Any) -> Any

Four panels: visits per participant, intervals, endpoint coverage and boundary shares.

Validation: TESTED.

plot_covariate_shift

plot_covariate_shift(report: Any, *, ax: Any = None) -> Any

Dot plot of the standardised mean difference of each feature, with the threshold marked.

Validation: TESTED.

plot_attrition

plot_attrition(
    result: Any, *, min_cell: int = 10, ax: Any = None
) -> Any

Draw the eligibility flow: one box per step with the count remaining and removed.

Validation: TESTED.

plot_trace

plot_trace(
    csv_files: Sequence[str],
    names: Sequence[str],
    *,
    axes: Any = None,
) -> Any

Trace plots, one row per parameter, one colour per chain.

Validation: TESTED.

plot_rank

plot_rank(
    csv_files: Sequence[str],
    names: Sequence[str],
    *,
    bins: int = 20,
    axes: Any = None,
) -> Any

Rank plots (Vehtari et al. 2021): ranks of pooled draws, one histogram per chain.

Uniform histograms indicate that the chains mix over the same distribution.

Validation: TESTED.

plot_energy

plot_energy(
    csv_files: Sequence[str], *, ax: Any = None
) -> Any

Energy plot: marginal energy against its first differences, pooled over chains.

Clearly narrower differences than marginal energy indicate poor exploration (low E-BFMI).

Validation: TESTED.

plot_cohort_trajectories

plot_cohort_trajectories(
    dataset: Any,
    endpoint: str = "updrs3",
    *,
    by: str = "cohort",
    max_participants: int = 200,
    seed: int = 0,
    ax: Any = None,
) -> Any

Spaghetti plot of observed trajectories, coloured by a participant column, with group medians.

Validation: TESTED.

plot_ppc_intervals

plot_ppc_intervals(
    draws: Any,
    y: Any,
    *,
    level: float = 0.9,
    max_points: int = 300,
    ax: Any = None,
) -> Any

Observed values against predictive intervals, sorted by predictive median (bayesplot style).

Points outside their interval are drawn in vermillion.

Validation: TESTED.

plot_coverage_calibration

plot_coverage_calibration(
    draws: Any,
    y: Any,
    *,
    levels: Sequence[float] = (
        0.1,
        0.2,
        0.3,
        0.4,
        0.5,
        0.6,
        0.7,
        0.8,
        0.9,
        0.95,
    ),
    ax: Any = None,
) -> Any

Empirical coverage of central intervals against nominal level; the diagonal is perfect calibration.

Validation: TESTED.

plot_reliability

plot_reliability(
    p: Any, e: Any, *, bins: int = 10, ax: Any = None
) -> Any

Reliability diagram for event probabilities: observed frequency against forecast probability per bin.

Validation: TESTED.

participant_report

participant_report(
    dataset: Any,
    participant_id: str,
    forecast: Any = None,
    *,
    title: str | None = None,
) -> Any

A one-page figure for one participant: the three endpoints with any forecast, side by side.

Validation: TESTED.

symphony_dt.config

Model configuration: the observation-model switches of pd_v2, named rather than written as literals.

ModelConfig

Bases: BaseModel

The switches and grid settings of one pd_v2 arm.

censored gives each endpoint the tobit density (1) or the truncated density (0). state_dependent_sigma is A01, ledd_in_mu_U is A02 and sigma_xbar is the A01 centring constant. Use ModelConfig.primary() for the study's primary arm.

Validation: VALIDATED. The switch values of primary() and a01_sensitivity() are the study's.

primary classmethod

primary() -> ModelConfig

The study's primary arm: A01 off, A02 on, A03 on for MoCA only.

Validation: VALIDATED.

a01_sensitivity classmethod

a01_sensitivity() -> ModelConfig

The study's pre-declared sensitivity arm: the primary arm with A01 switched on.

Validation: VALIDATED.

hyperparameters

hyperparameters() -> dict[str, Any]

Return the prior hyperparameters this configuration selects.

Validation: VALIDATED.

switches

switches() -> dict[str, Any]

Return the switch entries of the Stan data block.

Validation: VALIDATED.

symphony_dt.labels

Validation labels for every public function and class.

Three labels exist. VALIDATED marks the pd_v2 model and the evaluation code of record, as used in the SYMPHONY v2 study and ported with golden tests. TESTED marks code that is correct on synthetic data and unit tests but has not been validated on a clinical cohort. EXPERIMENTAL marks code whose design is not yet settled.

ValidationLabel

Bases: str, Enum

The validation status of a public function or class.

Validation: TESTED.

validation

validation(
    label: ValidationLabel | str,
) -> Callable[[T], T]

Attach a validation label to a function or class and record it in the registry.

The docstring of the decorated object must state the same label as Validation: <LABEL>.. A test checks the two agree for every public object.

Validation: TESTED.

registry

registry() -> dict[str, ValidationLabel]

Return a copy of the label registry, keyed by qualified name.

Validation: TESTED.

validation_status

validation_status() -> dict[str, str]

Import every public module and return the label of each public object.

Validation: TESTED.

symphony_dt.errors

Exceptions and warnings raised by symphony-dt.

Every package error subclasses SymphonyError, so a caller can catch the whole family at once.

SymphonyError

Bases: Exception

Base class of every error raised by symphony-dt.

SymphonyWarning

Bases: UserWarning

Base class of every warning issued by symphony-dt.

DataValidationError

Bases: SymphonyError, ValueError

A dataset failed schema validation.

The code attribute names the rule that failed, for example DV003.

ModelIntegrityError

Bases: SymphonyError

A frozen model file does not match its recorded sha256.

GateError

Bases: SymphonyError

A convergence gate could not be evaluated, or a gate override is malformed.

UnfrozenSpecificationError

Bases: SymphonyError

Scoring was requested against a specification that is not frozen, or has changed.

MappingError

Bases: SymphonyError, ValueError

An adapter mapping file is malformed or does not match the input.

CmdStanNotFoundError

Bases: SymphonyError

CmdStan is not installed or cannot be found.