Papers
Topics
Authors
Recent
Search
2000 character limit reached

CAPE: Patient ECG Contrastive Learning

Updated 10 July 2026
  • The paper introduces CAPE, a contrastive learning framework that pulls together dual augmented ECGs from the same patient while separating those from different patients.
  • CAPE employs a four-layer ResNet with signal-preserving augmentations and leverages multi-centre pretraining to enhance age and sex prediction accuracy.
  • The study finds that while multi-centre pretraining improves in-distribution performance, it may degrade out-of-distribution results, a challenge mitigated by the In-Distribution Batch strategy.

Searching arXiv for the specified CAPE paper and its closely related predecessor. Contrasting by Patient Augmented Electrocardiograms (CAPE) is a patient-level contrastive learning framework for ECG representation learning in which two ECG recordings from the same patient are made close in embedding space while ECGs from other patients in the batch are pushed apart. In the corresponding foundation-model study, CAPE is used to examine how the composition of pretraining data changes what is learned, and how those learned representations affect both in-distribution (ID) downstream performance and out-of-distribution (OOD) generalization across hospitals, countries, and continents (Khattak et al., 12 Sep 2025).

1. Conceptual basis and objective

CAPE is a contrastive self-supervised ECG foundation model. Its positive pairs are two ECGs from the same patient, recorded at different times and augmented in a signal-preserving way; its negative pairs are ECGs from other patients in the batch. The model therefore learns a shared embedding space in which same-patient ECGs are pulled together and different-patient ECGs are separated (Khattak et al., 12 Sep 2025).

The formulation aligns with InfoNCE / SimCLR-style contrastive learning. For projected embeddings ziz_i and zjz_j corresponding to two augmented ECGs from the same patient, the per-pair loss is described as

i,j=logexp(sim(zi,zj)/T)k=12N1[ki]exp(sim(zi,zk)/T)\ell_{i,j} = -\log \frac{\exp(\mathrm{sim}(z_i, z_j)/T)}{\sum_{k=1}^{2N} \mathbf{1}_{[k \neq i]} \exp(\mathrm{sim}(z_i, z_k)/T)}

where TT is the temperature, NN is the number of positive pairs in the batch, and sim(,)\mathrm{sim}(\cdot,\cdot) is cosine similarity,

sim(zi,zj)=zizjzizj.\mathrm{sim}(z_i,z_j) = \frac{z_i^\top z_j}{\|z_i\| \|z_j\|}.

The total loss is summed across all positive pairs in the batch:

=(i,j)i,j.\ell = \sum_{(i,j)} \ell_{i,j}.

This objective makes patient identity, rather than merely signal transformation, the organizing principle of positive-pair construction. A plausible implication is that CAPE is optimized to preserve persistent patient-level ECG structure across time while suppressing variation introduced by individual recordings or augmentations.

2. Architecture, augmentation, and signal pipeline

The CAPE model uses a four-layer ResNet backbone, a nonlinear projection head, and 256-dimensional embeddings for downstream tasks. Signal-preserving augmentations include random cropping and zero masking (Khattak et al., 12 Sep 2025).

Its ECG preprocessing pipeline uses leads I, II, V1–V6, a bandpass filter of 0.5–100 Hz, a notch filter for mains frequency, resampling to 400 Hz, and a standardized input of 7 seconds with shape 2800×82800 \times 8. This establishes a fixed multilead representation before contrastive pretraining (Khattak et al., 12 Sep 2025).

Downstream evaluation is performed with supervised MLP heads on frozen CAPE embeddings. The main prediction tasks are age prediction, treated as regression, and sex prediction, treated as classification. The reported metrics are MAE for age and AUROC/AUC for sex. In this setup, CAPE functions as a representation learner whose quality is assessed by linear or shallow supervised readout performance rather than by end-to-end finetuning alone.

3. Cohorts and experimental design

