π 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
- [Oct 2026] π Code for LSTA is released. The arXiv preprint and pretrained checkpoints are coming soon.
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.
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.
- π§ Method
- π Results
- π Appendix
- π Datasets
- βοΈ Installation
- β‘ Running experiments
- ποΈ Repository Structure
- π Citation
- π Acknowledgments
- π¨ Contact
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.
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.
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.
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.
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.
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.
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 6. Effect of the adaptation subspace rank
Figure 7. Effect of the number of unlabeled support windows
Figure 8. Effect of the number of test-time adaptation steps
Figure 9. Sensitivity to the adaptation step size
Figure 10. Robustness to test-time signal corruption
Figure 11. Distributions of LayerNorm updates
Figure 12. t-SNE of representations for the frozen backbone and adaptation methods
Appendix tables (click to expand)
Table 3. Comparison with published classifiers on the five subject-labeled datasets
Table 5. Window-labeled datasets (MIT-BIH, Sleep-EDF) and HPP
Table 6. F1 on HPP under support contamination
| 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.
git clone https://github.com/adinathdukre/LSTA.git
cd LSTA
pip install -r requirements.txtThe code requires PyTorch 2.x. For GPU execution, install a PyTorch build compatible with your CUDA environment.
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.
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.
Dataset-specific scripts are provided under ./scripts/. Run commands from the repository root.
For example, run APAVA with:
bash ./scripts/APAVA.shTo select a GPU:
GPU=1 bash ./scripts/APAVA.shRun the other datasets with:
bash ./scripts/ADFTD.sh
bash ./scripts/TDBRAIN.sh
bash ./scripts/PTB.sh
bash ./scripts/PTB-XL.sh --tune_subjects 400The scripts train the adaptation basis, select its configuration using validation macro-F1, and evaluate on test subjects. Matching saved basis checkpoints are reused automatically.
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.
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
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}
}This project builds on TeCh and Medformer. We thank their authors for sharing their code and preprocessing resources.
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.



