20 #define ESP_EVENT(s)                                                \    21     ofLogVerbose() << "[" << ofGetTimestampString() << "] " << (s)    23 class ofApp : 
public ofBaseApp, 
public GRT::Observer<GRT::ErrorLogMessage> {
    40     void dragEvent(ofDragInfo dragInfo) 
final;
    44         tuneable_parameters_.push_back(t);
    50     virtual void notify(
const ErrorLogMessage& data) 
final {
    51         status_text_ = data.getMessage();
    55         buffer_size_ = buffer_size;
    64         kTrainingHistoryRecording,
    73     string getAppStateInstruction() 
const;
    85     inline Fragment getAppView(AppState state) {
    87             case AppState::kCalibration:
    89             case AppState::kPipeline:
    91             case AppState::kTraining:
    92             case AppState::kTrainingRenaming:
    93             case AppState::kTrainingHistoryRecording:
    94             case AppState::kTrainingRelabelling:
    96             case AppState::kAnalysis:
    98             case AppState::kPrediction:
   100             case AppState::kConfiguration:
   101                 return CONFIGURATION;
   108     void drawInputs(uint32_t, uint32_t, uint32_t, uint32_t);
   109     void drawLiveFeatures(uint32_t, uint32_t, uint32_t, uint32_t);
   111     void drawCalibration();
   112     void drawLivePipeline();
   113     void drawTrainingInfo();
   114     void enableTrainingSampleGUI(
bool);
   116     void drawPrediction();
   121     void useOStream(
OStream& stream);
   126         use_leave_one_out_scoring_ = enable;}
   128     friend void useCalibrator(
Calibrator &calibrator);
   129     friend void usePipeline(GRT::GestureRecognitionPipeline &pipeline);
   136     friend void useTrainingDataAdvice(
string advice);
   146     bool setup_finished_ = 
false;
   149     const uint32_t kNumMaxLabels_ = 9;
   154     uint32_t buffer_size_ = 256;
   159     GRT::GestureRecognitionPipeline *pipeline_;
   163     uint32_t num_pipeline_stages_;
   168     uint32_t num_preprocessing_modules_;
   169     uint32_t num_feature_modules_;
   170     vector<double> getLastStageProcessedData() 
const;
   172     vector<Tuneable*> tuneable_parameters_;
   177     GRT::MatrixDouble sample_data_;
   178     GRT::MatrixDouble input_data_;
   179     std::mutex input_data_mutex_;  
   181     GRT::MatrixDouble test_data_;
   186     float training_accuracy_;
   187     int predicted_label_; CircularBuffer<int> predicted_label_buffer_;
   188     vector<double> predicted_class_distances_;
   189     CircularBuffer<vector<double>> predicted_class_distances_buffer_;
   191     vector<double> predicted_class_likelihoods_;
   192     CircularBuffer<vector<double>> predicted_class_likelihoods_buffer_;
   194     vector<UINT> predicted_class_labels_;
   195     CircularBuffer<vector<UINT>> predicted_class_labels_buffer_;
   197     vector<UINT> test_data_predicted_class_labels_;
   199     vector<double> class_distance_values_;
   200     vector<double> class_likelihood_values_;
   206     void onDataIn(GRT::MatrixDouble in);
   207     vector<OStream *> ostreams_;
   208     vector<OStreamVector *> ostreamvectors_;
   215     bool enable_history_recording_ = 
false;
   216     bool is_in_feature_view_ = 
false;
   221     int rename_target_ = -1;
   222     string rename_title_;
   223     string display_title_;  
   229     uint32_t relabel_source_;
   230     string relabel_source_title_;
   236     void setStatus(
const string& msg) {
   246     ofxDatGuiDropdown *serial_selection_dropdown_;
   247     void onSerialSelectionDropdownEvent(ofxDatGuiDropdownEvent e);
   253     vector<ofxGrtTimeseriesPlot> plot_live_features_;  
   254     ofxGrtTimeseriesPlot plot_inputs_snapshot_;  
   260     void onInputPlotValueSelection(
   268     ofxGrtTimeseriesPlot plot_raw_;
   269     vector<Plotter> plot_calibrators_;
   276     vector<ofxGrtTimeseriesPlot> plot_pre_processed_;
   277     vector<vector<ofxGrtTimeseriesPlot>> plot_features_;
   284     ofxGrtTimeseriesPlot plot_testdata_window_;
   285     Plotter plot_testdata_overview_;
   287     void updateTestWindowPlot();
   288     void runPredictionOnTestData();
   295     vector<Plotter> plot_samples_;
   296     vector<Plotter> plot_samples_snapshots_;
   297     vector<std::string> plot_samples_info_;
   299     void updatePlotSamplesSnapshot(
int num, 
int row = -1);
   302     bool is_final_features_too_many_ = 
false;
   303     vector<vector<Plotter>> plot_sample_features_;
   304     void toggleFeatureView();
   305     void populateSampleFeatures(uint32_t sample_index);
   306     vector<pair<double, double>> sample_feature_ranges_;
   308     vector<int> plot_sample_indices_; 
   310     vector<pair<ofRectangle, ofRectangle>> plot_sample_button_locations_;
   312     vector<ofxDatGui *> training_sample_guis_;
   313     void renameTrainingSample(
int num);
   314     void renameTrainingSampleDone();
   315     void deleteTrainingSample(
int num);
   316     void trimTrainingSample(
int num);
   317     void relabelTrainingSample(
int num);
   318     void deleteAllTrainingSamples(
int num);
   319     void doRelabelTrainingSample(uint32_t from, uint32_t to);
   325     void onBackgroundColorPickerEvent(ofxDatGuiColorPickerEvent e) {
   326         background_color_ = e.color;
   329         plot_inputs_.setBackgroundColor(background_color_);
   330         for (
auto& p : plot_live_features_) {
   331             p.setBackgroundColor(background_color_);
   333         plot_inputs_snapshot_.setBackgroundColor(background_color_);
   334         plot_raw_.setBackgroundColor(background_color_);
   335         for (
auto& p : plot_calibrators_) {
   336             p.setBackgroundColor(background_color_);
   338         for (
auto& p : plot_pre_processed_) {
   339             p.setBackgroundColor(background_color_);
   341         for (
auto& ps : plot_features_) {
   343                 p.setBackgroundColor(background_color_);
   346         plot_testdata_window_.setBackgroundColor(background_color_);
   349         for (
auto& p : plot_samples_) {
   350             p.setBackgroundColor(background_color_);
   352         for (
auto& p : plot_samples_snapshots_) {
   353             p.setBackgroundColor(background_color_);
   355         for (
auto& ps : plot_sample_features_) {
   357                 p.setBackgroundColor(background_color_);
   360         plot_class_likelihoods_.setBackgroundColor(background_color_);
   361         for (
auto& p : plot_class_distances_) {
   362             p.setBackgroundColor(background_color_);
   365     ofColor background_color_;
   367     void onTextColorPickerEvent(ofxDatGuiColorPickerEvent e) {
   368         text_color_ = e.color;
   371         plot_inputs_.setTextColor(text_color_);
   372         for (
auto& p : plot_live_features_) {
   373             p.setTextColor(text_color_);
   375         plot_inputs_snapshot_.setTextColor(text_color_);
   376         plot_raw_.setTextColor(text_color_);
   377         for (
auto& p : plot_calibrators_) {
   378             p.setTextColor(text_color_);
   380         for (
auto& p : plot_pre_processed_) {
   381             p.setTextColor(text_color_);
   383         for (
auto& ps : plot_features_) {
   385                 p.setTextColor(text_color_);
   388         plot_testdata_window_.setTextColor(text_color_);
   391         for (
auto& p : plot_samples_) {
   392             p.setTextColor(text_color_);
   394         for (
auto& p : plot_samples_snapshots_) {
   395             p.setTextColor(text_color_);
   397         for (
auto& ps : plot_sample_features_) {
   399                 p.setTextColor(text_color_);
   402         plot_class_likelihoods_.setTextColor(text_color_);
   403         for (
auto& p : plot_class_distances_) {
   404             p.setTextColor(text_color_);
   409     void onGridColorPickerEvent(ofxDatGuiColorPickerEvent e) {
   410         ofColor grid_color(e.color.r, e.color.g, e.color.b, 0x20);
   413         plot_inputs_.setGridColor(grid_color);
   414         for (
auto& p : plot_live_features_) {
   415             p.setGridColor(grid_color);
   417         plot_inputs_snapshot_.setGridColor(grid_color);
   418         plot_raw_.setGridColor(grid_color);
   419         for (
auto& p : plot_calibrators_) {
   420             p.setGridColor(grid_color);
   422         for (
auto& p : plot_pre_processed_) {
   423             p.setGridColor(grid_color);
   425         for (
auto& ps : plot_features_) {
   427                 p.setGridColor(grid_color);
   430         plot_testdata_window_.setGridColor(grid_color);
   433         for (
auto& p : plot_samples_) {
   434             p.setGridColor(grid_color);
   436         for (
auto& p : plot_samples_snapshots_) {
   437             p.setGridColor(grid_color);
   439         for (
auto& ps : plot_sample_features_) {
   441                 p.setGridColor(grid_color);
   444         plot_class_likelihoods_.setGridColor(grid_color);
   445         for (
auto& p : plot_class_distances_) {
   446             p.setGridColor(grid_color);
   450     void onLineWidthSliderEvent(ofxDatGuiSliderEvent e) {
   451         ofSetLineWidth(e.value);
   460     vector<InteractiveTimeSeriesPlot> plot_class_distances_;
   461     void onClassLikelihoodsPlotValueHighlight(
   463     void onClassDistancePlotValueHighlight(
   470     void saveTuneables(ofxDatGuiButtonEvent e);
   471     void loadTuneables(ofxDatGuiButtonEvent e);
   472     bool saveTuneablesWithPrompt();
   473     bool saveTuneables(
const string& filename);
   474     bool loadTuneablesWithPrompt();
   475     bool loadTuneables(
const string& filename);
   476     bool should_save_tuneables_;
   479     bool savePipelineWithPrompt();
   480     bool savePipeline(
const string& filename);
   481     bool loadPipelineWithPrompt();
   482     bool loadPipeline(
const string& filename);
   483     bool should_save_pipeline_;
   486     bool saveCalibrationDataWithPrompt();
   487     bool saveCalibrationData(
const string& filename);
   488     bool loadCalibrationDataWithPrompt();
   489     bool loadCalibrationData(
const string& filename);
   491     bool should_save_calibration_data_;
   493     bool saveTrainingDataWithPrompt();
   494     bool saveTrainingData(
const string& filename);
   495     bool loadTrainingDataWithPrompt();
   496     bool loadTrainingData(
const string& filename);
   498     bool should_save_training_data_;
   500     bool saveTestDataWithPrompt();
   501     bool saveTestData(
const string& filename);
   502     bool loadTestDataWithPrompt();
   503     bool loadTestData(
const string& filename);
   505     bool should_save_test_data_;
   512     const string kCalibrationDataFilename = 
"CalibrationData.grt";
   515     const string kTuneablesFilename       = 
"TuneableParameters.grt";
   516     string save_path_ = 
"";
   520     void saveAll(
bool saveAs = 
false);
   525     std::thread training_thread_;
   526     bool is_training_scheduled_;
   527     std::uint64_t schedule_time_;
   529     void beginTrainModel();
   531     void afterTrainModel();
   536     void scoreTrainingData(
bool leaveOneOut);
   537     void scoreImpactOfTrainingSample(
int label, 
const MatrixDouble &sample);
   538     bool use_leave_one_out_scoring_ = 
true;
   540     double true_positive_threshold_;
   541     double false_negative_threshold_;
   546     string getTrainingDataAdvice();
   547     string training_data_advice_ = 
"";
   549     void updateEventReceived(ofEventArgs& arg);  
   550     uint32_t update_counter_ = 0;
   551     std::shared_ptr<ofConsoleFileLoggerChannel> logger_;
   558         app->renameTrainingSample(num);
   561         app->deleteTrainingSample(num);
   564         app->trimTrainingSample(num);
   567         app->relabelTrainingSample(num);
   570         app->deleteAllTrainingSamples(num);
 Functions for specifying parameters that can be tuned by the user. 
void setup() final
Definition: ofApp.cpp:159
double t
Definition: user_accelerometer_walk_detection.cpp:78
void useTrainingDataAdvice(string advice)
Provide the user with custom advice on collecting training data. 
Definition: ofApp.cpp:2706
Definition: plotter.h:182
void gotMessage(ofMessage msg) final
Definition: ofApp.cpp:2611
void update() final
Definition: ofApp.cpp:1303
void trimButtonPressed(ofxDatGuiButtonEvent e)
Definition: ofApp.h:563
Calibrator calibrator
Definition: user_accelerometer_gestures.cpp:8
TrainingDataManager class that manages the training data and abstracts out common operations on the d...
TrainingSampleGuiListener(ofApp *app, int num)
Definition: ofApp.h:556
Definition: tuneable.h:21
void mouseDragged(int x, int y, int button) final
Definition: ofApp.cpp:2499
void mouseExited(int x, int y) final
Definition: ofApp.cpp:2602
Base class for output streams that forward ESP prediction results to other systems. 
Definition: ostream.h:43
Specifies data samples and code used to calibrate incoming sensor data. 
Definition: calibrator.h:121
void setBufferSize(uint32_t buffer_size)
Definition: ofApp.h:54
friend void setTruePositiveWarningThreshold(double threshold)
Only warn (highlight the confusion score) if the true positive rate is smaller than the threshold...
Definition: ofApp.cpp:2714
constexpr char kTrainingDataFilename[]
Definition: cli.cpp:13
TrainingSampleCheckerResult(* TrainingSampleChecker)(const GRT::MatrixDouble &)
function that takes a constant reference to a GRT MatrixDouble and returns a TrainingSampleCheckerRes...
Definition: training.h:54
VectorDouble threshold(VectorDouble in)
Definition: user_accelerometer_walk_detection.cpp:79
void useTrainingSampleChecker(TrainingSampleChecker checker)
Register a function for checking training samples. 
Definition: ofApp.cpp:2702
#define ESP_EVENT(s)                                                                                            
Definition: ofApp.h:20
TrainingDataManager class encloses GRT::TimeSeriesClassificationData and improves upon by adding util...
Definition: training-data-manager.h:38
ASCIISerialStream stream(115200, 3)
ofApp()
Definition: ofApp.cpp:141
void relabelButtonPressed(ofxDatGuiButtonEvent e)
Definition: ofApp.h:566
void exit() final
Definition: ofApp.cpp:2008
void dragEvent(ofDragInfo dragInfo) final
Definition: ofApp.cpp:2616
void windowResized(int w, int h) final
Definition: ofApp.cpp:2607
GestureRecognitionPipeline pipeline
Definition: user_accelerometer_gestures.cpp:7
Base class for output streams that forward ESP pipeline output to other systems. 
Definition: ostream.h:60
void useLeaveOneOutScoring(bool enable=true)
Whether or not to do leave-one-out scoring of training data. 
Definition: ofApp.cpp:2710
void setTextColor(ofColor color)
Definition: plotter.h:236
void useCalibrator(Calibrator &calibrator)
Definition: ofApp.cpp:2684
void keyReleased(int key) final
Definition: ofApp.cpp:2315
friend void useInputStream(InputStream &stream)
Definition: ofApp.cpp:2668
void deleteAllButtonPressed(ofxDatGuiButtonEvent e)
Definition: ofApp.h:569
constexpr char kPipelineFilename[]
Definition: cli.cpp:15
friend void setFalseNegativeWarningThreshold(double threshold)
Only warn (highlight the confusion score) if the false negative rate is larger than the threshold...
Definition: ofApp.cpp:2718
Definition: plotter.h:269
constexpr char kTestDataFilename[]
Definition: cli.cpp:14
void usePipeline(GRT::GestureRecognitionPipeline &pipeline)
Definition: ofApp.cpp:2680
friend void useOutputStream(OStream &stream)
Specify an OStream to which to stream predictions made by the active ESP pipeline. Multiple output streams are supported. 
Definition: ofApp.cpp:2672
void mousePressed(int x, int y, int button) final
Definition: ofApp.cpp:2504
void mouseEntered(int x, int y) final
Definition: ofApp.cpp:2597
virtual void notify(const ErrorLogMessage &data) final
Definition: ofApp.h:50
void setGridColor(ofColor color)
Definition: plotter.h:240
void deleteButtonPressed(ofxDatGuiButtonEvent e)
Definition: ofApp.h:560
friend void useStream(IOStream &stream)
Definition: ofApp.cpp:2692
void mouseMoved(int x, int y) final
Definition: ofApp.cpp:2494
void registerTuneable(Tuneable *t)
Definition: ofApp.h:43
void setBackgroundColor(ofColor color)
Definition: plotter.h:232
void keyPressed(int key) final
Definition: ofApp.cpp:2204
void draw() final
Definition: ofApp.cpp:1553
void mouseReleased(int x, int y, int button) final
Definition: ofApp.cpp:2509
void renameButtonPressed(ofxDatGuiButtonEvent e)
Definition: ofApp.h:557
void reloadPipelineModules()
Definition: ofApp.cpp:2198