Skip to content
genmilabPublic

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Learning Where to Adapt: Learned Subspace Test-Time Adaptation for Medical Time Series

Typing SVG

Paper Project Page Weights PyTorch Task Visitors

πŸ“„ Paper Β |Β  🌐 Project Page Β |Β  πŸ€— Checkpoints Β |Β  🧠 Method Β |Β  ⚑ Run

Adinath Dukre1,2*, Sandun Herath2*, Imran Razzak1,2

1Mohamed bin Zayed University of Artificial Intelligence, Abu Dhabi, UAE Β Β  2Vitalverse Β Β  *Equal contribution

GenMI Lab

πŸ”₯ News

  • [Oct 2026] πŸš€ Code for LSTA is released. The arXiv preprint and pretrained checkpoints are coming soon.

Overview

Official code for LSTA (Learned Subspace Test-Time Adaptation).

Test-time adaptation (TTA) promises to personalize medical time series classifiers to a new subject from a few unlabeled recordings. Its standard recipe, entropy minimization over normalization parameters, follows the model's uncertainty rather than the ways in which subjects actually differ, and with few windows it can turn correct predictions into errors. LSTA instead learns where to adapt: it meta-learns from past subjects a low-rank space of LayerNorm updates and restricts each new subject's adaptation to it.

LSTA overview Fig. 1. Overview of LSTA. (a) Premise: recordings from different subjects differ through a few shared factors such as gain, baseline and electrical axis (schematic; traces are illustrative, not measured data). (b) Entropy-based test-time adaptation moves every LayerNorm parameter along the model's uncertainty, whereas LSTA restricts the update of a new subject to a low-rank subspace meta-learned from past subjects. (c) Measured worst-case change in macro-F1 relative to the frozen backbone across the eight datasets; LSTA is the only method that never falls below the frozen model.

πŸ“– Contents

🧠 Method

LSTA framework Fig. 2. (a) Learning the adaptation subspace: unlabeled support windows determine an entropy-based LayerNorm update within a shared low-dimensional space. Classification loss on separate labeled query windows trains the adaptation basis, while the pretrained source parameters remain fixed. (b) Subject-specific test-time adaptation: the learned basis is frozen, and unlabeled support windows from an unseen subject determine the LayerNorm update used to classify that subject's query windows.

  • Learned adaptation subspace. Inter-subject shift is plausibly driven by a few shared physiological and recording factors, so LSTA restricts subject-specific LayerNorm updates to a shared low-rank subspace learned from training subjects.
  • Meta-training. For each training subject, unlabeled support windows determine an entropy step within the subspace, and the classification loss on labeled query windows from the same subject shapes the subspace.
  • Test time. The subspace is fixed, all parameters outside LayerNorm stay frozen, and each new subject adapts from at most eight unlabeled windows.

πŸ† Results

As reported in the paper:

  • On five EEG and ECG benchmarks with subject-exclusive splits, LSTA obtains the highest mean accuracy and macro-F1 among seven TTA baselines.
  • A learned subspace outperforms a random one in 22 of 25 dataset-seed pairs.
  • Across all eight datasets evaluated, LSTA is the only method whose macro-F1 never falls below that of the frozen model.
  • Under contaminated support, LSTA degrades far less than direct LayerNorm adaptation and turns fewer correct predictions into errors. On clean data, its gain over direct LayerNorm adaptation is concentrated on one dataset.

Main results Table 1. Macro-F1 (%, mean Β± s.d. over five backbone seeds) of test-time adaptation methods on the five subject-labeled datasets. All methods adapt the same frozen TeCh checkpoints with the same support draws and query windows, except MedTS-TTT, which uses its own backbone.

Component ablation Table 2. Component ablation (test F1, Γ—100, mean Β± s.d. over 5 seeds). Top: components added in turn. Bottom: LSTA's meta-learned rank-8 subspace replaced.

Performance and efficiency on TDBRAIN
Fig. 3. Performance and efficiency on TDBRAIN. Test macro-F1 against inference time per test episode (log scale); bubble size indicates FLOPs, and the upper-left corner is better.

Robustness to support contamination Fig. 4. Robustness to support contamination across six subject-labeled datasets. 0%, 25% or 50% of the support windows are replaced with windows from another subject of a different diagnostic class. Curves show mean macro-F1 across five backbone seeds and five support draws per seed.

πŸ“Ž Appendix

Additional figures and tables from the paper's appendix. Full captions are in the images; see also the project page.

Appendix figures (click to collapse)

Figure 5. t-SNE of pre-classifier features on APAVA
Figure 5. t-SNE of pre-classifier features on APAVA

Figure 6. Effect of the adaptation subspace rank
Figure 6. Effect of the adaptation subspace rank

Figure 7. Effect of the number of unlabeled support windows
Figure 7. Effect of the number of unlabeled support windows

Figure 8. Effect of the number of test-time adaptation steps
Figure 8. Effect of the number of test-time adaptation steps

