WaveDelineationMetrics¶
- class torch_ecg.components.WaveDelineationMetrics(macro: bool = True, tol: float = 0.15, extra_metrics: Callable | None = None)[source]¶
Bases:
Metrics
Metrics for the task of ECG wave delineation.
- Parameters:
macro (bool, default True) – Whether to use macro-averaged metrics or not.
tol (float, default 0.15) – Tolerance for the duration of the waveform, with units in seconds.
extra_metrics (callable, optional) –
Extra metrics to compute, has to be a function with signature
def extra_metrics( labels: Sequence[Union[Sequence[int], np.ndarray]], outputs: Sequence[Union[Sequence[int], np.ndarray]], fs: int ) -> dict
- compute(labels: ndarray | Tensor, outputs: ndarray | Tensor, class_map: Dict[str, int], fs: int, mask_format: str = 'channel_first', tol: float | None = None) WaveDelineationMetrics [source]¶
Compute metrics for the task of ECG wave delineation (sensitivity, precision, f1_score, mean error and standard deviation of the mean errors) for multiple evaluations.
- Parameters:
labels (numpy.ndarray or torch.Tensor) – Ground truth masks, of shape
(n_samples, n_channels, n_timesteps)
.outputs (numpy.ndarray or torch.Tensor) – Predictions corresponding to labels, of the same shape.
class_map (dict) – Class map, mapping names to waves to numbers from 0 to n_classes-1, the keys should contain “pwave”, “qrs”, “twave”.
fs (numbers.Real) – Sampling frequency of the signal corresponding to the masks, used to compute the duration of each waveform, and thus the error and standard deviations of errors.
mask_format (str, default "channel_first") – Format of the mask, one of the following: “channel_last” (alias “lead_last”), or “channel_first” (alias “lead_first”).
tol (float, optional) – Tolerance for the duration of the waveform, with units in seconds. Defaults to self.tol.
- Returns:
self – The metrics object itself with the computed metrics.
- Return type: