Keep the Millivolts: Shape-Only Adversarial Adaptation for Imbalanced ECG Diagnosis

When an electrocardiogram (ECG) classifier trained at one hospital is moved to another, it often degrades because the new site's recording hardware differs. A standard fix is adversarial domain adaptation. A second network, the discriminator, tries to guess which hospital a recording came from, and the classifier's feature extractor is trained to defeat it. For ECGs this fix has a hidden cost. One of the easiest cues for telling hospitals apart is signal amplitude, because amplitude varies with amplifier gain, electrode impedance, and calibration. Several diagnoses are also defined by amplitude: left ventricular hypertrophy, low-voltage QRS, and ST elevation are all stated in millivolts. A feature extractor trained to hide the hospital therefore learns to throw away absolute voltage. In effect, adversarial training works as a learned normalization that discards the very information that defines these classes. The damage concentrates on rare classes. Amplitude-defined conditions are minorities, and when they are more common at one site than another, their prevalence becomes a further amplitude cue that the discriminator can use.

We propose to split each recording into a shape part and a scale part and to apply adversarial alignment only to shape. The shape part is each lead normalized per instance, so it carries the timing and form of the waveform. The scale part is a beat-by-beat record of per-lead voltages in millivolts. It is not aligned adversarially. Instead it is corrected for site gain using only the abundant normal ECGs as a reference, and it is trained on the unlabeled target site by distilling from a source model that sees raw amplitudes. Class imbalance helps here: because normal recordings dominate every site, they give a large, trustworthy reference for estimating the instrument's gain without disturbing pathological voltages.

Core Claim

Our claim has two parts. First, standard and conditional adversarial adaptation on raw-amplitude ECGs measurably removes millivolt information from the learned features. The loss should be largest for amplitude-defined minority classes and nearly absent for rhythm classes. Second, routing amplitude around the discriminator should recover those classes without giving up the adaptation gains on shape-defined classes. The routing works through three steps: beat-level scale features, gain calibration anchored on normals, and distillation on unnormalized logits. The new element is the treatment of amplitude as a separately calibrated physical quantity inside adversarial adaptation, rather than as domain style to erase. We also give a specific reason why the calibration should be anchored on the majority class: it is the one estimate that label shift does not bias.

Research Program

The motivation comes from two kinds of evidence. Raw amplitude carries diagnostic content: Vision Transformer and ResNet arrhythmia classifiers on Chapman–Shaoxing did better on non-normalized than on z-normalized inputs (Deciphering Heartbeat Signatures), and normalizing transcranial Doppler waveforms removed the absolute velocity thresholds needed for clinical clustering (Toward Automated Classification of Pathological Transcranial Doppler Waveform Morphology via Spectral Clustering). Adversarial alignment can also go wrong under imbalance: Conditional Adversarial Domain Adaptation (CDAN) conditions the discriminator on class predictions to stop classes from being matched to the wrong partners, and Using Latent Codes for Class Imbalance Problem in Unsupervised Domain Adaptation (LADA) shows that adversarial methods lose 30–50% accuracy when class proportions differ between domains. Neither line asks what the discriminator removes when scale is itself diagnostic. We start from that question.

The first component is a diagnostic study. We will train source-only, DANN (a discriminator with a gradient-reversal layer), and CDAN+E models on raw-amplitude 12-lead ECGs. We will then fit linear probes from the frozen features to measured quantities: per-lead R-wave amplitude, the Sokolow–Lyon voltage sum, and ST deviation in millivolts. Probe accuracy before and after adaptation, set against per-class area under the precision–recall curve, tests whether adaptation trades voltage for invariance.

The second component is the factored model. We borrow the save-and-reuse idea of Reversible Instance Normalization (RevIN). RevIN normalizes each input and later restores the saved statistics at the output of a forecaster. We cannot restore statistics at the output of a classifier, so we keep the statistics as an input stream instead. These statistics are computed per beat and per lead, not once per recording. That design choice answers a known limitation: Time-Series Foundation Model Embeddings as Means for Physiological Feature Extraction found that appending a global mean and standard deviation to normalized embeddings helped amplitude features by 14.28% but helped second-derivative morphology by only 2.60%.

The model has two paths. A shape encoder reads the instance-normalized waveform and is aligned with a CDAN-style discriminator. A small scale encoder reads the sequence of beat-level amplitudes and never receives the discriminator's gradient. The two are fused before the classifier.

The CDAN discriminator is normally conditioned on raw softmax outputs, which are skewed toward majority classes under imbalance. We will condition it on logit-adjusted predictions instead, adding $\tau \log \hat{\pi}_y$ with target priors estimated by a moving average, as in Logit-Adjusted Test-Time Adaptation under Partial Class Imbalance. That paper used the adjustment for test-time entropy minimization; we reuse it to clean the conditioning signal.

The scale stream needs a gain correction for each site. For each lead $\ell$ we estimate

$$\hat g_\ell = \frac{\mathrm{median}\{a_\ell(x) : x \in T,\ \hat y(x) = \text{normal}\}}{\mathrm{median}\{a_\ell(x) : x \in S,\ y(x) = \text{normal}\}},$$

where $a_\ell(x)$ is the median beat amplitude of lead $\ell$ in recording $x$, $S$ is the source set, $T$ is the unlabeled target set, and $\hat y(x)$ is the shape path's prediction. Target scale features are divided by $\hat g_\ell$. The estimate uses only predicted normals, so a target site with more hypertrophy patients does not inflate its estimated gain. A median over all recordings would be inflated in that situation.

