Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / tests /conftest.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.79 kB
"""Shared fixtures for the public-interface tests.
Synthetic windows below are software fixtures, not HAR evidence. Tests that compare with
saved paper results need the frozen fold exports and the result CSVs; they run only when
``WISP_FROZEN_DATA`` (root of ``<dataset>/fold<k>/{train,valid,test}.npz``) is set.
"""
from __future__ import annotations
import os
from pathlib import Path
import numpy as np
import pytest
ROOT = Path(__file__).resolve().parents[1]
def make_windows_fixture(n=90, T=64, C=3, K=3, seed=0, subjects=6, offset=0):
rng = np.random.default_rng(seed)
y = np.resize(np.arange(K), n)
rng.shuffle(y)
t = np.arange(T)
X = np.stack([np.stack([np.sin(2 * np.pi * (c + 1 + k) * t / T + rng.normal()) for c in range(C)], 1)
for k in y]) + rng.normal(0, .3, (n, T, C))
groups = np.repeat(np.arange(subjects), int(np.ceil(n / subjects)))[:n] + offset
time_index = np.concatenate([np.arange((groups == s).sum()) for s in np.unique(groups)]).astype(float)
return X, y, groups, time_index
@pytest.fixture(scope="session")
def train_windows():
return make_windows_fixture(seed=0)
@pytest.fixture(scope="session")
def test_windows():
return make_windows_fixture(seed=1, offset=50)
@pytest.fixture(scope="session")
def valid_windows():
return make_windows_fixture(n=36, seed=5, subjects=2, offset=100)
def frozen_root():
root = os.environ.get("WISP_FROZEN_DATA")
return Path(root) if root else None
def saved_results_dir():
root = os.environ.get("WISP_SAVED_RESULTS")
return Path(root) if root else ROOT / "results"
requires_frozen = pytest.mark.skipif(frozen_root() is None,
reason="set WISP_FROZEN_DATA to the frozen fold exports to run this check")