Skip to content

[BTY-72] TPC Length of Stay Prediction - Model Implementation - CS598DLH Final Project - #1412

Merged
solarsys merged 15 commits into
sunlabuiuc:masterfrom
SubbuM123:finalproject
Nov 29, 2026
Merged

solarsys merged 15 commits into
sunlabuiuc:masterfrom
SubbuM123:finalproject

Conversation

@SubbuM123

@SubbuM123 SubbuM123 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Status — MIMIC-IV 2.2 demo measured; full clinical replication pending

The MIMIC-IV Clinical Database Demo 2.2 baseline and complete three-seed
sweep have RUN locally. Full-dataset eICU/MIMIC-IV experiments and
benchmark-comparable results remain PENDING.

This PR contributes the TPC model, extensions, synthetic tests/feasibility
evidence, a clinical runner, and measured small-demo results. It does not
reproduce the paper's eICU/MIMIC benchmark scores. The already-present public
demo was used locally; datasets, patient records, and checkpoints are excluded.

Contributors

Name NetID Illinois email
Aditya Ramesh ramesh18 ramesh18@illinois.edu
Subbu Muthiah subbum2 subbum2@illinois.edu

Contribution Type: Model (Option 2), UIUC CS 598 DLH.
The supporting adapter reuses existing datasets/extraction; this is not a
claim of full-pipeline extra credit.

Paper: Rocheteau et al., CHIL 2021,
Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the
Intensive Care Unit
.

Implementation

Adds TPC(BaseModel) and TPCLayer, implementing grouped temporal convolutions, pointwise feature mixing, and growing skip connections. Supports optional static, time, and diagnosis inputs, with positive remaining-LoS predictions bounded to 30 minutes–100 days.

Includes five dilation schedules (official, paper, constant, linear, exponential), four loss options (MSLE, MSE, asymmetric MSLE, and Huber log-loss), measurement-decay bases, and optional lab no-forward-fill preprocessing. Log losses operate on log(days); normalized labels are rejected. forward returns standard PyHealth regression outputs at the final time step, while forward_sequence exposes predictions across all time steps.

Adds TPCDayOne, a YAIB-based adapter for eICU and MIMIC-IV. It retains the first 24 hourly bins and predicts remaining ICU days at hour 24. Patient splits precede processor fitting to prevent data leakage. The adapter reuses private YAIB extraction helpers to preserve existing cohort and feature definitions, introducing a dependency on YAIB internals.

The clinical runner supports local datasets only, performs validation-MSLE checkpoint selection, and exports per-seed metrics and aggregate tables. Preparation is the default; training requires explicit --run, a local data root, and a documented dataset version. No datasets are downloaded. The synthetic and clinical runners share their baseline, ablation configurations, and metric definitions.

Reviewer file guide

File Purpose
pyhealth/models/tpc.py Architecture, schedules, losses, preprocessing, typed API examples
pyhealth/models/__init__.py Public TPC / TPCLayer exports
pyhealth/tasks/tpc_day_one.py Day-one continuous-LoS adapter using existing YAIB extraction
pyhealth/tasks/__init__.py Public TPCDayOne export
tests/core/test_tpc.py Synthetic model/gradient/causality, extension, adapter, preparation, and checkpoint tests
examples/synthetic_icu_los_tpc.py Existing measured synthetic sweep and clearly synthetic findings
examples/eicu_los_tpc.py No-data preparation and local clinical/demo runner
examples/tpc/README.md Full 45-row measured demo table, protocol, analysis, and pending full-data work
docs/api/models/pyhealth.models.tpc.rst and docs/api/models.rst Indexed model API docs
docs/api/tasks/pyhealth.tasks.tpc_day_one.rst and docs/api/tasks.rst Indexed adapter API docs

Measured MIMIC-IV demo results — not full clinical reproduction