Figure 9. Sensitivity to the adaptation step size
Figure 9. Sensitivity to the adaptation step size

Figure 10. Robustness to test-time signal corruption
Figure 10. Robustness to test-time signal corruption

Figure 11. Distributions of LayerNorm updates
Figure 11. Distributions of LayerNorm updates

Figure 12. t-SNE of representations for the frozen backbone and adaptation methods
Figure 12. t-SNE of representations for the frozen backbone and adaptation methods

Figure 13. t-SNE of ADFTD pre-classifier features
Figure 13. t-SNE of ADFTD pre-classifier features

Appendix tables (click to expand)

Table 3. Comparison with published classifiers on the five subject-labeled datasets
Table 3. Comparison with published classifiers on the five subject-labeled datasets

Table 4. Dataset summary
Table 4. Dataset summary

Table 5. Window-labeled datasets (MIT-BIH, Sleep-EDF) and HPP
Table 5. Window-labeled datasets (MIT-BIH, Sleep-EDF) and HPP

Table 6. F1 on HPP under support contamination
Table 6. F1 on HPP under support contamination

Table 7. Component ablation on HPP, MIT-BIH and Sleep-EDF
Table 7. Component ablation on HPP, MIT-BIH and Sleep-EDF

Table 8. Full comparison with TTA and source-free baselines
Table 8. Full comparison with TTA and source-free baselines

πŸ“Š Datasets

Dataset Signal Subjects Classes Label
ADFTD EEG 88 3 subject
APAVA EEG 23 2 subject
TDBrain EEG 72 2 subject
PTB ECG 198 2 subject
PTB-XL ECG 17,596 5 subject

This repository provides scripts for the five subject-labeled benchmarks above. The paper additionally reports MIT-BIH, Sleep-EDF and HPP.

⛏️ Installation

git clone https://github.com/adinathdukre/LSTA.git
cd LSTA
pip install -r requirements.txt

The code requires PyTorch 2.x. For GPU execution, install a PyTorch build compatible with your CUDA environment.

⚑ Running experiments

Data preparation

Download the datasets from Medformer and follow TeCh's preprocessing and subject-independent split protocol. TDBRAIN requires permission from the dataset provider.

Place the prepared datasets in their corresponding folders:

./data/ADFTD/
./data/APAVA/
./data/TDBRAIN/
./data/PTB/
./data/PTB-XL/

Each dataset folder should contain Feature/ and Label/label.npy, following the format expected by the data loaders.

Pretrained checkpoints

Download the pretrained TeCh backbone checkpoints from Hugging Face.

Place the downloaded checkpoints/ folder in the repository root, preserving its directory structure:

./checkpoints/baseline/<DATASET>/<experiment_name>/checkpoint.pth

These are source backbone checkpoints. The experiment scripts train and save the learned LSTA adaptation bases separately.

Launch scripts

Dataset-specific scripts are provided under ./scripts/. Run commands from the repository root.

For example, run APAVA with:

bash ./scripts/APAVA.sh

To select a GPU:

GPU=1 bash ./scripts/APAVA.sh

Run the other datasets with:

bash ./scripts/ADFTD.sh
bash ./scripts/TDBRAIN.sh
bash ./scripts/PTB.sh
bash ./scripts/PTB-XL.sh --tune_subjects 400

The scripts train the adaptation basis, select its configuration using validation macro-F1, and evaluate on test subjects. Matching saved basis checkpoints are reused automatically.

View results

Training records, learned bases, and evaluation results are saved under:

./runs/logs/TTA_SWEEP/<DATASET>/

Per-seed results are saved in test_result.json and test_result.txt. Aggregated results are saved in summary.json and summary.txt.

πŸ—‚οΈ Repository Structure

LSTA/
β”œβ”€β”€ run.py               # TeCh backbone training
β”œβ”€β”€ tta.py               # LSTA subspace learning, model selection and test-time evaluation
β”œβ”€β”€ data_provider/       # dataset loaders and subject-window sampling
β”œβ”€β”€ exp/                 # training and TTA evaluation loops
β”œβ”€β”€ models/              # TeCh backbone and encoder
β”œβ”€β”€ scripts/             # one launch script per dataset
β”œβ”€β”€ utils/               # losses, metrics, augmentation, logging
└── requirements.txt

πŸ“ Citation

If you find our paper and code useful in your research, please cite:

@article{dukre2026lsta,
  title={Learning Where to Adapt: Learned Subspace Test-Time Adaptation for Medical Time Series},
  author={Dukre, Adinath and Herath, Sandun and Razzak, Imran},
  journal={arXiv preprint},
  year={2026}
}

πŸ“š Acknowledgments

This project builds on TeCh and Medformer. We thank their authors for sharing their code and preprocessing resources.

πŸ“¨ Contact

For questions or collaboration, please open an issue or reach out to Adinath Dukre.

Important

LSTA is intended for research only. It is not approved for clinical use and must not inform any diagnostic or treatment decision.

Releases

Packages

Contributors

Languages