Skip to content
compressionKIT
Reference
HELIA

metrics

Reconstruction quality metrics for signal compression evaluation.

Machine-readable model

class

PRD

Python

Percent RMS difference metric with optional energy normalization.

compressionkit/evaluation/metrics.py:21

PRD(normalized: bool = True, name: str = 'prd', **kwargs={})

Percent RMS difference metric with optional energy normalization.

function

Compute scalar reconstruction metrics on two aligned signals.

compressionkit/evaluation/metrics.py:59

compute_signal_metrics(
original: np.ndarray,
reconstructed: np.ndarray,
*,
noise_power: float | None = None,
) -> dict[str, float]

Compute scalar reconstruction metrics on two aligned signals.

Parameters of compute_signal_metrics
NameTypeDefaultDescription
originalnp.ndarrayRequiredGround-truth signal (any shape; flattened).
reconstructednp.ndarrayRequiredReconstructed signal (same total size).
noise_powerfloat | NoneNoneOptional estimate of the *noise* contribution to the ground-truth power, in the same scale as ``mean(original**2)``. When provided, ``prdn_noise_percent`` is added to the result — this is PRD normalized by the *clean* signal power ``max(mean(orig^2) - noise_power, eps)`` rather than the raw signal power. It removes the unfair penalty applied to codecs that correctly remove noise from a noisy ground-truth.
function

Compute HR/HRV metrics for one PPG signal using physiokit.

compressionkit/evaluation/metrics.py:124

compute_ppg_physiokit_metrics(
signal: np.ndarray,
*,
sample_rate: int,
low_hz: float,
high_hz: float,
order: int,
min_peaks: int,
) -> dict[str, float] | None

Compute HR/HRV metrics for one PPG signal using physiokit.

function

Compare PPG pulse peak timing between paired original/reconstructed signals.

compressionkit/evaluation/metrics.py:204

summarize_ppg_peak_alignment(
originals: np.ndarray,
reconstructions: np.ndarray,
*,
sample_rate: int,
low_hz: float = 0.5,
high_hz: float = 8.0,
order: int = 3,
min_peaks: int = 5,
timing_tolerance_ms: float = 125.0,
) -> tuple[dict[str, float] | None, list[dict[str, Any] | None]]

Compare PPG pulse peak timing between paired original/reconstructed signals.

Peaks are detected through the same physiokit PPG path used for HR/HRV, then matched one-to-one within timing_tolerance_ms. This reports pulse preservation directly: precision catches extra invented pulses, recall catches missed pulses, and timing/IBI errors catch peak shifts that can degrade HRV even when waveform PRD is low.

function

Compare physiokit HR/HRV metrics between original and reconstructed signals.

compressionkit/evaluation/metrics.py:363

summarize_physiokit_alignment(
originals: np.ndarray,
reconstructions: np.ndarray,
*,
sample_rate: int,
low_hz: float,
high_hz: float,
order: int,
min_peaks: int,
) -> tuple[dict[str, float] | None, list[dict[str, Any] | None]]

Compare physiokit HR/HRV metrics between original and reconstructed signals.

function

Detect R-peaks and compute HR/HRV from a single ECG signal.

compressionkit/evaluation/metrics.py:461

compute_ecg_hr_hrv(
signal: np.ndarray,
*,
sample_rate: int,
min_peaks_for_hr: int = 2,
min_peaks_for_hrv: int = 3,
) -> dict[str, Any] | None

Detect R-peaks and compute HR/HRV from a single ECG signal.

Returns None when there are too few peaks to compute even HR. Otherwise returns num_peaks, hr_bpm, mean_rr_ms, peak_locations (sample indices), and — when at least min_peaks_for_hrv peaks are found — sdnn_ms and rmssd_ms.

function

Compare ECG HR/HRV/peak-timing between paired original and reconstructed signals.

compressionkit/evaluation/metrics.py:504

summarize_ecg_alignment(
originals: np.ndarray,
reconstructions: np.ndarray,
*,
sample_rate: int,
min_peaks_for_hr: int = 2,
min_peaks_for_hrv: int = 3,
timing_tolerance_ms: float = 10.0,
) -> tuple[dict[str, float] | None, list[dict[str, Any] | None]]

Compare ECG HR/HRV/peak-timing between paired original and reconstructed signals.

Parameters of summarize_ecg_alignment
NameTypeDefaultDescription
originalsnp.ndarrayRequiredIterable/array of ground-truth signals.
reconstructionsnp.ndarrayRequiredIterable/array of reconstructed signals (same N).
sample_rateintRequiredHz.
min_peaks_for_hrint2Minimum peaks required to report HR.
min_peaks_for_hrvint3Minimum peaks required to report HRV (SDNN/RMSSD).
timing_tolerance_msfloat10.0Threshold for "peak timing within tolerance".
Returns of summarize_ecg_alignment
TypeDescription
dict[str, float] | None``(summary, per_sample)``. ``summary`` is ``None`` if no pair was
list[dict[str, Any] | None]valid. ``per_sample`` is aligned with the inputs and contains
tuple[dict[str, float] | None, list[dict[str, Any] | None]]``None`` for pairs where either side lacked peaks.