Skip to content

Add Deep Cox Mixtures model for survival analysis - #1629

Open
doziej84 wants to merge 3 commits into
sunlabuiuc:masterfrom
doziej84:deep-cox-mixtures
Open

doziej84 wants to merge 3 commits into
sunlabuiuc:masterfrom
doziej84:deep-cox-mixtures

Conversation

@doziej84

@doziej84 doziej84 commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

This PR introduces Deep Cox Mixtures (DCM), a deep learning survival regression model that captures heterogeneous patient populations through a mixture of component-specific Cox proportional hazards models.

The implementation is based on:

Nagpal et al. (2021), Deep Cox Mixtures for Survival Regression.
https://proceedings.mlr.press/v149/nagpal21a.html

Implementation

  • Shared neural network feature encoder.

  • Probabilistic mixture gating network.

  • Component-specific log hazard ratios.

  • Cox partial likelihood with Breslow handling of tied event times.

  • Breslow baseline cumulative hazard estimation.

  • Shape-preserving cubic interpolation (PCHIP).

  • Approximate expectation-maximization training.

  • Patient-specific survival probability prediction.

  • Checkpoint persistence for neural parameters and baseline hazard functions.

Files Added or Modified

File | Description -- | -- pyhealth/models/deep_cox_mixtures.py | Core model implementation pyhealth/models/__init__.py | Model registration tests/core/test_deep_cox_mixtures.py | Unit tests examples/deep_cox_mixtures_example.py | Runnable synthetic example examples/support2_survival_deep_cox_mixtures.py | SUPPORT2 experiments examples/deep_cox_mixtures_uncertainty.py | Fold-based uncertainty analysis examples/deep_cox_mixtures_results.md | Experimental results and ablation study docs/api/models/pyhealth.models.deep_cox_mixtures.rst | API documentation docs/api/models.rst | Documentation index

The three-component configuration achieved the strongest observed balance between discrimination and probabilistic accuracy. Increasing the number of mixture components beyond three did not consistently improve performance.

Detailed experimental results, demographic subgroup analysis, uncertainty estimates and reproduction instructions are provided in examples/deep_cox_mixtures_results.md.

Testing

All 20 DCM unit tests passed locally.

python -m pytest tests/core/test_deep_cox_mixtures.py -v

Tests cover mathematical correctness, tied event times, censoring, mixture probabilities, gradient computation, EM training, survival prediction, input validation and checkpoint persistence.

The synthetic demonstration can be executed without downloading SUPPORT2:

python examples/deep_cox_mixtures_example.py

Documentation and Formatting

  • API documentation added and registered.

  • Sphinx HTML documentation built successfully with warnings.

  • Python files formatted using Black and isort.

Limitations

  • DCM uses its dedicated fit_em() training method rather than the standard PyHealth Trainer.

  • PCHIP interpolation differs from the original paper's spline smoothing procedure.

  • The experimental calibration estimator differs from the published estimator.

  • Uncertainty estimates are descriptive fold-based standard errors rather than patient-level bootstrap standard errors.

  • The experiments reproduce several qualitative performance trends but do not establish exact numerical reproduction.

Contribution Checklist

  • Core model implementation

  • Model registration

  • Unit tests

  • Runnable synthetic example

  • Experimental evaluation

  • Ablation study

  • API documentation

  • Code formatting

  • Local regression tests

Course Information

  • Course: Georgia Tech CSE6250 — Big Data for Healthcare

  • Project: Deep Cox Mixtures for Survival Regression

  • Georgia Tech username: copara8 and mcrosby8

  • Georgia Tech email: copara8@gatech.edu & mcrosby8@gatech.edu

  • GitHub username: doziej84

  • Contribution type: Model implementation

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 86.81% (49198 / 56672 lines)

Modified file Coverage Lines
pyhealth/models/__init__.py 100.00% 98 / 98
pyhealth/models/deep_cox_mixtures.py 88.48% 238 / 269
pyhealth/models/query_focused_ehr.py 90.64% 155 / 171
pyhealth/tasks/__init__.py 98.21% 110 / 112
pyhealth/tasks/chapman_heartlang.py 96.23% 102 / 106
pyhealth/tasks/physionet2012_inhospital_mortality.py 94.52% 138 / 146
pyhealth/tasks/query_focused_ehr.py 91.88% 147 / 160
pyhealth/tasks/temple_university_EEG_tasks.py 83.24% 154 / 185

