Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b3f334e
Add files via upload
ahling21 Nov 15, 2026
b6d2e6a
Update tpc_eicu.py
ahling21 Nov 20, 2026
5ed55a7
Update test_tpc_real.py
ahling21 Nov 20, 2026
9392038
Update test_hourly.py
ahling21 Nov 20, 2026
e831314
Update tpc_eicu.py
ahling21 Nov 20, 2026
b121553
Update test_tpc_real.py
ahling21 Nov 20, 2026
276cc88
Update test_hourly.py
ahling21 Nov 20, 2026
319267e
Update tpc_eicu.py
ahling21 Nov 22, 2026
93c7e86
Update test_tpc_real.py
ahling21 Nov 22, 2026
61d78c4
Update test_hourly.py
ahling21 Nov 22, 2026
2fb2b61
Add Person C hourly LOS task fixtures and LSTM checkpoint
xiaoluo0916 Nov 17, 2026
5a483a0
Include synthetic intake-output fixture despite output ignore rule
xiaoluo0916 Nov 17, 2026
0fea051
Audit rubric readiness and fix hourly prediction look-ahead
xiaoluo0916 Nov 18, 2026
dca848f
Remove internal project planning notes from contribution
xiaoluo0916 Nov 18, 2026
b71e78d
Use neutral naming for TPC examples and test support
xiaoluo0916 Nov 18, 2026
b902f31
Remove machine-specific paths from validation reports
xiaoluo0916 Nov 18, 2026
1156863
Document reusable task interface and satisfy PR usage example check
xiaoluo0916 Nov 18, 2026
8bb5ebb
Apply repository lint rules to hourly task
xiaoluo0916 Nov 18, 2026
e2cd976
Leave explicit preprocessing and training extension points
xiaoluo0916 Nov 18, 2026
d6e569c
Clarify placeholders should reuse existing team implementations
xiaoluo0916 Nov 18, 2026
8d08fdd
Normalize generated CSV line endings for clean diffs
xiaoluo0916 Nov 18, 2026
7f88f5f
Delete tpc_eicu.py
ahling21 Nov 22, 2026
b3b1186
Update tpc_eicu.py
ahling21 Nov 22, 2026
4830d49
Update tpc_eicu.py
ahling21 Nov 22, 2026
bbce4a4
Update test_tpc_eicu.py
ahling21 Nov 22, 2026
71cd188
Update tpc_fixtures.py
ahling21 Nov 22, 2026
e534892
Update checkpoint.py
ahling21 Nov 22, 2026
ed655a3
Update tpc_fixtures.py
ahling21 Nov 22, 2026
a2d3ef7
Update generate_synthetic.py
ahling21 Nov 22, 2026
212164a
Update eicu_hourly_los_lstm.py
ahling21 Nov 22, 2026
736edc5
Update test_tpc_checkpoint.py
ahling21 Nov 22, 2026
8ae84f6
Update pyhealth.tasks.tpc_eicu.rst
ahling21 Nov 22, 2026
4a3ef18
Update pyhealth.tasks.tpc_eicu.rst
ahling21 Nov 22, 2026
15fd196
Update tpc_eicu.py
ahling21 Nov 22, 2026
99839e4
Update test_tpc_eicu.py
ahling21 Nov 22, 2026
9b0ff21
Apply Black formatting to TPC task and tests
ahling21 Nov 22, 2026
2b05e9b
Delete test_hourly.py
ahling21 Nov 22, 2026
9ad227c
Rename test_tpc_real.py to tests/integration/test_tpc_real.py
ahling21 Nov 22, 2026
d6a2d67
Update test_tpc_real.py
ahling21 Nov 22, 2026
92cf1da
Update pyhealth.tasks.tpc_eicu.rst
ahling21 Nov 23, 2026
0ba1306
Add RNN_V2 LSTM training, 6 metrics, and 2x3 missingness ablation
EmilyJYN Nov 25, 2026
47f03a5
Complete TPC eICU LoS example results, PR rules, docs, and tests
EmilyJYN Nov 26, 2026
4af6fe2
Adapt TPC eICU task to updated YAIB and RNN_V2 APIs
ahling21 Nov 27, 2026
d7f644f
Align default batch size with reported experimental settings
ahling21 Nov 27, 2026
84a2c3d
Merge latest upstream master and resolve task documentation conflict
ahling21 Nov 27, 2026
5ab8a04
Address AI review feedback on metrics tests, pre-rebase notes, and docs
EmilyJYN Nov 28, 2026
ba14b3f
Fix direct script import path, add synthetic ablation test, use jagge…
EmilyJYN Nov 28, 2026
daa9bcd
Clarify external patient subset preparation
ahling21 Nov 28, 2026
4d747aa
Clamp LOS labels and support optional label normalization
ahling21 Nov 28, 2026
53bbffb
Document synthetic CSVs and move checkpoint test into CI suite
ahling21 Nov 28, 2026
403ad23
Address AI review feedback on TPC task and example
ahling21 Nov 29, 2026
6ac4bb7
Merge upstream master and resolve task import conflict
ahling21 Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Available Tasks
Value Set Pair Classification (VSAC) <tasks/pyhealth.tasks.ValueSetPairClassification>
Time-to-event survival (GBSG and SUPPORT) <tasks/pyhealth.tasks.survival_time_to_event>
TCGA RNA-seq Survival Prediction <tasks/pyhealth.tasks.TCGASurvivalPrediction>
Hourly remaining ICU LOS <tasks/pyhealth.tasks.tpc_eicu>
Query-Focused EHR Summarization (MIMIC-III) <tasks/pyhealth.tasks.QueryFocusedEHRTask>
Multi-event survival (Rotterdam) <tasks/pyhealth.tasks.multi_event_survival_rotterdam>
Vasopressor Onset (MIMIC-III) <tasks/pyhealth.tasks.VasopressorOnsetMIMIC3>
Expand Down
116 changes: 116 additions & 0 deletions docs/api/tasks/pyhealth.tasks.tpc_eicu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. Contributors: Manling Tan, Yining Jin, Xiao Luo
.. NetIDs: manling4, yining34, xiaoluo6
..
.. Paper Title:
.. Temporal Pointwise Convolutional Networks for
.. Length of Stay Prediction in the Intensive Care Unit
..
.. Paper Authors:
.. Emma Rocheteau, Pietro Liò, and Stephanie Hyland (2021)
..
.. Paper URL:
.. https://arxiv.org/abs/2007.09483


