Repository navigation
Add Dynamic survival analysis for early event prediction (MIMIC-III decompensation) - #1558
shusted3-gt wants to merge 13 commits into
Conversation
38fe1a4 to
033333c
Compare
|
/review |
033333c to
40057be
Compare
|
/review |
|
I rebased this branch on the latest master (no conflicts) and re-ran the tests and the PR rules check locally: 80 tests pass and the contribution rules pass. The build and contribution-rules workflows are still waiting for approval because this is my first contribution to the repo. Could a maintainer please approve them so the checks can run? Happy to make any recommended adjustments, thank you! |
Test CoverageTotal: 86.30% (45810 / 53082 lines)
|
|
/review |
| if self.label_mode == "survival": | ||
| self.task_name = f"{self.task_name}_survival" | ||
|
|
||
| def pre_filter(self, df: Any) -> Any: |
There was a problem hiding this comment.
[medium] pre_filter has no test
DecompensationMIMIC3.pre_filter drops every chartevents/labevents row whose itemid is not in ITEMS, and keeps all other event types. The only test in tests/core/test_decompensation_mimic3.py covers _missing, so a wrong filter (for example a cast or a keep-mask error) would silently change every sample and no test would fail. Add a test with a small pl.LazyFrame that checks the mapped itemids are kept, unmapped ones are dropped, and other event types pass through, and that missing columns raise ValueError.
There was a problem hiding this comment.
Added in cf289f6: tests for pre_filter (mapped items kept, unmapped and non-numeric dropped, other tables pass through, missing columns raise ValueError) and an end-to-end MIMIC3Dataset.set_task test.
| [2.0] | ||
| """ | ||
| stays = _check_stays(scores, times, time_to_event, event, horizon) | ||
| n_events = sum(s[3] for s in stays) |
There was a problem hiding this comment.
[medium] Events no alarm can reach are counted in the recall denominator
n_events counts every stay with an observed death (event == 1). The task sets event to 1 for deaths after ICU discharge too, as the test 'late death' expects. A death more than horizon hours after the last step can never fall in an alarm window, so those events cap event recall below 1 and lower alarm_event_auprc and event_recall@p. The reported numbers (for example 0.533 vs 0.674 in the paper) are therefore understated by this definition, and the description does not mention it. Fix: count only events that some step of the stay could warn of, such as deaths within horizon hours of the stay's end, or state the definition and the share of such events in the description and docs.
There was a problem hiding this comment.
Documented in the event_alarm module docstring and in the PR description (cf289f6). The metric itself is unchanged, so the reported numbers stay as they are.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution, Sarah and Allyson. It adds a MIMIC-III decompensation task with binary and survival label modes, a DynamicSurvivalRNN built on RNN_V2, event-level alarm metrics, a runnable ablation, docs and about 80 tests. It also reports its results, including the ones that don't match the paper, which I appreciate.
This looks ready to merge. All the components are new and self-contained, and the exports in the __init__.py files are registration only. The link to RNN_V2 (subclassing it and using its helpers) is covered by the description's "built on RNN_V2". Coverage meets the bar: 86.3% for the repository, 98.9% for event_alarm.py, 100% for dynamic_survival.py, 96.7% for dynamic_survival_rnn.py and 90.8% for decompensation_mimic3.py. The docs match the code.
Optional suggestions:
- Add a small test for
DecompensationMIMIC3.pre_filter, for example on a tiny polars LazyFrame. Today only_missingis tested, and a wrong item filter would silently change every sample. - Say in the description or the
event_alarmdocs how events are counted for recall. Deaths that happen long after ICU discharge count as events, but no step can warn of them. This caps recall below 1 and may explain part of the gap to the paper's alarm/event numbers. - Mention that
pyhealth/tasks/medmod_decompensation_mimic4.pyimplements a similar 24 h label for MIMIC-IV, and why this MIMIC-III task is separate. - Consider a small test that goes through
MIMIC3Dataset.set_taskend to end. At the moment only the example scripts cover it.
Reviewed commit 40057be
|
Why this PR has To help the maintainers decide, please comment here with what your PR does that the others don't, such as fidelity to the paper, results or test coverage. Whichever PR isn't picked can still contribute its unique parts on top of the chosen one. The decision is tracked in #1668. The AI review suggested approve on an older commit. Please rebase (registration lines only) so it can be reviewed again on the latest code. |
|
Picked as PyHealth's dynamic survival analysis model and MIMIC-III decompensation task. We compared this with #1646. Yours is the more correct and complete of the two:
The AI review suggested approve on 40057be, and this PR was opened first. Before it can merge:
We've asked #1646 to contribute survTLS smoothing, PMF and survival outputs, and extra alarm policies on top of this. |
cf289f6 to
3293448
Compare
|
Completed rebase on master (no conflicts) and re-ran the tests and the PR rules check locally: 84 tests pass and the contribution rules pass. |
|
/review |
3293448 to
82eaff4
Compare
|
/review |
Contributors:
Georgia Tech CSE/OAN 6250 (Big Data for Health), Fall 2026.
Contribution Type: Full Pipeline (model + task + metrics + pipeline-level ablation on the existing
MIMIC3Dataset; no new dataset class,mimic3_icu.yamladds the extra columns the task needs).Paper: Yèche, Burger, Veshchezerova, Rätsch. "Dynamic Survival Analysis for Early Event Prediction." CHIL 2024. https://proceedings.mlr.press/v248/yeche24a.html
Description:
Reproduces part of the paper in PyHealth on the MIMIC-III decompensation task (death within
horizonhours, predicted every hour, cohort of Harutyunyan et al. 2019).DecompensationMIMIC3): hourly samples from 17 chart/lab variables.label_mode="survival"adds the per-steptime_to_eventandeventlabels the survival model needs. The default"binary"mode is unchanged.DynamicSurvivalRNN, built onRNN_V2): predicts a hazard for each of the nexthorizonhours, trained with the survival loss truncated to the horizon (Eq. 3-4 of the paper). It returns the risk of the event within the horizon,1 - prod(1 - hazard_k). The hazard head's bias can be initialized to the average hazard of each hour (Section 3.2).pyhealth.metrics.event_alarm): the event-level evaluation of Section 4.1: an alarm policy with silencing, alarm precision, event recall at a given alarm precision, first-alarm distance, and the area under the alarm precision / event recall curve.examples/mimic3_decompensation_dsa_ablation.py): EEP baseline vs. DSA with and without hazard-bias initialization, same encoder and patient split, over seeds.The survival loss, the bias initialization and the event-level metrics are implemented from the paper's equations and sections, and the task follows its MIMIC-III decompensation setup.
Not implemented (future work): survTLS, the imminent-prioritization alarm policy, HiRID and the other tasks. Only the fixed-horizon alarm policy is used.
Related: pyhealth/tasks/medmod_decompensation_mimic4.py implements the same 24 h decompensation definition for the MedMod multimodal benchmark on MIMIC-IV with chest X-rays and only a binary label. DecompensationMIMIC3 is separate because it runs on MIMIC-III with the 17 benchmark variables and adds the per-step time-to-event and event labels that the survival model needs.
Files to Review:
pyhealth/tasks/decompensation_mimic3.py- task: cohort selection, benchmark cleaning rules, hourly samples, binary and survival label modespyhealth/models/dynamic_survival_rnn.py- model: hazard head, truncated survival loss, risk, bias initializationpyhealth/models/dynamic_survival.py- NumPy reference for the targets, hazard prior and loss (what the model is tested against)pyhealth/metrics/event_alarm.py- event-level alarm metricsexamples/mimic3_decompensation_dsa_ablation.py- runnable end-to-end ablation (demo-data command in its docstring)examples/mimic3_decompensation_rnn_v2.py- baseline classifier and horizon ablationpyhealth/datasets/configs/mimic3_icu.yaml- extra MIMIC-III columns for the tasktests/core/test_decompensation_mimic3.py,test_dynamic_survival.py,test_dynamic_survival_rnn.py,test_event_alarm.py- 84 tests on synthetic datadocs/api/...and the__init__.pyfiles ofpyhealth/models,pyhealth/metricsandpyhealth/tasks- docs pages and exportsResults
(30% sample of MIMIC-III patients: 8,624 / 1,848 / 1,862 stays for train / validation / test, 189 test events; horizon 24 h, 5 seeds, 20 epochs; mean over seeds):
Limitations:
30% patient sample (disk limits for the full event cache), one fixed patient split, 20 epochs, a small GRU. The EEP and bias-init arms changed little between 10 and 20 epochs; the no-bias-init arm may not be converged. Cohort and alarm-evaluation details may differ from the paper's code, so absolute numbers are not directly comparable.
Event recall counts every observed death as an event, including deaths long after the last step of the stay (for example after ICU discharge) that no alarm can warn of. This caps recall below 1 and understates alarm/event AuPRC and event recall relative to a definition that excludes them; the definition is documented in the event_alarm module docstring.