The study pretrains CAPE on four cohorts: BIDMC (Beth Israel Deaconess Medical Centre, USA), CODE (Clinical Outcomes in Digital Electrocardiogram, Brazil), SHZS (Shanghai Zhongshan Hospital, China), and VUMC (Vanderbilt University Medical Centre, USA). Together, these four cohorts form the combined pretraining set BCSV, which contains 5,203,352 ECGs and spans three continents: North America, South America, and Asia (Khattak et al., 12 Sep 2025).

Cohort Geography Size
BIDMC USA, North America 1,106,886 ECGs; 127,041 patients
CODE Brazil, South America 1,123,903 ECGs; 424,577 patients
SHZS China, Asia 1,560,551 ECGs; 420,956 patients
VUMC USA, North America 1,412,012 ECGs; 252,306 patients
UK Biobank (UKB) United Kingdom, Europe 70,655 ECGs; 66,402 patients
PTB-XL Germany, Europe 21,799 ECGs; 18,869 patients

Two additional European cohorts are used for downstream evaluation: UK Biobank, described as a healthy volunteer cohort, and PTB-XL, described as an open-access secondary care dataset. The resulting design separates large-scale pretraining from geographically external evaluation and makes it possible to test whether improvements obtained from multi-centre pretraining transfer to distinct healthcare settings (Khattak et al., 12 Sep 2025).

4. Dependence on pretraining distribution

A central finding is that downstream performance depends on the distributional properties of the pretraining cohort, including demographics and health status. The multi-centre pretraining model CAPE-X, trained on BCSV, achieves the best in-distribution average performance, giving the lowest mean MAE and highest mean AUROC across label cohorts; equivalently, it achieves the best age MAE and best sex AUROC in the in-distribution setting (Khattak et al., 12 Sep 2025).

Among single-cohort pretraining models, BIDMC and VUMC outperform CODE and SHZS. The study links this to health status and signal variability: secondary-care cohorts contain more diverse and pathological ECG patterns, whereas healthier cohorts are more homogeneous, reducing representation richness. This establishes that the number of patients is not the only determinant of pretraining quality; the kind of patients and the diversity of ECG morphology also matter (Khattak et al., 12 Sep 2025).

The evaluation cohort also affects apparent performance. UK Biobank often shows the strongest downstream performance because it is a healthy volunteer cohort, has a narrower age distribution, and has a more concentrated age range around the ages with lowest error. The study therefore states that performance comparisons across different cohorts are not directly comparable unless cohort composition is controlled. This suggests that benchmark results for ECG foundation models can reflect label-cohort geometry as much as representational quality.

5. OOD generalization, cohort artifacts, and In-Distribution Batch

The same study reports a paradox: multi-centre pretraining improves ID accuracy but can worsen OOD generalization. When CAPE-X is pretrained on the combined multi-centre BCSV cohort and then a prediction head is trained on BIDMC, performance drops sharply on external cohorts, especially CODE and SHZS. The paper reports strong degradation in OOD sex prediction AUROC and age MAE under this configuration (Khattak et al., 12 Sep 2025).

The accompanying analysis attributes this effect to cohort-specific artifacts. Using t-SNE, the embeddings from CAPE-X cluster by cohort, and the study states that these clusters appear to be driven less by ethnicity and more by technical differences such as recording hardware, preprocessing differences, and acquisition pipelines. Under mixed-cohort contrastive batching, those features can become easy discriminative shortcuts. A plausible implication is that CAPE-X can partially encode where an ECG came from, not only what it encodes clinically.

To address this issue, the authors propose the In-Distribution Batch (IDB) strategy, used in the CAPE-Z model. Under IDB, each contrastive batch contains samples from only one cohort; positives still come from the same patient, negatives come from other patients in the same cohort, and all batch elements are therefore drawn from a single distribution. For cohort XX, the batch-wise loss is written as

zjz_j0

