Back to Portfolio
Healthcare AI

ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals

A physiologically informed deep-learning framework that disentangles ECG morphology from rhythm to generalize to unseen hospitals and devices without fine-tuning.

ET
Eric Tran · Project lead
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals

Key Features

  • Morphology–rhythm disentanglement: deterministic MiniRocket waveform features combined with explicit HRV rhythm descriptors
  • Bi-directional Mamba backbone (16 layers) for linear-time long-range temporal context
  • Cross-attention fusion with a Perceiver latent bottleneck of 64 tokens
  • Numerically stable Power Mean pooling (Q=3) that emphasises high-evidence segments without the brittleness of max pooling
  • Protocol-faithful evaluation: 5-fold subject-aware cross-validation, fixed threshold, no test-time adaptation
  • Macro ROC-AUC of 0.848 ± 0.047 on Chapman–Shaoxing (45,000+ 12-lead recordings)
  • Zero-shot PR-AUC of 0.708 for atrial fibrillation on the external CPSC-2021 cohort
  • Calibration analysis, bootstrap confidence intervals, HRV domain-identifiability probe and noise/lead/sampling robustness tests

Overview

Deep learning already classifies electrocardiograms (ECG) well within a single dataset. The obstacle to clinical deployment is what happens across datasets: move a model to another hospital, with different hardware, lead placement, sampling rates and patient mix, and accuracy often falls away. ECG-RAMBA attacks that generalization gap by explicitly separating the two information streams clinicians actually reason about — morphology and rhythm — and re-integrating them through context-aware fusion.

The Problem

Many architectures implicitly entangle morphological waveform patterns with rhythm dynamics inside a single representation. That entanglement encourages shortcut learning: the network latches onto dataset-specific acquisition cues that correlate with labels in training but do not reflect causal physiology. The result is a model that looks excellent on its own benchmark and becomes brittle under distribution shift — precisely the behaviour that erodes clinical trust.

Standard 12-lead ECG acquisition

Approach

Clinical ECG interpretation integrates at least two complementary streams: morphology (P/QRS/T shape, ST–T deviations) and rhythm (beat-to-beat variability and regularity). ECG-RAMBA mirrors that separation in the architecture itself:

  • Morphology — MiniRocket extracts stable, deterministic waveform representations efficiently, without learning dataset-specific filters.
  • Rhythm — heart-rate variability (HRV) descriptors derived from R–R intervals encode global rhythm dynamics using clinically standardised definitions.
  • Long-range context — a bi-directional Mamba backbone refines temporal context in linear time, capturing rhythm evidence that unfolds over many beats.
  • Fusion — cross-attention merges the two views through a Perceiver bottleneck of 64 latent tokens before multi-label prediction over 27 ECG classes.
ECG-RAMBA architecture integrating MiniRocket morphology features, HRV rhythm descriptors and a BiMamba backbone with cross-attention fusion

Power Mean pooling

Transient abnormalities are easy to lose under windowed inference: max pooling is brittle to noise, while averaging dilutes short pathological events. We introduce a numerically stable Power Mean pooling operator that acts as a soft-attention mechanism over windows. A full sweep showed higher exponents marginally improve F1 while increasing sensitivity to noise artifacts, so Q=3 was adopted as the robust operating point.

Sensitivity analysis over the Power Mean pooling exponent Q

Protocol-Faithful Evaluation

Evaluation choices strongly influence reported ECG results. Protocols that allow subject overlap between training and test splits, or that tune decision thresholds in ways deployment would not permit, yield optimistic estimates. We therefore enforce subject-level separation, a fixed decision threshold and no test-time adaptation throughout.

  • Chapman–Shaoxing (45,000+ 12-lead recordings at 500 Hz) for training and in-distribution evaluation under strict 5-fold subject-aware cross-validation.
  • CPSC-2021 for zero-shot paroxysmal atrial fibrillation under device noise and sampling shift.
  • PTB-XL for zero-shot transfer across diverse diagnostic superclasses and acquisition protocols.

Results

In distribution, ECG-RAMBA reaches a macro ROC-AUC of 0.848 ± 0.047 with a macro F1 of 0.312 ± 0.052 at a fixed threshold. In zero-shot transfer it attains PR-AUC 0.708 for atrial fibrillation on CPSC-2021, substantially outperforming a comparable raw-signal Mamba baseline and remaining competitive against learned convolutional and transformer baselines.

Zero-shot atrial fibrillation detection results on the external CPSC-2021 cohort

Transfer reveals a dichotomy grounded in physiology rather than noise. Rhythm-dominant abnormalities generalize robustly across devices, confirming the model captures global temporal invariants. Morphology-dependent pathologies — particularly myocardial infarction on PTB-XL — degrade under transfer, reflecting sensitivity to lead-set configuration. We quantify that behaviour rather than averaging it away.

Zero-shot transfer results on PTB-XL across diagnostic superclasses

The gap between strong ranking (ROC-AUC) and more conservative fixed-threshold decisions is examined directly through a calibration analysis, distinguishing a genuinely conservative operating point from simple miscalibration — a distinction that matters for a decision-support system expected to minimise false positives and avoid alarm fatigue.

Ablation study isolating the contribution of morphology, rhythm and long-range context

Ablations indicate deterministic morphology provides a strong foundation, while explicit rhythm modeling and long-range context are the critical drivers of cross-domain robustness. Robustness checks cover noise, sampling-rate and lead perturbations, alongside an HRV domain-identifiability probe that tests whether rhythm features leak dataset provenance.

Robustness of the model under progressive lead dropout

Outcome

ECG-RAMBA shows that physiological disentanglement is a practical route to cross-domain robustness: the model transfers to unseen cohorts without fine-tuning, and its interpretable division of labour between waveform morphology, rhythm descriptors and long-range evidence makes its failure modes legible instead of mysterious.

Saliency analysis showing which ECG regions drive model predictions

Gallery

Figures and interface screenshots from the project.

ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 1
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 2
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 3
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 4
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 5
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 6
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 7
ECG-RAMBA — Zero-Shot ECG Generalization Across Hospitals - Image 8