Skip to main content

Evaluation metrics and interactive reports for synthetic ECG quality assessment

Project description

ECGEN-Eval

Evaluation metrics and interactive HTML reports for synthetic ECG quality assessment. Part of the ECGEN research suite (ECGEN-FM, ECGEN-VAE, Pulse2Pulse).

Installation

pip install -e .           # core
pip install -e ".[dev]"    # + pytest, black, ruff

Optional dependencies:

pip install wfdb           # for loading PTB-XL / WFDB records
pip install scipy          # for Welch PSD, resampling, and R-peak detection (recommended)
pip install dtaidistance   # fast Cython DTW (falls back to pure-Python)

Quick start

import numpy as np
from ecgen_eval import load_ecg_npy, AVAILABLE_METRICS

# Load model outputs (shape: N × L × T)
real  = load_ecg_npy("real_ecgs.npy",  label="PTB-XL")
synth = load_ecg_npy("synth_ecgs.npy", label="ECGEN-FM")

# Compute a metric
mmd = AVAILABLE_METRICS["mmd"]()
result = mmd.compute(real.data, synth.data, lead_names=real.lead_names)
print(f"MMD = {result.score:.6f}")
print(result.per_lead_scores)

Data loaders

Function Input Use case
load_ecg_npy(path) .npy / .npz (N, L, T) ECGEN-FM, ECGEN-VAE, Pulse2Pulse outputs
load_ecg_wfdb(dir) WFDB .hea/.dat records PTB-XL and PhysioNet datasets
load_ecg_folder(path) auto-detected Any of the above + CSV

load_ecg_folder auto-detects the format based on file extensions.

Metrics

All metrics are available via AVAILABLE_METRICS["key"]() and return a MetricResult with .score, .per_lead_scores, and .extra.

Original metrics

Key Name Lower / Higher Paper
mmd Maximum Mean Discrepancy Lower ↓ Gretton et al., JMLR 2012
dtw Dynamic Time Warping Lower ↓ Berndt & Clifford, KDD 1994
prd Percent Root-mean-square Difference Lower ↓ Zigel et al., IEEE TBME 2000
psd PSD Divergence (Jensen-Shannon) Lower ↓ Welch, IEEE Trans Audio 1967 · Applied: Golany & Radinsky, AAAI 2019
fd Fréchet Distance Lower ↓ Heusel et al., NeurIPS 2017 · Applied: Thambawita et al., Sci Rep 2021

New metrics (literature review 2018 – 2025)

Key Name Lower / Higher Paper
psnr Peak Signal-to-Noise Ratio Higher ↑ Huynh-Thu & Ghanbari, Electron Lett 2008
ssim Structural Similarity Index (1-D) Higher ↑ Wang et al., IEEE TIP 2004 · ECG: Hayn et al., Physiol Meas 2018
swd Sliced Wasserstein Distance Lower ↓ Rabin et al., LNCS 2011 · Kolouri et al., NeurIPS 2019
mae Mean Absolute Error (nearest-neighbour) Lower ↓ Zigel et al., IEEE TBME 2000
hrv Heart Rate Variability (SDNN/rMSSD/pNN50) Lower ↓ Task Force ESC/NASPE, Circulation 1996
pr_dist Distribution Precision & Recall Higher ↑ Kynkäänniemi et al., NeurIPS 2019
sqi Signal Quality Index (QRS template) Higher ↑ Clifford et al., CinC 2017
nn_dist Nearest-Neighbour Distance (memorisation) Lower ↓ Meehan et al., AISTATS 2020
heart_rate Heart Rate Distribution (JS divergence) Lower ↓ Pan & Tompkins, IEEE TBME 1985 · Applied: Golany & Radinsky, AAAI 2019
spectral_entropy Spectral Entropy Divergence Lower ↓ Inouye et al., EEG Clin Neurophysiol 1991

CLI