Configuration MAD (days) MAPE (%) MSLE R2 Bias (days) Long-stay MAD
Baseline TPC 2.418 +/- 0.440 152.585 +/- 45.901 1.982 +/- 0.076 -0.309 +/- 0.145 -1.918 +/- 0.655 8.565 +/- 1.620
Constant dilation 2.420 +/- 0.475 152.774 +/- 40.920 1.944 +/- 0.173 -0.286 +/- 0.138 -1.814 +/- 0.685 8.482 +/- 1.712
Linear/paper dilation 2.414 +/- 0.475 149.732 +/- 32.894 1.964 +/- 0.182 -0.298 +/- 0.163 -1.917 +/- 0.654 8.512 +/- 1.712
Exponential dilation 2.428 +/- 0.470 151.983 +/- 38.404 2.009 +/- 0.163 -0.315 +/- 0.163 -1.939 +/- 0.651 8.579 +/- 1.663
Asymmetric MSLE 2.429 +/- 0.426 159.959 +/- 51.447 2.003 +/- 0.078 -0.303 +/- 0.167 -1.880 +/- 0.683 8.515 +/- 1.653
Huber log-loss 2.421 +/- 0.432 157.031 +/- 50.108 1.994 +/- 0.061 -0.306 +/- 0.153 -1.890 +/- 0.671 8.556 +/- 1.626
Decay base 0.5 2.433 +/- 0.447 150.689 +/- 45.305 1.995 +/- 0.091 -0.315 +/- 0.146 -1.948 +/- 0.669 8.585 +/- 1.627
Decay base 0.9 2.416 +/- 0.481 148.019 +/- 31.425 1.930 +/- 0.248 -0.282 +/- 0.209 -1.910 +/- 0.689 8.436 +/- 1.806
Lab no-forward-fill 2.455 +/- 0.464 142.007 +/- 23.042 1.982 +/- 0.264 -0.320 +/- 0.181 -1.995 +/- 0.627 8.529 +/- 1.648
MSE — Sanity Check 2.433 +/- 0.424 167.999 +/- 66.739 2.145 +/- 0.258 -0.272 +/- 0.156 -1.848 +/- 0.743 8.420 +/- 1.552

Demo source: 100 patients /
140 source ICU stays; the day-one YAIB-based cohort retains 88 patients /
117 stays. Values are mean +/- sample standard deviation over seeds 0/1/2.
Patient counts per seed: train/validation/test = 61/13/14; stay counts =
85/14/18, 80/17/20, and 75/21/21. Baseline selected epochs = 3/4/3.
Long-stay test counts = 3/3/4. The complete 135-training sweep took 149.51
seconds on an Apple M4 Pro with one PyTorch CPU thread, using warm caches.
The seven source files matched the supplied SHA256 checksums. A separate
three-seed baseline exactly reproduced the sweep baseline.

Negative R2 and negative bias show poor squared-error performance and
underprediction, particularly on long stays. The small loss/decay differences
are not compelling relative to seed variation. Asymmetric MSLE's synthetic
benefit did not clearly transfer. Temporal width 13 had the lowest observed
mean MSLE (1.834 +/- 0.434), but this is descriptive, not independently
validated selection across 45 test-evaluated rows. All rows have negative mean
R2. Different seeds also change patient partitions; subgroup counts are tiny.
No hyperparameters were retuned after inspecting test performance.

In every row, long-stay bias equals the negative of long-stay MAD, so every test stay of 5 days or more was underpredicted in every seed. With only 3/3/4 such stays per seed, this shows a consistent direction of error, not a precise estimate of its size.

Full-dataset cohorts, experiments, benchmark-comparable scores, and comparison
with published paper performance remain PENDING. Different feature/cohort and
day-one training definitions prevent a like-for-like benchmark comparison.

Executed demo protocol

The demo sweep contains 45 matched one-factor labels and three seeds
(paper/linear are identical aliases). Sweeps cover layers 1/3/5/9, kernels 2–5, each integer temporal
and pointwise channel count 4–16, dropout 0/0.2/0.45, and learning rates
0.001/0.0023/0.01. Baseline values cover unchanged settings. Extensions cover
alternative dilation, asymmetric/Huber losses, decay 0.5/0.75/0.9, and lab
no-forward-fill. Report MAD, MAPE, MSLE, R2, bias, >=5-day long-stay MAD/bias,
and subgroup counts as three-seed mean +/- sample standard deviation.

