Four worked examples on physiological data. Each pairs a measure to the kind of
change it detects best. Runnable end-to-end in
examples/medical.py
(uses synthetic data so it runs with no files — swap in pd.read_csv(...) for
your own recordings).
Reduced beat-to-beat variability is clinically meaningful. Sample entropy drops when a healthy, variable heart rate becomes abnormally regular.
import pandas as pd
from entroscope import sample
bpm = pd.read_csv("ecg.csv")["bpm"]
regularity = sample.rolling(bpm, window=100, m=2, r=0.2)
# healthy-phase mean ~2.34 -> regular-phase mean ~1.32 : a clear dropA seizure shows up as the trace collapsing onto a dominant rhythm. Both permutation and spectral entropy fall as broadband background activity gives way to a single frequency.
from entroscope import permutation, spectral
eeg = pd.read_csv("eeg.csv")["uv"]
perm = permutation.rolling(eeg, window=100, order=4)
spec = spectral.rolling(eeg, window=100, sf=50.0) # sf = sampling frequency (Hz)
# background -> seizure: permutation 4.44 -> 2.68, spectral 5.03 -> 0.63Approximate entropy rises as a steady breathing cycle breaks down into irregular, labored breathing.
from entroscope import approximate
chest = pd.read_csv("respiration.csv")["expansion"]
irregularity = approximate.rolling(chest, window=80, m=2, r=0.2)
# steady-phase mean ~0.32 -> irregular-phase mean ~0.49 : a riseDifferential entropy is a function of spread, so it rises when glucose variability increases — a shift from well-controlled to a volatile regime.
from entroscope import differential
glucose = pd.read_csv("cgm.csv")["mgdl"]
variability = differential.rolling(glucose, window=48, dist="normal")
# controlled-phase mean ~2.98 -> volatile-phase mean ~5.29 : a clear rise