# Run all metrics and generate interactive HTML report
ecgen-eval eval \
  --real   /path/to/real_ecgs.npy \
  --synthetic /path/to/model1_ecgs.npy \
  --synthetic /path/to/model2_ecgs.npy \
  --output report.html

# List available metrics
ecgen-eval list-metrics

# ECG waveform comparison only (no metrics)
ecgen-eval visualize \
  --real /path/to/real.npy \
  --synthetic /path/to/synth.npy \
  --compare-mode overlay

Key options for eval:

  • --metrics mmd prd psd psnr hrv — run a subset of metrics
  • --fs 500 — sampling frequency
  • --n-samples 5 — ECG samples shown in gallery
  • --offline — embed Plotly.js for offline viewing
  • --max-samples 500 — cap loaded recordings per folder

Report

The HTML report includes:

  • Dataset summary table
  • Interactive ECG gallery (overlay / side-by-side / grid)
  • Per-metric: score table, per-lead bar chart, PSD overlay (PSD metric), violin plot (DTW)
  • Radar chart summarising all metrics
  • Metrics summary table with Download CSV button
  • References / citations

Running tests

pytest tests/ -v

Project structure

ecgen_eval/
├── data/
│   ├── dataset.py      ECGDataset container
│   └── loader.py       npy / WFDB / CSV loaders
├── metrics/
│   ├── base.py         BaseMetric + MetricResult
│   ├── mmd.py          MMD
│   ├── dtw.py          DTW
│   ├── prd.py          PRD
│   ├── psd.py          PSD divergence
│   ├── fd.py           Fréchet Distance
│   ├── psnr.py         PSNR
│   ├── ssim.py         1-D SSIM
│   ├── swd.py          Sliced Wasserstein Distance
│   ├── mae.py          MAE / RMSE
│   ├── hrv.py          HRV statistics (SDNN, rMSSD, pNN50)
│   ├── pr_dist.py      Distribution Precision & Recall
│   ├── sqi.py          Signal Quality Index
│   ├── nn_dist.py      Nearest-Neighbour Distance
│   ├── heart_rate.py   Heart Rate Distribution
│   └── spectral_entropy.py  Spectral Entropy Divergence
├── visualization/
│   ├── ecg_paper.py    ECG graph-paper figure factory
│   ├── ecg_waveform.py Waveform comparison plots
│   └── metric_plots.py Bar, violin, PSD overlay, radar
├── report/
│   └── html_report.py  HTML report generator
└── cli.py              Click CLI entry point
tests/
├── conftest.py
├── test_dataset.py
├── test_loader.py
└── test_metrics.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecgen_eval-0.2.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ecgen_eval-0.2.0-py3-none-any.whl (74.2 kB view details)

Uploaded Python 3

File details

Details for the file ecgen_eval-0.2.0.tar.gz.

File metadata

  • Download URL: ecgen_eval-0.2.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ecgen_eval-0.2.0.tar.gz
Algorithm Hash digest
SHA256 268709860bd275bb87d86314c3bcdc953d1231b7fb790cea064eb473d5f38cef
MD5 c46343f5df6811fa62f0753c0cf4accd
BLAKE2b-256 8f72a977cd22dc6ff56aaa8bd211ab917c15c787c0305bd7e24b9d6f59037ad1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ecgen_eval-0.2.0.tar.gz:

Publisher: publish.yml on vlbthambawita/ECGEN-Eval

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ecgen_eval-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ecgen_eval-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 74.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ecgen_eval-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2eed546a61301aaca946d3cd3045e0ca95f0a560ce633e531da583b70bb0e91e
MD5 5ab308acb575d69d8ff36d337410df46
BLAKE2b-256 5455d6daea6edb6945b6182bacb01703b678a6a3833963636b987a45cb5f1678

See more details on using hashes here.

Provenance

The following attestation bundles were made for ecgen_eval-0.2.0-py3-none-any.whl:

Publisher: publish.yml on vlbthambawita/ECGEN-Eval

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page