The compute-constrained baseline is N=3, k=4, Y=Z=4, main dropout=0.2,
temporal dropout=0.05, official dilation, MSLE, Adam learning rate 0.0023,
batch size 32, and eight epochs. Use 70/15/15 patient splits independently
for seeds 0/1/2, sharing each seed's partition across all configurations.
Select on validation MSLE and evaluate the selected checkpoint once on test.

Linear is identical to the paper schedule, not a separate novelty.
MSE vs. MSLE is explicitly a Sanity Check. Dataset-size comparisons in
the synthetic example are a Compute-Constraint Demonstration, not novel
credit. Hyperparameter sweeps are sensitivity analyses.

Existing synthetic evidence (not clinical reproduction)

The synthetic example already embeds its measured 47-configuration,
three-seed feasibility sweep. These numbers remain clearly labelled synthetic
and are not substituted into clinical placeholders or compared numerically
with another team's clinical scores. The demo findings above are separate
from synthetic evidence; full-cohort clinical extension findings remain PENDING.

Usage

Preparation without dataset access or training:

python -m examples.eicu_los_tpc --prepare-only --all-configs \
  --output-dir output/tpc_clinical_plan

Future training, only after authorized eICU data are available locally:

python -m examples.eicu_los_tpc --run --dataset eicu \
  --root /AUTHORIZED/PATH/eicu-crd/2.0 --data-version 2.0 \
  --configs baseline --seeds 0 1 2 --epochs 8 --batch-size 32 \
  --output-dir output/tpc_eicu_baseline

Use --dataset mimic4 with the actual MIMIC-IV release/root as appropriate.
See the README for full-sweep execution and dataset-file requirements.
Each output directory must be new. No patient IDs or predictions are written
into the aggregate result tables; data/caches/checkpoints stay local and ignored.

Validation and Limitations

-46 focused tests/doctests pass, with 17 subtests. Tests use synthetic fixtures.
-The MIMIC-IV 2.2 demo ran end to end. Full MIMIC-IV and eICU execution remain unverified.
-The YAIB cohort differs from the original TPC paper's cohort. This implementation trains at day one rather than every hour and uses 48 dynamic and four static features, without diagnosis or additional time inputs.
-Standard BatchNorm uses running statistics during inference rather than the original implementation's batch-statistics inference. Causality is enforced during evaluation.
-No mortality head, multitask objective, or variable-length masked loss is implemented.
-Full-dataset clinical experiments and comparisons against published TPC results remain pending.

@SubbuM123 SubbuM123 changed the title initial commit, added to init TPC Length of Stay Prediction - Model Implementation - CS598DLH Final Project Nov 8, 2026
@adityaramesh15

Copy link
Copy Markdown
Contributor

Status — MIMIC-IV 2.2 demo measured; full clinical replication pending

The MIMIC-IV Clinical Database Demo 2.2 baseline and complete three-seed
sweep have RUN locally. Full-dataset eICU/MIMIC-IV experiments and
benchmark-comparable results remain PENDING.

This PR contributes the TPC model, extensions, synthetic tests/feasibility
evidence, a clinical runner, and measured small-demo results. It does not
reproduce the paper's eICU/MIMIC benchmark scores. The already-present public
demo was used locally; datasets, patient records, and checkpoints are excluded.

Contributors

Name NetID Illinois email
Aditya Ramesh ramesh18 ramesh18@illinois.edu
Subbu Muthiah subbum2 subbum2@illinois.edu

Contribution Type: Model (Option 2), UIUC CS 598 DLH.
The supporting adapter reuses existing datasets/extraction; this is not a
claim of full-pipeline extra credit.

Paper: Rocheteau et al., CHIL 2021,
Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the
Intensive Care Unit
.

Implementation

Adds TPC(BaseModel) and TPCLayer: per-feature grouped temporal convolutions
and pointwise feature mixing with growing skip connections, optional static,
time, and diagnosis inputs, and positive remaining-LoS predictions bounded to
30 minutes–100 days. forward supplies PyHealth regression outputs/loss at the
last time step; forward_sequence exposes predictions at all time steps.

