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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Port of tinymind (C++) `examples/har_activity`: an LSTM classifies windows
//! of accelerometer samples into four activities (walking, walking upstairs,
//! walking downstairs, sitting), reading each window one sample at a time, and
//! the program writes the same files the C++ example writes, byte for byte:
//!
//! - stdout: the training log (mean |error| per epoch), the test accuracy and
//! two baselines (nearest centroid on per-axis mean and standard deviation,
//! which ignores sample order, and chance)
//! - `har_samples.csv`: one synthesized window per activity
//! - `har_loss.csv`: mean |error| per epoch
//! - `har_confusion.csv`: the test confusion matrix
//!
//! Network: 3 inputs -> 16 LSTM cells -> 4 sigmoid outputs, Q16.16, trained
//! at learning rate 0.1 without momentum, gradients clipped to [-1, 1]. The
//! windows are synthesized unless a `har.csv` file in the C++ example's format
//! (`window,t,ax,ay,az,label`) is found, as in the C++.
//!
//! Run: `cargo run --release --example har_activity -- [--readout-only]
//! [output_dir] [har.csv]` (default `output`, and `har.csv` in the current
//! directory). `--readout-only`, as in the C++, keeps the LSTM's input, gate
//! and recurrent weights at their initial values and trains only the
//! hidden-to-output weights.
use fs;
use ;
use PathBuf;