Workflow run · 7fbe77d

@solarsys solarsys added the status: manual Pending maintainer's review label Nov 27, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 7fbe77d

from sksurv.nonparametric import CensoringDistributionEstimator
from sksurv.util import Surv

from pyhealth.datasets import Support2Dataset

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] SUPPORT2 example reuses Support2Dataset without the description naming it

The example imports and uses the existing PyHealth Support2Dataset (line 25, used at line 37). This creates a link to another concrete dataset component. The PR description does not mention this reuse; only the markdown results file does, and a markdown file does not count as the description. Either confirm the sharing in the PR description and say why (for example, to reproduce the benchmark with the standard SUPPORT2 loader), or keep the example self-contained by loading the CSV directly and deriving the features and outcomes in the script. Both options are acceptable.


from pyhealth.datasets import Support2Dataset
from pyhealth.models import DeepCoxMixtures
from pyhealth.tasks import SurvivalTimeToEventSupport2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] SUPPORT2 example reuses SurvivalTimeToEventSupport2 task without the description naming it

The example imports the existing SurvivalTimeToEventSupport2 task (line 27, used at line 42) and depends on its output keys (features, duration, event, patient_id). This is a link to another concrete task component that the PR description does not name. Either confirm the sharing in the PR description and explain why the existing task is used, or keep the example self-contained by building its own cohort from the CSV. Both options are acceptable.


return {
"logit": log_risk,
"y_prob": mixture_probs,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] y_prob holds latent subgroup membership, not survival probability

forward() returns the mixture membership probabilities under y_prob. In PyHealth, y_prob is the model's prediction, so generic code (Trainer metrics, interpretability) will read membership probabilities as survival outputs. The docs state this, so it is non-blocking. Consider a separate key name or a note in the class docstring. The model also returns no loss key, so it cannot use the standard Trainer; this too is documented.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: need change
decision: human review

Thank you for contributing Deep Cox Mixtures. It adds a mixture-of-Cox survival model with Breslow baselines, a dedicated EM training method, tests, documentation, and a SUPPORT2 reproduction and ablation. The model is self-contained and the tests are thorough. Coverage meets the bar: deep_cox_mixtures.py is at 88.5% and the whole repository is at 86.8%.

To get this merged:

  • examples/support2_survival_deep_cox_mixtures.py builds on the existing Support2Dataset and SurvivalTimeToEventSupport2 task. Your PR description doesn't mention this. Please either add a sentence to the description confirming the reuse is intended and saying why (for example, to reproduce the paper's experiments on PyHealth's own SUPPORT2 pipeline), or make the example self-contained.

Optional suggestions:

  • Section 6.4 of deep_cox_mixtures_results.md gives White ECE values (0.0241, 0.0266, 0.0266) that appear in none of the tables above it. Consider adding a White-population table or noting where those numbers come from.
  • The examples need scikit-survival and matplotlib. You already say to install them in the reproduction instructions. Adding the same note at the top of the example docstrings would help.
  • Consider adding tests for the other input checks in fit_em, such as non-positive durations, non-finite features and a mismatched feature count. Only invalid events and invalid component counts are tested now.
  • The docstring Examples blocks in cox_partial_loss, DeepCoxMixtures and BreslowBaseline are indented oddly, so they may render badly in Sphinx. BreslowBaseline also has a stray whitespace line after its docstring.
  • Your description says the Sphinx build succeeded "with warnings". Check whether any come from these docstrings.

Reviewed commit 7fbe77d

@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: four open PRs add a Deep Cox Mixtures model for SUPPORT2: #1579, #1611, #1629 and #1641. PyHealth keeps one implementation per component, so a maintainer has to pick one.

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 (registration lines only). The AI review's 'To get this merged' points are still open.

@solarsys

Copy link
Copy Markdown
Collaborator

We compared the four Deep Cox Mixtures PRs and picked #1641 to merge first. This PR had four main gaps:

  • It has no task of its own. The example uses master's 27-feature DeepSurv task, not the paper's 44-feature protocol.
  • forward returns no loss or y_true.
  • forward puts the mixture probabilities in y_prob.
  • fit_em takes one full-batch step per epoch.

After #1641 merges, please contribute:

Drop: the duplicate model, the synthetic matplotlib example, and most of the results file.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants