ESP  0.1
The Example-based Sensor Predictions (ESP) system tries to bring machine learning to the maker community.
ofApp.cpp File Reference
#include "ofApp.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <string>
#include "user.h"
#include "ofxParagraph.h"
#include "ofYesNoDialog.h"

Classes

class  Palette
 

Functions

string encodeName (const string &name)
 
string decodeName (const string &name)
 
void ofDrawColoredBitmapString (ofColor color, const string &text, float x, float y)
 
void useInputStream (InputStream &stream)
 
void useOutputStream (OStream &stream)
 Specify an OStream to which to stream predictions made by the active ESP pipeline. Multiple output streams are supported. More...
 
void useOutputStream (OStreamVector &stream)
 
void usePipeline (GRT::GestureRecognitionPipeline &pipeline)
 
void useCalibrator (Calibrator &calibrator)
 Specify the Calibrator to be used by the ESP system. More...
 
void setGUIBufferSize (uint32_t buffer_size)
 
void useStream (IOStream &stream)
 
void useStream (IOStreamVector &stream)
 
void useTrainingSampleChecker (TrainingSampleChecker checker)
 Register a function for checking training samples. More...
 
void useTrainingDataAdvice (string advice)
 Provide the user with custom advice on collecting training data. More...
 
void useLeaveOneOutScoring (bool enable)
 Whether or not to do leave-one-out scoring of training data. More...
 
void setTruePositiveWarningThreshold (double threshold)
 Only warn (highlight the confusion score) if the true positive rate is smaller than the threshold. True positive rate is the probability that this sample is correctly classified. When the actual rate is smaller than the threshold, this indicates a sample that is less likely to be considered as this class. More...
 
void setFalseNegativeWarningThreshold (double threshold)
 Only warn (highlight the confusion score) if the false negative rate is larger than the threshold. False negative rate is the probability that this sample is incorrectly classified as other classes. When the actual rate is larger than the threshold, this sample is likely to be mis-classified. More...
 

Variables

const uint32_t kTooManyFeaturesThreshold = 32
 
const uint32_t kDelayBeforeTraining = 50
 
const double kPipelineHeightWeight = 0.3
 
const ofColor kSerialSelectionColor = ofColor::fromHex(0x00FF00)
 

Function Documentation

string decodeName ( const string &  name)
string encodeName ( const string &  name)
void ofDrawColoredBitmapString ( ofColor  color,
const string &  text,
float  x,
float  y 
)
void setFalseNegativeWarningThreshold ( double  threshold)

Only warn (highlight the confusion score) if the false negative rate is larger than the threshold. False negative rate is the probability that this sample is incorrectly classified as other classes. When the actual rate is larger than the threshold, this sample is likely to be mis-classified.

void setGUIBufferSize ( uint32_t  buffer_size)

This will be linked against ofApp::setGUIBufferSize

void setTruePositiveWarningThreshold ( double  threshold)

Only warn (highlight the confusion score) if the true positive rate is smaller than the threshold. True positive rate is the probability that this sample is correctly classified. When the actual rate is smaller than the threshold, this indicates a sample that is less likely to be considered as this class.

void useCalibrator ( Calibrator calibrator)

Specify the Calibrator to be used by the ESP system.

This Calibrator will be applied to data coming from the current input stream (IStream instance specified by useInputStream()) before it is passed to the current machine learning pipeline (GestureRecognitionPipeline specified by usePipeline()). Only one calibrator can be active at a time, but it can include multiple CalibrateProcess instances, each of which specifies one sample of calibration data to be collected by the user.

void useInputStream ( InputStream stream)

Tells the ESP system from which input stream to read sensor data for processing by the active machine learning pipeline. Call from your setup() function. The specified stream will be automatically started by the ESP system. Note that only one input stream is supported; subsequent calls to useInputStream() will replace the previously-specified stream.

See also: useOutputStream() for specifying an output stream (to which to stream the predictions made by the ESP pipeline) and useStream() to specify a stream to use for both input and output.

Parameters
streamthe input stream to use. May be an IOStream instance, in which case the stream will only be used for input.
void useLeaveOneOutScoring ( bool  enable = true)

Whether or not to do leave-one-out scoring of training data.

If enabled, to score each training sample, the model will be trained on all other samples. Otherwise, the model will be trained once on all samples and then each sample will be scored using this one model.

Leave-one-out training is generally more useful, as it's typically more informative to evaluate models using data that wasn't used to train them. On the other hand, leave-one-out scoring can be much slower because it requires retraining the model once for each training sample.

Note that "training sample" refers to one sample collected by the user, which may consist of multiple individual data-points.

Leave-one-out scoring is enabled by default and will be used unless disabled by a call to this function in the setup() of the active example.

Parameters
enablewhether or not to enable leave-one-out scoring
void useOutputStream ( OStream stream)

Specify an OStream to which to stream predictions made by the active ESP pipeline. Multiple output streams are supported.

See also: useInputStream() to specify the input stream (from which to read sensor data into the ESP pipeline); and useStream() to specify a single stream for both input and output.

Parameters
streamthe OStream to use
void useOutputStream ( OStreamVector stream)
void usePipeline ( GRT::GestureRecognitionPipeline &  pipeline)

Tells the ESP system which machine learning pipeline to use. Call from your setup() function. Note that only one pipeline is supported; subsequent calls to usePipeline() will replace the previously-specified pipeline.

The pipeline will be fed with data from the input stream specified using useStream() or useInputStream(), as modified by the calibrators specified using useCalibrator().

void useStream ( IOStream stream)

Tells the ESP system which stream to use, for both input and output. Call from your setup() function. The specified stream will be automatically started by the ESP system. Note that only one input stream is supported at a time; subsequent calls to useStream() will cause the new stream to be used for input, replacing input from streams passed to any previous calls to useStream() or useInputStream(). Multiple simultaneous output streams are supported, however, so calling useStream() will cause output to be sent to the specified stream in addition to streams previously specified with useStream() or useOutputStream().

Parameters
streamthe stream to use for input and output
void useStream ( IOStreamVector stream)
void useTrainingDataAdvice ( string  advice)

Provide the user with custom advice on collecting training data.

This advice will be shown in the training tab of the interface. If supplied, it will override the default, per-classifier advice provided by ESP.

You may want to provide advice on:

  • the amount of training data required
  • the effect of gathering additional training data
  • the effect of individual bad training samples
  • what good sample look like (although see useTrainingSampleChecker() for a programmatic means of providing the user with feedback on the quality of individual training samples)
  • etc.

On the other hand, try to keep the advice relatively brief, as it will take up space on the training tab of the ESP interface.

The string will be automatically wrapped at the edge of the screen. No markup or formatting (including explicit line breaks) supported.

Parameters
advicethe advice to show to the user
void useTrainingSampleChecker ( TrainingSampleChecker  checker)

Register a function for checking training samples.

The TrainingSampleChecker specified here will be called on each new sample of training data collected by the user. The result, indicated by the TrainingSampleCheckerResult returned, will be shown to the user.

Here's an example of how you might use this function:

TrainingSampleCheckerResult myChecker(const MatrixDouble &data) {
    if (data.getNumRows() == 0) {
        return TrainingSampleCheckerResult(
            TrainingSampleCheckerResult::FAILURE,
            "Error: Training sample doesn't contain any data.");
    }
    if (data.getNumRows() == 1) {
        return TrainingSampleCheckerResult(
            TrainingSampleCheckerResult::WARNING,
            "Warning: Sample only contains one data point.");
    }

    return TrainingSampleCheckerResult::SUCCESS; // use default message
}

void setup() {
    useTrainingSampleChecker(myChecker);
}

Note that only one TrainingSampleChecker can be active at any time. Subsequent calls to this function will replace the previously-registered checker.

Parameters
checkerthe function to be called on the user's training samples

Variable Documentation

const uint32_t kDelayBeforeTraining = 50
const double kPipelineHeightWeight = 0.3
const ofColor kSerialSelectionColor = ofColor::fromHex(0x00FF00)
const uint32_t kTooManyFeaturesThreshold = 32