Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / src /wisp /blocks.py
Zipeng365's picture
wisp-har 0.3.0: scikit-learn interface, recipe catalog, Optuna search, cost-accuracy figures
4731b11 verified
Raw History Blame Contribute Delete
1.8 kB
"""The three WISP-CIS representation blocks under their paper names.
Each function returns an unfitted kernel transformer configured exactly as inside
WISP-CIS (``wisp.cis_algorithms.StateRocketIntervalHMM``) for the given seed. They take
windows ``(n, T, C)`` and return ``(n, d)`` features; each standardises every window
and channel itself.
"""
from __future__ import annotations
from wisp.cpu.features import IntervalDistributionSketch, RandomConvSketch, WearableFeatureExtractor
__all__ = ["RandomConvolution", "IntervalSummary", "StateSpectral"]
def RandomConvolution(random_state: int = 42, n_kernels: int = 384) -> RandomConvSketch:
"""Paper block R: random dilated multichannel convolutions with PPV/max/mean/std pooling."""
return RandomConvSketch(n_kernels=int(n_kernels), random_state=int(random_state))
def IntervalSummary(random_state: int = 42, n_intervals: int = 24) -> IntervalDistributionSketch:
"""Paper block I: dyadic plus random intervals summarised by moments, slope and quantiles.
``random_state`` is the recipe seed; the CIS seed offset (+29) is applied here, so
``IntervalSummary(s)`` equals the I block of ``WISPRepresentation("cis", random_state=s)``.
"""
return IntervalDistributionSketch(n_random_intervals=int(n_intervals), random_state=int(random_state) + 29)
def StateSpectral() -> WearableFeatureExtractor:
"""Paper block S: magnitude/jerk, spectrum, autocorrelation, cross-axis and symbolic state features."""
return WearableFeatureExtractor(include_raw_stats=False, include_magnitude=True, include_jerk=True,
include_multiscale=False, include_spectral=True, include_autocorr=True,
include_cross_channel=True, include_symbolic=True, symbolic_bins=6)