Hourly remaining ICU length of stay
===================================

.. automodule:: pyhealth.tasks.tpc_eicu
:members:
:show-inheritance:

Implementation status
---------------------

The task implements adult cohort selection, hourly dynamic feature
extraction, admission static features, and hourly remaining-LOS labels.
The observation horizon is capped at 336 hours.

Remaining LOS labels are clamped to a minimum of 0.5 hours
(1/48 day).

Label normalization is controlled by ``normalize_labels``.
The default is ``True``, which preserves YAIB's min-max label
normalization. Set ``normalize_labels=False`` to preserve raw
remaining-LOS labels in hours for MSLE-based models.

Observation removal is controlled by ``missing_rate`` (0.0 to 1.0).
Removal uses one deterministic mask per stay for a given seed and stay
identifier, so repeated training epochs over the same dataset see the same
masked observations. A rate of 0.0 preserves all observed values, while a rate
of 1.0 removes all observed feature cells.

When ``include_decay=True``, decay features are calculated after
observation removal. Observed values reset to 1.0, and unobserved
values decay by a factor of 0.75 per hour.

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] Decay description omits features that are never observed

The page says unobserved values decay by 0.75 per hour. In the code (pyhealth/tasks/tpc_eicu.py, _decay), a feature with no prior observation stays at 0 rather than decaying. Add one sentence saying so.


Missing dynamic values remain NaN in the task output. Forward filling
and normalization are handled by the configured YAIB preprocessing
pipeline.


Usage and validation
--------------------

From a repository checkout in Python 3.12 or 3.13::

python -m pip install -e . pytest
python examples/tpc_support/generate_synthetic.py /tmp/tpc_synthetic
python -m examples.tpc_support.checkpoint --output /tmp/tpc_checkpoint.json
python -m pytest tests/core/test_tpc_eicu.py -q --durations=5
python -m pytest tests/core/test_tpc_checkpoint.py -q
python examples/eicu_hourly_los_lstm.py --synthetic --epochs 2

The synthetic CSV generator produces invented records across five patients.
The committed CSV files in ``examples/tpc_support/synthetic_eicu/``
serve as illustrative examples of the expected eICU data format for
manual inspection. They are not required at runtime. The synthetic
generator creates fresh CSV files for the example and checkpoint scripts.

The checkpoint script validates cohort selection, static values, aggregated
measurements, and remaining-LOS labels against independent numerical
expectations without training a model. The CSV-to-task checkpoint test
is included in the core test suite.

Input and output specification
------------------------------

Load ``lab``, ``vitalperiodic``, ``vitalaperiodic``, ``intakeoutput``,
``respiratorycharting``, and ``nursecharting`` using :class:`~pyhealth.datasets.eICUDataset`.
One sample is produced per eligible stay:

* Adults have known age >=18 and total ICU stay >=5 hours; ``> 89`` maps to 90.
Unknown age excludes the stay. Unknown sex or invalid height/weight is NaN.
* Static features are age, sex (male=1, female=0), admission height and weight.
* Dynamic uses 48 YAIB features. For H=min(floor(total LOS hours),336), its
values have shape (H,48), with missing values retained as NaN.
* Bin [b,b+1) becomes available at timestamp b+1. At hour 5 the model may
consume bins 0–4 only.
* Labels at hours 5..H have shape (H-4,1) and equal
max(0.5, total LOS hours - h). All raw labels are at least
0.5 hours, including exact-discharge labels. The observation
horizon is capped; remaining LOS is not capped.
* ``missing_rate`` controls deterministic per-stay removal of observed hourly
feature cells prior to forward-fill. A rate of 0.0 preserves observations;
1.0 removes all observed cells.
* ``include_decay=True`` adds decay features matching the dynamic
feature dimensions. Decay resets to 1.0 upon observation and
decreases by a factor of 0.75 per unobserved hour.
* Split by ``patient_id`` rather than ``stay_id``, and fit learned processors
on training patients only. By default, YAIB label processors min-max scale
training targets. Set ``normalize_labels=False`` to disable label
normalization and retain raw LOS targets in hours for MSLE-based models.

For models requiring unnormalized LOS targets::

from pyhealth.tasks import TPCLengthOfStayEICU

task = TPCLengthOfStayEICU(
missing_rate=0.1,
include_decay=True,
normalize_labels=False,
)

This task reproduces the hourly remaining-LOS prediction formulation from the
paper using YAIB feature extraction and PyHealth's existing preprocessing
pipeline, rather than re-implementing the TPC model architecture.
Loading
Loading