Supports official, paper, constant, linear, and exponential dilation;
MSLE, MSE, asymmetric MSLE, and Huber log-loss; measurement-decay bases; and
optional lab no-forward-fill using original observation masks. Log losses use
log(days), not log1p; normalized labels are rejected.

Adds TPCDayOne using existing YAIB extraction for supported eICU/MIMIC-IV
datasets. It retains the first 24 hourly bins and predicts continuous remaining
days at hour 24. Patient splits precede processor fitting, preserving
training-only normalization and raw measurement masks. The clinical runner
checks required local source/join files, selects checkpoints using validation
MSLE, and exports per-seed metrics plus mean/std tables. Default execution only
prepares a plan and PENDING rows; training requires explicit --run, a local
data root, and a documented data version. It never downloads datasets.

Reviewer file guide

File Purpose
pyhealth/models/tpc.py Architecture, schedules, losses, preprocessing, typed API examples
pyhealth/models/__init__.py Public TPC / TPCLayer exports
pyhealth/tasks/tpc_day_one.py Day-one continuous-LoS adapter using existing YAIB extraction
pyhealth/tasks/__init__.py Public TPCDayOne export
tests/core/test_tpc.py Synthetic model/gradient/causality, extension, adapter, preparation, and checkpoint tests
examples/synthetic_icu_los_tpc.py Existing measured synthetic sweep and clearly synthetic findings
examples/eicu_los_tpc.py No-data preparation and local clinical/demo runner
examples/tpc/README.md Full 45-row measured demo table, protocol, analysis, and pending full-data work
docs/api/models/pyhealth.models.tpc.rst and docs/api/models.rst Indexed model API docs
docs/api/tasks/pyhealth.tasks.tpc_day_one.rst and docs/api/tasks.rst Indexed adapter API docs

Measured MIMIC-IV demo results — not full clinical reproduction

Configuration MAD (days) MAPE (%) MSLE R2 Bias (days) Long-stay MAD
Baseline TPC 2.418 +/- 0.440 152.585 +/- 45.901 1.982 +/- 0.076 -0.309 +/- 0.145 -1.918 +/- 0.655 8.565 +/- 1.620
Constant dilation 2.420 +/- 0.475 152.774 +/- 40.920 1.944 +/- 0.173 -0.286 +/- 0.138 -1.814 +/- 0.685 8.482 +/- 1.712
Linear/paper dilation 2.414 +/- 0.475 149.732 +/- 32.894 1.964 +/- 0.182 -0.298 +/- 0.163 -1.917 +/- 0.654 8.512 +/- 1.712
Exponential dilation 2.428 +/- 0.470 151.983 +/- 38.404 2.009 +/- 0.163 -0.315 +/- 0.163 -1.939 +/- 0.651 8.579 +/- 1.663
Asymmetric MSLE 2.429 +/- 0.426 159.959 +/- 51.447 2.003 +/- 0.078 -0.303 +/- 0.167 -1.880 +/- 0.683 8.515 +/- 1.653
Huber log-loss 2.421 +/- 0.432 157.031 +/- 50.108 1.994 +/- 0.061 -0.306 +/- 0.153 -1.890 +/- 0.671 8.556 +/- 1.626
Decay base 0.5 2.433 +/- 0.447 150.689 +/- 45.305 1.995 +/- 0.091 -0.315 +/- 0.146 -1.948 +/- 0.669 8.585 +/- 1.627
Decay base 0.9 2.416 +/- 0.481 148.019 +/- 31.425 1.930 +/- 0.248 -0.282 +/- 0.209 -1.910 +/- 0.689 8.436 +/- 1.806
Lab no-forward-fill 2.455 +/- 0.464 142.007 +/- 23.042 1.982 +/- 0.264 -0.320 +/- 0.181 -1.995 +/- 0.627 8.529 +/- 1.648
MSE — Sanity Check 2.433 +/- 0.424 167.999 +/- 66.739 2.145 +/- 0.258 -0.272 +/- 0.156 -1.848 +/- 0.743 8.420 +/- 1.552

