Repository navigation
Add Deep Cox Mixtures (SurvivalDCM) and a SUPPORT2 time-to-event task - #1611
murphycrosby wants to merge 11 commits into
Conversation
Test CoverageTotal: 86.51% (46982 / 54307 lines)
|
|
/review |
| seed: Random seed. | ||
| """ | ||
| rng = np.random.default_rng(seed) | ||
| config = Path(pyhealth.datasets.__file__).parent / "configs" / "support2.yaml" |
There was a problem hiding this comment.
[medium] Example reads Support2Dataset's YAML config, a link not explained in the description
write_synthetic_support2 reads pyhealth/datasets/configs/support2.yaml to get the column list of the Support2Dataset table. This creates a new link between this example and another component's config file, and the PR description does not mention it. The same link appears in tests/core/test_survival_dcm_support2.py:210. Please either confirm this dependency and say why in the description, or make the example self-contained by hard-coding the columns it writes. The synthetic file only needs the columns the task reads, so either choice is workable.
| # Hazard at the observed time: how fast the baseline curve is falling | ||
| # relative to its height, scaled by the patient's hazard ratio. The | ||
| # small floor keeps the log finite where a curve is flat. | ||
| baseline_hazard = (-baseline_slope / baseline_survival).clamp(min=1e-8) |
There was a problem hiding this comment.
[medium] Event-free subgroup keeps a flat survival-1 baseline and can absorb censored patients
When a subgroup has no observed events in fit_baselines, breslow_baseline_survival returns an empty curve and smooth_baseline_survival returns a flat curve at 1 with slope 0. In the E-step, a censored patient's log-likelihood under that subgroup is then 0, the maximum possible, while event patients get about -18 from the 1e-8 hazard floor. So censored patients are pulled into the event-free subgroup, which then stays event-free, and its flat curve pulls predicted survival upward through the gate weights in _mixture_survival. I reasoned this from the code and did not reproduce it, but no test covers an empty or event-free subgroup, and the ECE numbers in the description are worse for DCM than for the baselines at some horizons. Please handle this case explicitly (for example, exclude subgroups with no events from the posterior or warn when one occurs) and add a test for it.
|
|
||
| # Run the dataset's Dask workers as threads, so loading the CSV starts | ||
| # no child processes. Everything else in the loader runs unchanged. | ||
| def threaded_cluster(**kwargs): |
There was a problem hiding this comment.
[low] Re-implements the threaded Dask loader already in tests/core/survival_test_utils.py
The repo already provides threaded_csv_loading() in tests/core/survival_test_utils.py, and test_gbsg.py and test_survival_pipeline.py use it. This test defines its own threaded_cluster and patches DaskCluster directly. Using the shared context manager would remove the duplicate and match the other survival tests.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution, Murphy. It adds Deep Cox Mixtures (SurvivalDCM) with an EM-style training procedure. It also adds a 9,105-patient, 44-feature SUPPORT2 time-to-event task, a cross-validated example with a K ablation, tests and API docs. The model follows the paper, and the docs openly list where it differs from the authors' code. It looks ready to merge.
Coverage meets the bar. The whole repository is at 86.51%, against the 60% guideline. survival_dcm.py is at 97.81% and survival_dcm_support2.py is at 98.73%, both above the 80% guideline. The tests check hand-computed values for the Cox likelihood, the Breslow baseline and the E-step posterior.
Optional suggestions:
- Empty subgroups: A subgroup that gets no observed events keeps a flat baseline at survival 1 with slope 0. In
subgroup_posterior, a censored patient then gets a log-likelihood of 0 under that subgroup, which is higher than under any subgroup with real events. This can pull censored patients into empty subgroups and bias predictions upward. Consider a short test or a docstring note on this case, or a guard such as skipping or re-seeding empty subgroups. - Support2 config: The example and the task test both read
pyhealth/datasets/configs/support2.yamlto get the column names for synthetic data. Since the description says the task builds onSupport2Dataset, this seems intended. A sentence in the description or a comment saying so would make it explicit. - Test helper: The threaded Dask patch in the task test may duplicate an existing helper in the repository. Reuse it if one exists.
Reviewed commit 51b127b
|
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. This branch also conflicts with master, only in registration lines; please rebase. |
|
We compared the four Deep Cox Mixtures PRs and picked #1641 to merge first. Its model has a self-contained After #1641 merges, please rebase and turn this PR into the following. Add:
Drop:
Thank you, and sorry about the overlap. |
Contributor: Murphy Crosby (mcrosby8), Chidozie Opara (copara8)
Contribution Type: Full Pipeline (model + task subset; uses the existing
Support2Dataset)Paper: Nagpal, Yadlowsky, Rostamzadeh and Heller, Deep Cox Mixtures for Survival Regression, MLHC 2021. https://proceedings.mlr.press/v149/nagpal21a.html
Description: I added Deep Cox Mixtures (DCM) to PyHealth. This is my reproduction of the paper for Georgia Tech CSE 6250.
DCM is a mixture of Cox models. A shared network feeds two heads: a gate that says which hidden subgroup a patient probably belongs to, and an expert that gives a log hazard ratio for each subgroup. Each subgroup gets its own baseline survival curve, so proportional hazards only has to hold inside a subgroup. With one subgroup it's just a single deep Cox model.
What's in the PR:
SurvivalDCM: the network, the Cox partial likelihood, Breslow baselines smoothed with a spline, the E-step with sampled assignments, and survival prediction at any times you pick. Training follows the paper's EM procedure, so you callfit_baselinesbefore training and after every epoch.SurvivalDCMSupport2: SUPPORT2 set up the way the DCM authors did it: all 9,105 patients and 44 features (18 numeric, 6 one-hot categorical), withdurationandeventlabels. This is different from the existingSurvivalTimeToEventSupport2, which uses the DeepSurv benchmark version (8,873 complete cases, 27 features).Results on SUPPORT2 (all patients; 25th / 50th / 75th percentile horizons):
Bootstrap standard errors are about 0.004 to 0.007 for C_td, 0.002 for the Brier score and 0.003 to 0.005 for ECE. They don't include the variation from retraining.
On C_td and the Brier score my baselines match the paper's Table 8 within about 0.003. DCM beats both baselines on discrimination at the 25th and 50th percentile horizons, same as the paper. Calibration is mixed: DCM is at least as good as the baselines at the first two horizons, but not at the 75th. For non-White patients it doesn't have the lowest calibration error, so I couldn't reproduce that claim. In the ablation, every mixture beats K=1 on C_td at the first two horizons (by 0.03 to 0.06 at the 25th percentile and 0.015 to 0.033 at the 50th). The order among K=3, 4 and 6 changed between training runs, so I can't say more than 3 subgroups helps. The full tables, including non-White patients, are in the example script's docstring. Non-White includes the 42 patients with missing race, which gives the paper's 21.02%.
Where I differ from the paper and the authors' code:
Files to Review:
pyhealth/models/survival_dcm.py- the model and its three helper functionspyhealth/tasks/survival_dcm_support2.py- the taskexamples/support2_survival_survival_dcm.py- reproduction and K ablation; runs on synthetic data with no argumentstests/core/test_survival_dcm.py- model tests (36, synthetic tensors, each well under 0.1 s)tests/core/test_survival_dcm_support2.py- task tests (13, synthetic patients)docs/api/models/pyhealth.models.survival_dcm.rstanddocs/api/tasks/pyhealth.tasks.survival_dcm_support2.rst- API pagesdocs/api/models.rst,docs/api/tasks.rst,pyhealth/models/__init__.py,pyhealth/tasks/__init__.py- one added line eachNotes:
auton-survival(auton_survival/models/dcm/) only as a reference.deep_cox_mixtures.pyandsupport2_survival.py. I renamed them so they wouldn't clash with Add Deep Cox Mixtures model and SUPPORT2 censored-survival task #1579 and so they'd match PyHealth'ssurvival_mdn.py.