Package validation and Monte Carlo cache¶
The vitaldb_resolution package returns a status for every value in the dataset, reproduces each fitted likelihood, and can precompute every posterior for fast Monte Carlo draws.
| Date | 2026-10-13 |
| Status | current |
| Methods | Rounding, heaping and value resolution |
Background¶
- The API takes a VitalDB variable name and a recorded value and returns a distribution over true values. Single-resolution variables get one uniform component; heaped variables get a mixture over rounding modes.
Data¶
- 6,388 cases × 79 clinical variables (504,652 variable-case cells) and all 928,448 lab results.
Method¶
- Ran the full dataset through the package and compared each model's log-likelihood with the stored one:
python tools/validate.py clinical_data.csv lab_data.csv --fullin vitaldb-resolution, which writesvalidation_report.json(statuses, flags, densities, latent and uniform gaps, and the wall time of each pass). - Built quantile tables for posteriors from fitted models and compared knot counts, storage types and knot placement against the exact posteriors:
python tools/precision_study.py clinical_data.csv lab_data.csv OUT(tail-mean end knots, the cache's rule) and the same with--end-knots support --no-cache(end knots at the support ends), which writeOUT/precision.jsonandOUT/precision_support.json.
Results¶
- Clinical statuses: 217,132 ok, 61,106 zero or not recorded, 45,533 missing, 178,864 not applicable, 1,987 imputed, 20 invalid, 10 top-coded. Lab results: 927,816 ok, 543 top-coded (lactate 317, aPTT 226) and 89 bottom-coded (ESR), with 19 off-grid flags (validation_report.json, vitaldb-resolution 0.6.0).
- The clinical pass takes 4.2 min and the lab pass 5.0 min on one core (WSL2 on the author's PC; 2 November).
- The cache holds the whole dataset in 214 MB (1,024 knots, int16). One iteration draws every value in about 7 ms for the cases and about 18 ms including all lab results on the same machine.
- At any number of knots, int16 has the same worst-case error as float32 and float64. The default is 1,024 knots in int16, with worst mean error 4.7 × 10⁻⁴ SD.
- Knot placement mattered more than either. End knots at the support ends inflated the SD by up to 46 % at 256 knots (13 % at 1,024); interior knots with tail-mean-preserving end knots cut the worst SD error to 1.1 % and 0.42 %.
- Since vitaldb-resolution v0.6.0 (18 October; model version 2): each result's density within a rounding
interval comes from the fitted latent at call time (uniform only where no latent is fitted), and every result
names its density, model id, version and fit hash. The latent and uniform means differ by a few per cent of
the interval near the median and by 0.2–0.45 of its width at small values and at the edges. Models are
versioned (v1 archived and still loadable,
models.lockper release), every stored log-likelihood now matches the recomputed one, and the registry records each anchor's basis. - Reproduced (2 November). Rerun on 2 November with vitaldb-resolution 0.6.0 (commit 93bbf7f, WSL2):
python tools/validate.py clinical_data.csv lab_data.csv --full(validation_report.json) andpython tools/precision_study.py clinical_data.csv lab_data.csv OUT, then the same with--end-knots support --knots 256,1024 --no-cache(precision.json, precision_support.json; outputs in$W/distribution_api_validation). Every status count, flag and log-likelihood is identical to the released report; the precision figures match the earlier run, except that the SD inflation with end knots at the support ends is 46% at 256 knots, not the 80% first written, and the timings, which depend on the machine, are now those of this run. The precision run's arrays measure 214 MB at the default; the resident memory added on loading (also recorded) is not a reliable measure across options and is not quoted.
Discussion¶
- The default's worst mean error is about 20 times smaller than the Monte Carlo standard error after 10,000 iterations.
- Building the package surfaced new rules: two out-of-range anaesthesia ends, 93 clock-offset mismatches, child native resolution, and a revised red-cell rule.
Limitations¶
- Where a posterior has a gap between two rounding windows, draws can land inside it. This is the large point-wise quantile error (0.8 SD at the 99th percentile at 1,024 knots); it barely moves the mean, SD or W1.
- The 214 MB, the 7 and 10 minute passes, the pre-fix inflation of up to 80% and the 0.8 SD at the 99th percentile are not in a saved output;
tools/precision_results.jsongives the cache as 186.7 MB at 1,024 knots.
Worked examples¶
| Example | Side | Status | Summary |
|---|---|---|---|
| A regression that carries rounding uncertainty through | value | current | Acute kidney injury after surgery against intraoperative urine output (mL/kg/h), fitted once on the recorded numbers and once per draw from the true-value distributions: the rounding moves 14% of cases across the oliguria threshold, but widens the confidence interval of the cohort's regression by at most 4%. |
Code¶
Tags: from the resolution work