Demo source: 100 patients /
140 source ICU stays; the day-one YAIB-based cohort retains 88 patients /
117 stays. Values are mean +/- sample standard deviation over seeds 0/1/2.
Patient counts per seed: train/validation/test = 61/13/14; stay counts =
85/14/18, 80/17/20, and 75/21/21. Baseline selected epochs = 3/4/3.
Long-stay test counts = 3/3/4. The complete 135-training sweep took 149.51
seconds on an Apple M4 Pro with one PyTorch CPU thread, using warm caches.
The seven source files matched the supplied SHA256 checksums. A separate
three-seed baseline exactly reproduced the sweep baseline.

Negative R2 and negative bias show poor squared-error performance and
underprediction, particularly on long stays. The small loss/decay differences
are not compelling relative to seed variation. Asymmetric MSLE's synthetic
benefit did not clearly transfer. Temporal width 13 had the lowest observed
mean MSLE (1.834 +/- 0.434), but this is descriptive, not independently
validated selection across 45 test-evaluated rows. All rows have negative mean
R2. Different seeds also change patient partitions; subgroup counts are tiny.
No hyperparameters were retuned after inspecting test performance.

Full-dataset cohorts, experiments, benchmark-comparable scores, and comparison
with published paper performance remain PENDING. Different feature/cohort and
day-one training definitions prevent a like-for-like benchmark comparison.

Executed demo protocol

The demo sweep contains 45 matched one-factor labels and three seeds
(paper/linear are identical aliases). Sweeps cover layers 1/3/5/9, kernels 2–5, each integer temporal
and pointwise channel count 4–16, dropout 0/0.2/0.45, and learning rates
0.001/0.0023/0.01. Baseline values cover unchanged settings. Extensions cover
alternative dilation, asymmetric/Huber losses, decay 0.5/0.75/0.9, and lab
no-forward-fill. Report MAD, MAPE, MSLE, R2, bias, >=5-day long-stay MAD/bias,
and subgroup counts as three-seed mean +/- sample standard deviation.

The compute-constrained baseline is N=3, k=4, Y=Z=4, main dropout=0.2,
temporal dropout=0.05, official dilation, MSLE, Adam learning rate 0.0023,
batch size 32, and eight epochs. Use 70/15/15 patient splits independently
for seeds 0/1/2, sharing each seed's partition across all configurations.
Select on validation MSLE and evaluate the selected checkpoint once on test.

Linear is identical to the paper schedule, not a separate novelty.
MSE vs. MSLE is explicitly a Sanity Check. Dataset-size comparisons in
the synthetic example are a Compute-Constraint Demonstration, not novel
credit. Hyperparameter sweeps are sensitivity analyses.

Existing synthetic evidence (not clinical reproduction)

The synthetic example already embeds its measured 47-configuration,
three-seed feasibility sweep. These numbers remain clearly labelled synthetic
and are not substituted into clinical placeholders or compared numerically
with another team's clinical scores. The demo findings above are separate
from synthetic evidence; full-cohort clinical extension findings remain PENDING.

Usage

Preparation without dataset access or training:

python -m examples.eicu_los_tpc --prepare-only --all-configs \
  --output-dir output/tpc_clinical_plan

Future training, only after authorized eICU data are available locally:

python -m examples.eicu_los_tpc --run --dataset eicu \
  --root /AUTHORIZED/PATH/eicu-crd/2.0 --data-version 2.0 \
  --configs baseline --seeds 0 1 2 --epochs 8 --batch-size 32 \
  --output-dir output/tpc_eicu_baseline

Use --dataset mimic4 with the actual MIMIC-IV release/root as appropriate.
See the README for full-sweep execution and dataset-file requirements.
Each output directory must be new. No patient IDs or predictions are written
into the aggregate result tables; data/caches/checkpoints stay local and ignored.

