Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / src /wisp_fast /funnel /cache.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
1.44 kB
"""Context for shared feature blocks during a search (``_SEARCH``); ``_ACTIVE`` is never set here."""
from contextvars import ContextVar
_SEARCH = ContextVar("wisp_search_memory", default=None)
_ACTIVE = ContextVar("wisp_feature_store", default=None)
def transform_blocks(blocks, X):
config = _ACTIVE.get()
shared_search = _SEARCH.get()
if shared_search is not None and config is None:
return shared_search.transform(blocks,X)
if config is None:
shared = len(blocks)>=2 and all(getattr(b,"zscore",False) and hasattr(b,"transform_normalized") for b in blocks)
if shared:
from wisp.cpu.features import _as_3d, _safe_zscore_per_window
from . import features as fx
if X.flags.c_contiguous:
z=fx._normalize(_as_3d(X))
return [b.transform_normalized(z) for b in blocks]
canonical=(fx.RandomConvSketch,fx.IntervalDistributionSketch,fx.WearableFeatureExtractor)
if fx._time_major_view(X) and all(type(b) in canonical and not b.fast_profile for b in blocks):
# Keep the original reduction layout; reuse only if the actual
# normalized buffer can enter all three packed backends.
z=_safe_zscore_per_window(_as_3d(X))
if z.flags.c_contiguous:return [b.transform_normalized(z) for b in blocks]
return [block.transform(X) for block in blocks]