Input and output¶
read_table and write_table handle CSV, TSV, Parquet, Excel and Arrow, chosen by file suffix. Both accept
pandas or polars frames. write_dataset stores a TwinDataset as one table per frame plus dataset.json, and
read_dataset checks the fingerprint on the way back.
from symphony_dt.io import write_dataset, read_dataset
write_dataset(ds, "cohort", format="parquet")
same = read_dataset("cohort")
Posteriors are stored as netCDF through ArviZ: write_posterior(idata, "fit.nc") and read_posterior("fit.nc").
Adapters for wide tables, OMOP CDM, FHIR R4, CDISC SDTM and the PPMI download layout are described on the Interoperability page.
Fits and forecasts as ArviZ InferenceData (TESTED)¶
fit_to_inference_data turns a fit into the groups ArviZ expects, so its diagnostics and plots work directly.
from symphony_dt.io import fit_to_inference_data, forecast_to_inference_data, write_posterior
idata = fit_to_inference_data(result, split.fit) # result is a FitResult, split.fit its data
write_posterior(idata, "fit.nc")
fc = forecast_to_inference_data(forecast) # forecast from forecast_exact or forecast_fast
A fit gives posterior, with chain and draw dimensions, and sample_stats under ArviZ's names. Given the fit's
data, it also gives observed_data, posterior_predictive and log_likelihood. Replicated data come from the
model's own truncated or censored observation density. The log likelihood is the one fit_log_likelihood returns.
Per-participant latent blocks are left out of the posterior unless globals_only=False.
A forecast gives posterior_predictive over its targets, observed_data where a target was observed, and
constant_data with each target's participant, endpoint, time and horizon. Forecast draws are pooled across
chains, so the chain dimension has length one.
ArviZ 0.x returns an InferenceData and ArviZ 1.x an xarray DataTree. Both write to netCDF with
write_posterior, which needs the io extra.