Repository navigation
Conversation
Test CoverageTotal: 87.03% (51038 / 58641 lines)
|
|
/review |
| indicates whether death occurs strictly within the prediction horizon. | ||
|
|
||
| The cohort follows the MIMIC-III benchmark convention of adult ICU stays | ||
| and excludes transfers between wards or care units within the stay. |
There was a problem hiding this comment.
[medium] Class docstring says transfers within the stay are excluded; code checks only first vs last unit
The docstring says the cohort 'excludes transfers between wards or care units within the stay'. The code (lines 763-768) only compares first_wardid with last_wardid and first_careunit with last_careunit, and the PR's own docs say intermediate transfers are not detected. Reword to say the stay is excluded when its first and last ward or care unit differ, and that intermediate transfers are not checked.
| if task.survtls_lengthscale is None: | ||
| hazard_label[event_index] = 1.0 | ||
| else: | ||
| hazard_label = task._smooth_survival_label(event_bin) |
There was a problem hiding this comment.
[medium] Example reuses the task's private _smooth_survival_label helper (undisclosed link)
This example calls task._smooth_survival_label, a private method of DecompensationMIMIC3, to build synthetic survTLS targets. The description does not mention this link. PyHealth keeps components self-contained so that changing one does not silently change another, so a private helper used from outside the class is a coupling. Either confirm the sharing and explain it in the description, or keep the component self-contained by building the synthetic targets inside the example.
| import numpy as np | ||
| import pytest | ||
|
|
||
| from examples.mortality_prediction.pmf_urgency import pmf_urgency_score |
There was a problem hiding this comment.
[medium] Test imports the example module examples/mortality_prediction/pmf_urgency.py (undisclosed link)
The test imports pmf_urgency_score from an example script. The description calls the function 'reusable' but does not say a test depends on the example module. Either confirm the sharing and say why in the description (for example, that the example module is the canonical implementation), or keep the test self-contained by moving the scoring function to a module the test can own.
| EXAMPLE_DIR = Path(__file__).resolve().parents[2] / "examples" / "mortality_prediction" | ||
| sys.path.insert(0, str(EXAMPLE_DIR)) | ||
|
|
||
| from early_event_metrics import ( |
There was a problem hiding this comment.
[medium] Test loads examples/mortality_prediction/early_event_metrics.py through sys.path (undisclosed link)
The test puts the example directory on sys.path and imports early_event_metrics. The description does not state this link. Either confirm and explain the sharing in the description, or keep the component self-contained. Note that the metrics live in examples/ rather than pyhealth/metrics/, so they are not importable as library code.
| - "first_careunit" | ||
| - "dbsource" | ||
| - "last_careunit" | ||
| - "first_wardid" |
There was a problem hiding this comment.
[medium] New dedicated MIMIC-III config has no committed loader test
The config adds first_wardid and last_wardid to icustays, and the description says it was validated only with temporary synthetic CSV fixtures that are not in the repo. Existing MIMIC-III config behavior is covered by tests such as tests/core/test_mimic3.py. Add a committed test that loads the dedicated config with a small CSV fixture and checks that both ward IDs appear in the patient events, plus a check that the default config still loads without them.
| if age_years < 18: | ||
| continue | ||
|
|
||
| mortality = ( |
There was a problem hiding this comment.
[low] mortality flag includes dod, but labels use only deathtime
mortality is true when dod falls in the admission window (line 789), but death_time is taken only from deathtime (line 793), so a stay with dod in the window and no deathtime gets mortality=1 in the sample (line 867) while every y_true is 0. Either use deathtime for both, or document the difference.
| 7.207267791681239, | ||
| ) | ||
|
|
||
| CONTINUOUS_STDS: ClassVar[tuple[float, ...]] = ( |
There was a problem hiding this comment.
[low] Normalization constants look outlier-driven; provenance should be stated
Several standard deviations look implausible for the channels they describe: glucose about 1767 (mean 140), SpO2 about 5135 (mean 105), diastolic BP about 222 (mean 62), and pH about 1.66 (mean 7.2). With these values, typical measurements z-score to near zero, and the tests only check the arithmetic. Document where the statistics came from, state whether they were computed on cleaned data, and confirm they match the reference preprocessing.
| return samples | ||
|
|
||
|
|
||
| def validation_auprc(model: DSA, loader) -> float: |
There was a problem hiding this comment.
[low] validation_auprc is used to score the test split
The helper is named validation_auprc but is called with test_loader on line 211. Rename it to something like evaluate_auprc so the reported number is not mistaken for a validation score.
| if __name__ == "__main__": | ||
| unittest.main() | ||
|
|
||
| def test_dsa_state_dict_roundtrip(): |
There was a problem hiding this comment.
[low] State-dict test is defined after the main block
test_dsa_state_dict_roundtrip sits after the if name == 'main' block that calls unittest.main(), so running the file directly exits before the test is defined. Move it above the block and use self.assertTrue or assertEqual inside a TestCase for consistency with the rest of the file.
There was a problem hiding this comment.
AI Review
suggestion: need change
decision: human review
Thank you for this substantial contribution. It adds a Dynamic Survival Analysis (DSA) model, an hourly MIMIC-III decompensation task, an opt-in ward-ID config, examples, docs and tests. It is close, but a few things need fixing first.
To get this merged:
- Coverage:
pyhealth/tasks/decompensation_mimic3.pyis at 66.67%, below the 80% per-file bar. The uncovered code is probably the chartevent and labevent parsing in_clean_valueand_hourly_observations. Please add tests for the unit conversions (temperature, weight, height, FiO2, blood pressure strings, categorical values) and for event filtering by stay and time. Overall repo coverage (87%) anddsa.py(84.75%) are fine. - Sharing between components:
examples/mortality_prediction/mimic3_decompensation_dsa.pycalls the task's private_smooth_survival_label. Two tests (test_early_event_metrics.pyandtest_pmf_urgency.py) import from theexamples/modules. The description doesn't mention either. Please say in the description why you share this code, or keep the pieces self-contained, for example by using a public method or copying the logic. Either choice is fine. - Docstring accuracy: the task docstring says transfers between wards or care units within the stay are excluded. The code only compares the first and last ward and the first and last care unit. Please reword it to match, as your API docs already do.
- Config test: the new
mimic3_decompensation.yamlis never loaded by a committed test. Please add a small test that loads it through the dataset loader with a synthetic fixture. You have already run this manually.
Optional suggestions:
- The
mortalityflag countsdod, but the labels use onlydeathtime. Consider aligning them or documenting the difference. - Please document where
CONTINUOUS_STDScomes from. Some values look very large. validation_auprcin the full-pipeline example actually scores the test set, so a rename would help.- The module-level
test_dsa_state_dict_roundtripsits after the__main__guard intest_dsa.py. Moving it above the guard is cleaner. - The
from .decompensation_mimic3 import ...line intasks/__init__.pysits after the__getattr__function. Moving it up with the other imports is tidier.
Reviewed commit b0a3025
|
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's open points on this PR still apply. |
|
We compared this with #1558 and picked #1558 as the base. This PR has these problems:
Your PR has several things #1558 doesn't, and we'd like them on top. After #1558 merges, please contribute the following, with tests in
Drop:
|
Contributors
Georgia Institute of Technology — CSE 6250: Big Data for Health, Fall 2026
Team B5 — Paper #31
Contribution Type
Related Paper
Dynamic Survival Analysis for Early Event Prediction, CHIL 2024.
Description
This PR introduces Dynamic Survival Analysis (DSA) for early event prediction and integrates an hourly MIMIC-III decompensation prediction task into PyHealth.
Model
BaseModel.Task
BaseTask.jaggedfeature processor.Additional Contributions
Files to Review
Core Implementation
pyhealth/models/dsa.py: DSA model and survival prediction.pyhealth/tasks/decompensation_mimic3.py: Hourly feature processing and survival targets.pyhealth/datasets/configs/mimic3_decompensation.yaml: Dedicated configuration exposing first and last ward IDs while preserving the default MIMIC-III configuration.pyhealth/models/__init__.py: Model export.pyhealth/tasks/__init__.py: Task export.Examples and Evaluation
All six files below are in
examples/mortality_prediction/.mimic3_decompensation_dsa.py: Synthetic model ablation.mimic3_decompensation_dsa_full_pipeline.py: Synthetic patient-to-task-to-model training and evaluation.early_event_metrics.py: Event-level alarm evaluation.pmf_urgency.py: PMF urgency scoring and synthetic example.DSA_REPRODUCTION_RESULTS.md: Reproduction and extension results.DSA_SYNTHETIC_PIPELINE_RESULTS.md: Synthetic integration results.Documentation
docs/api/models/pyhealth.models.DSA.rstdocs/api/tasks/pyhealth.tasks.decompensation_mimic3.rstdocs/api/models.rstdocs/api/tasks.rstUnit Tests
tests/core/test_dsa.pytests/core/test_decompensation_mimic3.py: Task tests, including five additional ward and care-unit filtering regression tests.tests/core/test_early_event_metrics.pytests/core/test_pmf_urgency.pyReproduction and Ablation Results
Compute-constrained training reproduced the qualitative improvement across the DSA ablations. Full-cohort evaluation using saved predictions yielded the following timestep-level test AuPRC values:
The MIMIC-III test cohort contains 523,208 timesteps from 6,237 ICU stays, including 490 event stays. Bias initialization and truncation improved AuPRC, while survTLS performed slightly better than truncation. The EEP baseline achieved slightly higher fixed-horizon AuPRC than survTLS.
Extension: PMF-Based Patient-Specific Urgency
The extension combines cumulative event risk with near-term event probability share and expected event imminence. It uses a 24-hour prediction horizon, a 6-hour near-term horizon, and equal weighting (alpha = 0.5).
Full-cohort event-level test AuPRC:
The proposed strategy outperformed both fixed-horizon strategies but did not exceed the reproduced imminent priority strategy.
The reusable scoring function was verified against 808,167 saved validation and test timestep scores (284,959 validation and 523,208 test). All records aligned, with a maximum absolute error of approximately 3.33e-16 in both splits. This verifies scoring consistency, not an independent recomputation of the complete event-level evaluation.
Synthetic Examples and End-to-End Validation
The lightweight model ablation uses 48 synthetic samples. Test AuPRC for the three configurations:
The end-to-end example processes 12 synthetic ICU patients through the decompensation task, constructs PyHealth sample datasets, trains DSA using PyHealth Trainer, and evaluates held-out patients. It uses patient-level train/validation/test splits (8/2/2 patients; 204/51/51 hourly samples).
Synthetic end-to-end test AuPRC:
Both examples run on CPU without restricted clinical data. These synthetic scores demonstrate functionality, not clinical performance.
Testing and Validation
The following checks were completed locally:
masteralignment checked before the initial submission.Running the Tests
From the repository root in a PyHealth environment with the required dependencies:
Running the Examples
Backward Compatibility Fix
The initial GitHub CI run reported 15 failures and 12 setup errors caused by mandatory ward ID attributes in the default MIMIC-III configuration. The repository's demo fixture does not contain those columns.
Commit
b0a3025daddresses this issue:mimic3.yamlconfiguration, leaving existing tasks unaffected by the additional attribute requirements.mimic3_decompensation.yamlas an opt-in configuration for datasets containing both ward ID columns.All nine affected regression test files were rerun locally: 55 tests passed, 3 were skipped, and there were no failures or errors. The actual dataset loader also successfully loaded both configurations using synthetic CSV fixtures, including preservation of two distinct ward IDs in the dedicated configuration.
The DSA model, survival target generation, PMF urgency extension, and previously reported reproduction results remain unchanged. The full upstream CI suite has not yet been confirmed passing after this fix.
Using the Dedicated Configuration
From the repository root, with MIMIC-III data containing both ward ID columns:
The dedicated configuration requires source data containing both ward ID columns. If both ward IDs are unavailable under the default configuration, the task can still process a stay subject to the remaining cohort criteria, but ward ID consistency cannot be verified. If only one ward ID is available, the task excludes the stay. Comparing the first and last ward IDs does not detect every possible intermediate transfer.
Limitations