UCI-HAR(行動認識)データセット
load_uci_har
Section titled “load_uci_har”実体: griffith_logic.datasets.har.load_uci_har(関数)
def load_uci_har( root: str | None = None, download: bool = True, return_subjects: bool = False,)UCI-HAR の生 Inertial Signals(9ch × 128step)を読む。
既定の置き場所は repo 直下の data-uci-har/(resolve_data_root と同じ解決規則)。
har_raw.npz があればそれだけを読む。無ければ UCI HAR Dataset/ の
テキストから読んで har_raw.npz を作り、そのディレクトリも無ければ
zip(約 60MB)をダウンロードして展開する。
引数
root— データ置き場。None ならdata-uci-har/を自動解決するdownload— 手元に無いときダウンロードしてよいか。False なら 見つからない場合FileNotFoundErrorを送出するreturn_subjects— True なら被験者 ID(1..30)の配列も返す
戻り値
(x_train, y_train, x_test, y_test)。x_* は float32 の
(N, 9, 128)(チャネル順は UCI_HAR_CHANNELS)、y_* は 0..5 の int64。
return_subjects=True のときは末尾に subject_train, subject_test
(int64、各窓を撮った被験者の ID)を足した 6 要素のタプルを返す。
例外
FileNotFoundError: データが無く download=False のとき
このAPIを使っている例
- 行動認識(UCI-HAR、スマホ加速度) —
examples/27_har.py
fit_thermometer_thresholds
Section titled “fit_thermometer_thresholds”実体: griffith_logic.datasets.har.fit_thermometer_thresholds(関数)
def fit_thermometer_thresholds(x_train: np.ndarray, n_thresholds: int = 4) -> np.ndarray訓練データの分位点から、チャネルごとの温度計閾値を決める。
各チャネルの全サンプル・全時刻の値を 1 つの分布とみなし、
i / (n_thresholds + 1)(i = 1..n_thresholds)分位点を閾値にする。
4 閾値なら 20 / 40 / 60 / 80 パーセンタイルである。分位点で切るので、
どのビットも訓練データ上でおおよそ偏りなく立つ(情報を使い切りやすい)。
引数
x_train—(N, C, L)の実数信号。訓練分割だけを渡すこと (テストの分布を閾値に混ぜると評価が楽観的になる)n_thresholds— 1 チャネルあたりの閾値数(ビット数)
戻り値
float32 の (C, n_thresholds)。各行は昇順。
このAPIを使っている例
- 行動認識(UCI-HAR、スマホ加速度) —
examples/27_har.py
thermometer_encode
Section titled “thermometer_encode”実体: griffith_logic.datasets.har.thermometer_encode(関数)
def thermometer_encode( x: np.ndarray, n_thresholds: int = 4, thresholds: np.ndarray | None = None,) -> np.ndarray実数信号を温度計符号(単調に積み上がる 0/1 ビット)へ変換する。
チャネル c の値 v に対し、閾値 θ[c, 0] <= θ[c, 1] <= ... ごとに
bit_t = (v > θ[c, t]) を並べる。閾値が昇順なので、bit_t = 1 なら
それより低い閾値のビットはすべて 1 になる(温度計のように下から埋まる)。
閾値の決め方は 2 通り。thresholds を渡せばそれを使う(通常は
fit_thermometer_thresholds(x_train, n) で訓練データの分位点から作った
ものを、訓練・テスト両方に同じ値で適用する)。None のときは 入力 x 自身の
分位点を使う(fit_thermometer_thresholds と同じ式)。テスト分割にこれを
使うと分布がリークするので、評価には必ず訓練由来の閾値を渡すこと。
引数
x—(N, C, L)の実数信号(float 配列)n_thresholds—thresholdsが None のときの閾値数。thresholdsを 渡す場合は無視されるthresholds—(C, T)または(T,)の昇順の閾値。(T,)は全チャネル共通
戻り値
float32 の (N, C, L, T)(値は 0.0 / 1.0)。
reshape(N, -1) すると C × L × T ビットの 1 本の入力線になる
(並びは チャネル → 時刻 → 閾値 の順)。
このAPIを使っている例
- 行動認識(UCI-HAR、スマホ加速度) —
examples/27_har.py