Add TPC model for length of stay prediction #626
+2,153
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add TPC Model for Length of Stay Prediction
Overview
This PR implements Temporal Pointwise Convolutional Networks (TPC) for healthcare time series prediction, specifically designed for length of stay (LoS) prediction tasks in ICU and other clinical settings.
Paper: Rocheteau et al., "Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the Intensive Care Unit," CHIL 2021
Paper Link: https://arxiv.org/pdf/2007.09483
Original Code: https://github.com/EmmaRocheteau/TPC-LoS-prediction
What's Added
1. TPC Model (
pyhealth/models/tpc.py)2. Complete Example (
examples/tpc_example.ipynb)3. Updated Imports (
pyhealth/models/__init__.py)Key Features
Architecture Innovations
[input, temporal_out, pointwise_out]at each layerPyHealth Integration
SampleDatasetandTrainerEmbeddingModelfor categorical feature handlingPerformance
Test Results (Synthetic ICU Data, 1000 patients): for only 5 epochs
Implementation Decisions
Loss Function Choice
The original paper uses masked MSLE (Mean Squared Logarithmic Error with masking) for sequence-to-sequence prediction tasks where a prediction is made at each timestep.
Our implementation performs sequence-to-one prediction (single LoS value per patient), not sequence-to-sequence. The model already handles variable-length sequences by extracting the last valid timestep representation. Therefore:
We use PyHealth's standard MSE loss because:
(batch, seq_len)predictions, we output(batch, 1)Code Quality
Documentation
Code Standards
BaseModelconventionsTesting
Trainersplit_by_patientandget_dataloaderUsage Example
See
examples/tpc_example.ipynbfor complete tutorial.Files Changed
Reproducibility
This implementation is part of a reproducibility study for CS 598 Deep Learning for Healthcare (UIUC). The code demonstrates that:
Additional Notes
For Reviewers
Future Work
Potential extensions (not in this PR):
Thank you for reviewing! I'm happy to address any feedback or make requested changes.