Finally, the scale path receives a training signal on the target site. A teacher trained on raw source amplitudes is applied to gain-corrected target recordings. Its predictions for amplitude-defined classes are distilled into the student by matching temperature-scaled raw logits. We follow the design lesson of Normalization-Free Knowledge Distillation for Variable-Bit CSI Feedback in Massive MIMO. That paper found that distillation on normalized tensors did worse than no distillation, because normalization destroyed the scale information that mattered. Their setting was wireless channel reconstruction, so the transfer to ECG diagnosis is itself something we test.

The data come from the file's ECG resources. PTB-XL (Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL) is the source. Its 71 statements include voltage criteria and hypertrophy labels that are rare relative to normal ECGs. We create domain shift in two ways. The first is controlled: a target split of PTB-XL with simulated per-lead gain and impedance changes, plus resampled prevalence of the amplitude-defined classes. Here the true gain is known, so the calibration can be checked directly. The second is real: PTB-XL to Chapman–Shaoxing, evaluated on the overlapping label set. Measured feature annotations from PTB-XL+ supply ground-truth millivolt quantities for the probes; its commercial feature extractors agree with each other at correlation above 0.9 on global features.

Baselines

Source-only reference. The do-nothing reference is a source-only ResNet/Inception classifier trained on raw amplitudes and applied to the target site unchanged. In-domain on PTB-XL, ensembles of such networks reach a macro AUC of about 0.939 on diagnostic statements (Deep Learning for ECG Analysis). That number tells us how much room cross-site degradation leaves. No reported result found on Lacuna for cross-site ECG adaptation from PTB-XL to Chapman–Shaoxing or under simulated gain shift, so every adapted number will be measured by us against this reference.

Strongest existing competitors. These are CDAN+E and LADA. CDAN+E is the strongest conditional adversarial method in the file, at 87.7% on Office-31 versus 82.2% for DANN (Conditional Adversarial Domain Adaptation). LADA is the method built specifically for label-proportion mismatch (Using Latent Codes for Class Imbalance Problem in Unsupervised Domain Adaptation). No reported result found on Lacuna for either method on ECG. We will run both on the same backbone, the same raw-amplitude inputs, the same unlabeled target pool, and an equal hyperparameter search budget, with model selection by the same target-free validation rule.

Ablations. The ablations isolate each ingredient. The first applies the discriminator to both paths, which tests whether keeping scale out of the adversarial game is the cause of any gain. The second replaces beat-level scale with global mean and standard deviation, as in Time-Series Foundation Model Embeddings. The third replaces normal-anchored gain with the median over all target recordings. The fourth uses normalized-logit distillation or none. The fifth uses unadjusted CDAN conditioning.

Success criterion. The proposal beats the competitors if it raises per-class AUPRC on amplitude-defined minority classes by a margin larger than the variation across random seeds. It must do so while matching CDAN+E on rhythm classes within seed noise, and while keeping probe accuracy for millivolt quantities close to source-only levels.

Why not just…?

Why not just skip adaptation and train on raw amplitudes? Raw inputs help in-domain, as the Chapman–Shaoxing comparison shows (Deciphering Heartbeat Signatures). But a raw-amplitude model is exactly the one that site gain miscalibrates. A 20% amplifier difference moves a borderline recording across a voltage criterion. The controlled gain-shift split measures this directly. If source-only raw models turn out to be robust to realistic gain shifts, the motivation weakens and we will report that.

Why not just divide each site's signals by its median amplitude? This is the most serious threat, because it is a one-line form of our calibration. It fails only when prevalence of amplitude-defined classes differs between sites, since the site median then absorbs disease as if it were gain. Our experiments vary target prevalence over a controlled range and compare each gain estimate with the known simulated gain. If site-median scaling matches the normal-anchored estimate across that range, the calibration component is unnecessary. The contribution would then reduce to keeping scale out of the discriminator, and we would say so.

Why not just append mean and standard deviation to normalized features, then align? This was tested on physiological signals and recovered little fine morphology: 2.60% for second-derivative features (Time-Series Foundation Model Embeddings). A global variance also cannot represent ST deviation in one lead or voltage ratios across leads. The global-statistics ablation tests whether that holds for diagnosis as well as regression.

Why not just use LADA or logit adjustment alone? Both correct for differing class proportions, but neither stops the discriminator from erasing voltage. If imbalance were the whole problem, LADA would close the gap on amplitude-defined classes, and the millivolt probes would stay intact under LADA. The diagnostic study tests both predictions.

Decisive Experiments

The study is organized around three checks that could each falsify the idea.

The first check is the diagnostic. If DANN and CDAN+E do not reduce linear decodability of millivolt quantities, and do not cut AUPRC more on hypertrophy and voltage classes than on rhythm classes, then the stated mechanism is wrong and the factored model has no reason to exist.

The second check is the prevalence sweep on the controlled split. As the target prevalence of hypertrophy rises, gain estimation error should grow for the all-recording median and stay flat for the normal-anchored estimate. Per-class AUPRC should follow the same pattern.

The third check is the real transfer from PTB-XL to Chapman–Shaoxing on overlapping classes. The factored model should hold rhythm performance at CDAN+E's level while improving amplitude-defined classes. The ablations should attribute that improvement mainly to removing scale from the discriminator, rather than to the extra parameters of the scale path. A capacity-matched version, in which the scale path exists but also receives the discriminator's gradient, controls for this.