streamsim.src.detectors.hr_anomaly module

Robust Heart Rate Anomaly Detector

This module provides a streaming change point detector specifically designed for identifying persistent heart rate deviations from a fixed baseline established during an initial warmup period.

Detection Method:

The detector collects heart rate samples during a configurable warmup phase to establish a baseline mean and standard deviation. Subsequent samples are compared against this baseline using z-scores. A change point is confirmed only after a configurable streak of consecutive outliers, reducing false positives from transient noise.

Important Dependencies:
  • collections.deque: Efficient circular buffer for warmup data

  • streamsim.src.core.interfaces.StreamingChangePointDetector: Base interface

Author: F.Feenstra

class streamsim.src.detectors.hr_anomaly.HeartRateAnomalyDetector(threshold_std: float = 3.0, warmup_beats: int = 15, confirmation_count: int = 3, recovery_count: int = 5, baseline_adaptation: float = 0.0)[source]

Bases: StreamingChangePointDetector

Detects heart rate deviations against a FIXED baseline established during warmup.

Unlike rolling window detectors, this maintains the original baseline and only updates it slowly (or not at all), making it sensitive to sudden changes that persist over time.

property drift_detected: bool

Check if a change point was recently detected.

reset() None[source]

Reset internal state.

update(feature_value: float) bool[source]

Update detector with new heart rate value.

Parameters:

feature_value (float) – Current heart rate in BPM.

Returns:

True if a significant deviation is confirmed.

Return type:

bool