Validation and limitations

  • 46 focused tests/doctests pass, plus 17 subtests, using synthetic data only.
    The slowest test call takes about 0.05 seconds; a fresh pytest process takes
    about 4.4 seconds including PyHealth imports. The literal total-runtime-under-
    one-second target is therefore not met on this environment.
  • Black (-l 88), Ruff, PR contribution rules, and focused model/task Sphinx
    documentation pass. Full-repository documentation has previously observed
    unrelated warnings; no claim is made of a clean full-repository docs build.
  • The MIMIC-IV 2.2 demo has run end to end. eICU and full MIMIC-IV execution
    remain unverified. Unit tests still use synthetic fixtures, never demo data.
  • YAIB cohort exclusions differ from the original TPC cohort and use
    retrospective observation-gap filtering. This adapter trains only at day one,
    not at every hour. Its 48 dynamic/four static features are not the paper's
    original feature set; the runner supplies no diagnosis or extra time inputs.
    Lab-only ablation features exclude mixed-source features.
  • Standard BatchNorm uses running statistics at inference rather than the
    official implementation's batch-statistics inference. Training BatchNorm
    pools over time; strict causality applies in evaluation. No mortality head,
    multitask objective, or variable-length masked loss is claimed.
  • Official-model numerical parity has not been run. The official repository is
    MIT-licensed; any future adapted source must retain its license notices.
  • Rebased onto upstream/master, the actual upstream default and current PR
    base; upstream has no main. Maintainer edits remain enabled.

Remaining work

  • Obtain authorized full-dataset clinical access and prepare local files.
  • Run full-dataset baseline and ablations; retain the demo findings separately.
  • Add full-cohort results and discuss findings against the paper, documenting
    cohort/configuration differences.
  • Complete Gradescope, the final AI-usage Google Form, and the 4–7 minute
    presentation separately; these non-code submissions are not verified here.

@Logiquo Logiquo changed the title TPC Length of Stay Prediction - Model Implementation - CS598DLH Final Project [BTY-72] TPC Length of Stay Prediction - Model Implementation - CS598DLH Final Project Nov 15, 2026
@github-actions github-actions Bot mentioned this pull request Nov 15, 2026
@solarsys solarsys added the status: manual Pending maintainer's review label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 87.60% (53249 / 60788 lines)

Modified file Coverage Lines
pyhealth/metrics/fairness_utils/__init__.py 100.00% 3 / 3
pyhealth/metrics/fairness_utils/capacity.py 100.00% 59 / 59
pyhealth/models/__init__.py 100.00% 108 / 108
pyhealth/models/tpc.py 99.56% 227 / 228
pyhealth/tasks/__init__.py 98.37% 121 / 123
pyhealth/tasks/clinical_presence_mortality_mimic3.py 98.84% 256 / 259
pyhealth/tasks/tpc_day_one.py 95.24% 40 / 42

Workflow run · 00cfc60

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@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.

Previous review

Reviewed commit fe2213b

@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.

Previous review

AI Review

suggestion: need change
decision: human review

Thank you for this contribution. It adds a TPC model (with TPCLayer), a day-one continuous length-of-stay task (TPCDayOne), a clinical runner, synthetic and MIMIC-IV demo experiments, and docs. The tests are thorough, and coverage meets the bar: 86.13% for the whole repository, 99.56% for tpc.py and 95.24% for tpc_day_one.py. The work is close to ready.

To get this merged:

  1. The sharing between examples/eicu_los_tpc.py and examples/synthetic_icu_los_tpc.py isn't explained. The clinical runner imports BASE, METRICS, ablation_configs and los_metrics from the synthetic example. Please say in the description why it reuses them (for example, to keep the protocol and metrics identical). Or make the runner self-contained by copying them in. Either is fine.
  2. The docs for pyhealth/models/tpc.py don't match the code. The value_key docstring says the input is forward-filled. When observed_key is set, which is how TPCDayOne and the runner use it, the input is raw and may contain NaNs, and the model fills it itself. Please update the docstring to describe both cases.

Optional suggestions:

  • TPCDayOne calls underscore-prefixed YAIB internals (_stays, _base_cohort, _dynamic, _features_read, _DYNAMIC_FEATURES). The description should name this link and give a reason, as in item 1.
  • With kernel_size=1, the official dilation schedule gives dilation 0 for layers after the first. Consider validating this case or documenting it.
  • The toctree in tasks.rst sits apart from the existing task index. You could place it more consistently.
  • The task API page carries demo-status text that will go stale. You could point to the README instead.

Reviewed commit fe2213b

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@adityaramesh15

Copy link
Copy Markdown
Contributor

Completed both requested documentation fixes in e1f53d5.

