Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / src /wisp_fast /funnel /numeric.py
Zipeng365's picture
wisp-har 0.4.0: WISP-Funnel search and the adaptive HMM switch (default decoder)
93a9282 verified
Raw History Blame Contribute Delete
885 Bytes
"""Numeric geometry (state tables, quantile levels, frequency bands) shared by the feature blocks."""
from functools import lru_cache
import numpy as np
@lru_cache(maxsize=4)
def _state_table(length):
den = np.maximum(np.arange(length + 1), 1)[:, None]
p = np.arange(length + 1, dtype=np.float64)[None, :] / den
return np.stack((p, p * np.log(p + 1e-12)), axis=-1)
@lru_cache(maxsize=128)
def _state_levels(length,bins):
pos = (length-1)*np.linspace(0,1,bins+1)[1:-1]
lo = pos.astype(np.intp)
return lo, np.minimum(lo+1,length-1), pos-lo
@lru_cache(maxsize=64)
def _frequency_plan(time,bands):
freq=np.fft.rfftfreq(time)
pairs=[(0,0) if np.isnan(lo) or np.isnan(hi) else
(int(freq.searchsorted(lo)),int(freq.searchsorted(hi))) for lo,hi in bands]
return freq,np.array([(l,max(l,r)) for l,r in pairs],dtype=np.float64).reshape(-1,2)