The reported effect is that CAPE-Z reduces cohort clustering in embedding space, improves OOD robustness, and maintains strong ID performance. The paper further states that CODE age MAE improves dramatically, SHZS age MAE improves dramatically, and sex AUROC also rises substantially on external cohorts; unlike CAPE-X, CAPE-Z shows no obvious cohort clustering in t-SNE space (Khattak et al., 12 Sep 2025).

6. Relation to earlier ECG contrastive learning and the “good views” problem

CAPE addresses a question already prominent in ECG self-supervision: what should count as a positive pair? A closely related study, “Finding ‘Good Views’ of Electrocardiogram Signals for Inferring Abnormalities in Cardiac Condition,” investigates several ways to define positive samples for arrhythmia-oriented contrastive learning and concludes that learned representations invariant to patient identity are powerful in arrhythmia detection (Jeong et al., 2024).

That earlier work explicitly compares five notions of positive-sample construction. Two are patient-specific: a CLOCS-like temporal/spatial invariance strategy using non-overlapping temporal windows and/or different leads from the same ECG, and a SimCLR-style strategy using two stochastic augmentations of the same ECG. Three are patient-invariant: pairing ECGs from different patients who share age and gender, pairing ECGs sharing expert-labeled rhythm categories, and pairing ECGs whose 11 numerical ECG attributes satisfy zjz_j1. Its downstream evaluation is a 4-class arrhythmia classification task on the Chapman ECG dataset, with classes SR, SB, GSVT, and AFIB, and a linear classifier trained on frozen embeddings from a ResNet-18 encoder (Jeong et al., 2024).

The reported AUROC scores in that study are 81.4 ± 1.3 for the supervised baseline, 88.9 ± 1.6 / 83.0 ± 1.1 for Strategy 1, 89.6 ± 0.6 for Strategy 2, 88.1 ± 1.3 for Strategy 3, 99.3 ± 0.0 for Strategy 4, and 94.2 ± 0.3 for Strategy 5. The paper concludes that all contrastive methods outperform the supervised baseline and that patient-invariant strategies are as good as or better than patient-specific strategies. Strategy 5 is presented as the strongest practical result because it requires only automatically extracted numerical features rather than expert semantic labels, whereas Strategy 4 is noted as less useful because it depends on labels already close to the downstream task (Jeong et al., 2024).

The connection to CAPE is conceptual but not identical in mechanism. The earlier paper mostly selects real ECGs from other patients as positive matches based on demographics, rhythms, or wave attributes, whereas CAPE constructs positives from two ECG recordings of the same patient and studies how cohort composition and batching alter the resulting representation. Both lines of work, however, are organized around the same high-level principle: contrastive learning is most effective when positive views preserve task-relevant information while becoming invariant to nuisance factors. This suggests that CAPE belongs to a broader shift in ECG self-supervision from generic signal perturbation toward clinically structured definitions of “good views.”

7. Significance and scope

Within ECG foundation-model research, CAPE is significant for isolating a specific dependency that is often implicit in contrastive pipelines: representation quality is a function not only of architecture and loss, but also of pretraining distribution, batching policy, health-status mix, and cohort-specific technical variation (Khattak et al., 12 Sep 2025).

The study therefore sharpens two points that are sometimes conflated. First, multi-centre, demographically diverse pretraining can improve in-distribution accuracy by exposing the model to more patient variability, broader disease patterns, and richer training signal. Second, the same diversity can reduce OOD generalization if contrastive batches mix cohorts in a way that allows the encoder to exploit cohort identity cues. The proposed IDB strategy is presented as a practical way to preserve intra-cohort consistency during pretraining and reduce spurious cohort encoding while retaining strong ID performance.

In that sense, CAPE is less a claim that more data is always better than a claim that cohort-aware contrastive design is essential. Its stated clinical target is the development of ECG foundation models that are fair, generalizable, and robust across hospitals and countries, and its empirical message is that those properties depend materially on how patient-level positives and cohort-level negatives are organized during pretraining (Khattak et al., 12 Sep 2025).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Contrasting by Patient Augmented Electrocardiograms (CAPE).