The clinical runner intentionally reuses BASE, METRICS, ablation_configs, and los_metrics from the synthetic example to keep baseline settings, one-factor ablations, and metric definitions identical across runners. Clinical runs exclude synthetic dataset-size experiments; importing the helpers does not generate data or run experiments. This rationale is now in the runner module description and examples/tpc/README.md.

The TPC value_key documentation now distinguishes finite, pre-filled input without observed_key from raw input with observed_key, where unobserved values may be NaN and the model fills them internally. The decay_key documentation also clarifies when decay is recomputed.

Committed and pushed as Aditya Ramesh adityaramesh15@gmail.com. The current account cannot edit this PR description, so the explanation is recorded here and in the committed documentation.

adityaramesh15 and others added 2 commits November 24, 2026 21:41
Reject kernel_size < 2 for the official multi-layer dilation schedule,
move the TPC task into the existing tasks toctree, and keep run status
out of the task API page.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@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.

Previous review

Reviewed commit b0d2360

@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.

Previous review

AI Review

suggestion: need change
decision: human review

Thank you for this contribution. It adds a TPC model for ICU length-of-stay prediction, a day-one TPCDayOne task built on the existing YAIB extraction, a synthetic sweep, a clinical runner, tests, docs and measured MIMIC-IV demo results. It is thorough and close to ready. Coverage is well above the bar: 86.4% for the repository, 99.6% for tpc.py and 95.2% for tpc_day_one.py.

To get this merged:

  1. Name the link between components in the PR description. examples/eicu_los_tpc.py imports BASE, METRICS, ablation_configs and los_metrics from examples/synthetic_icu_los_tpc.py. The module docstring and the README explain this, but the PR description does not. Please either confirm in the description that the sharing is intended and say why, or make the clinical runner self-contained by copying those helpers.
  2. Name the other new link too. TPCDayOne calls the private YAIB helpers _stays, _base_cohort, _dynamic and _DYNAMIC_FEATURES, and instantiates the YAIB task classes. The description mentions reusing the YAIB extraction, but please state explicitly that it depends on these private helpers and why. Alternatively, keep the task self-contained.

Optional suggestions:

  • In the demo table, LongBias equals -LongMAD in every row. That means every stay of 5 days or more is underpredicted in every run. A sentence on this in the findings would help readers.
  • The README is long. The 45-row table could be trimmed to the key rows, with the full table linked or placed in a separate file.
  • The tests mock the real set_task split path. A tiny synthetic test of that path would add confidence.

Reviewed commit b0d2360

@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: three open PRs add a TPC model, #1412, #1428 and #1574 (#1412 and #1428 both claim BTY-72). #1428 and #1627 both add an eICU length-of-stay task. A maintainer has to pick one model and one eICU task.

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.

Separately, the AI review's open point is to name, in the description, why examples/eicu_los_tpc.py imports from examples/synthetic_icu_los_tpc.py. The branch also conflicts with master (only docs/api/models.rst).

@solarsys

Copy link
Copy Markdown
Collaborator

Picked as PyHealth's TPC model. We compared the three TPC models (#1412, #1428, #1574) and the two eICU tasks (#1428, #1627). Yours fits PyHealth best and keeps the paper's layer:

  • per-feature grouped causal dilated convolutions;
  • pointwise convolutions;
  • concatenated skip connections;
  • decay channels, BatchNorm and the diagnosis encoder.

Sizes come from the processors, it runs with the standard Trainer, and coverage is 99.6%. It was also opened first, so it's the primary BTY-72 claimant.

Before it can merge:

  1. Rebase on master. Only docs/api/models.rst conflicts.
  2. Add the official TPC repository's MIT copyright notice, since the layer mirrors its structure.
  3. Optional: trim the README.

Next, for fidelity: forward scores only the last hour, so the Trainer never trains the paper's hourly MSLE objective. We've asked #1574 to contribute a per-hour mode with a masked loss on top of your model, using the #1627 hourly eICU task.

Once these fixes are pushed, we'll move this PR to status: automatic and request an AI review. If the review approves, it merges.

Added copyright and licensing information for TPCLayer.
@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.

Previous review

