Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
File size: 885 Bytes
93a9282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""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)