Reviewed commit e2d333c

@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.

Previous review

AI Review

suggestion: need change
decision: human review

Thank you for the TPC contribution. It adds a TPC model with TPCLayer, a TPCDayOne task built on the YAIB extraction, synthetic and clinical runners, docs, and measured MIMIC-IV demo results. The work is thorough and close to ready. Coverage is well above the bar: tpc.py is at 99.6%, tpc_day_one.py at 95.2%, and the whole repository at 87.6%.

To get this merged:

  1. In pyhealth/models/tpc.py, the diagnosis encoder uses nn.BatchNorm1d. A training batch with a single stay then raises an error whenever diag_key is used. The default DataLoader can produce such a batch as the last, smaller batch. Please make the encoder safe for batch size 1. For example, use LayerNorm or drop that normalization. Alternatively, document the restriction clearly, validate it, and add a test with diag_key and a one-sample batch.

Optional suggestions:

  • The clinical runner marks a run FAILED only for ValueError, RuntimeError or OSError. A broader except Exception would record other failures as well.
  • Add a direct test of the set_task and PatientSplit path of TPCDayOne.
  • tests/core/test_tpc.py imports fixtures from the YAIB test files. Copying the few helpers would keep the tests self-contained.
  • The description explains the reuse of YAIB private helpers and of the synthetic example's helpers, which is good.

Reviewed commit e2d333c

@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 00cfc60

stays = source._stays(patient)
if stays.height == 0:
return []
stays, hourly, static = source._base_cohort(patient, stays)

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] Day-one cohort eligibility uses data after hour 24

The call to source._base_cohort applies YAIB's exclusions over the whole stay. The observation-count rule counts bins outside the first 24 hours, and the gap rule is measured over the stay's first 7 days. A stay's inclusion therefore depends on measurements taken after the prediction time, which a deployed day-one model would not have. The docstring and README disclose this as retrospective. Consider stating in the TPCDayOne docstring that reported metrics are on a cohort selected with future data, or restricting the exclusions to hours 0-23 for a true day-one cohort.

@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: approve
decision: human review

Thank you for contributing TPC. It adds the TPC model, a day-one length-of-stay task for eICU and MIMIC-IV, a synthetic ablation example, a local-data clinical runner, API docs, and measured MIMIC-IV demo results. It looks ready to merge.

Why it looks ready

  • The model, losses, dilation schedules, decay and no-forward-fill preprocessing, and the adapter's day-one window and label logic match the description and docs. The limitations (running-statistics BatchNorm, YAIB cohort differences, no mortality head) are stated clearly.
  • Coverage meets the bar. The whole repository is at 87.6%, pyhealth/models/tpc.py is at 99.6%, and pyhealth/tasks/tpc_day_one.py is at 95.2%.
  • The links between components are named in the description with reasons. TPCDayOne reuses YAIB's private extraction helpers to keep the existing cohort and feature definitions. The clinical runner imports BASE, METRICS, ablation_configs and los_metrics from the synthetic example to keep baselines and metrics identical.
  • The new components are only registered through exports in the package __init__.py files. No existing export is removed, renamed or rebound.

Optional suggestions

  • tests/core/test_tpc.py imports private helpers (_lab, _patient, T0, _admission) from the YAIB test modules. A short note in the description would make that link explicit. Copying the small fixtures would also keep the tests self-contained.
  • tpc_day_one.py depends on YAIB internals (_features_read, _stays, _base_cohort, _dynamic, _DYNAMIC_FEATURES). A short comment there, or a test that fails clearly if those helpers change, would make future breakage easier to diagnose.
  • The README and the example docstring each hold the full 45-row table. Keeping the table in one place and linking to it from the other would shorten the docs.
  • The blank line you added in pyhealth/tasks/__init__.py after the TPCDayOne import is unnecessary.

Reviewed commit 00cfc60

@solarsys solarsys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving as PyHealth's TPC model. Thanks for fixing the batch-of-one case. Next, for fidelity, is the per-hour training mode #1574 was asked to contribute on top.

@solarsys
solarsys merged commit 5290878 into sunlabuiuc:master Nov 29, 2026
2 checks passed
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.

3 participants