21 #define GRT_DLL_EXPORTS
30 debugLog.setProceedingText(
"[DEBUG GRP]");
31 errorLog.setProceedingText(
"[ERROR GRP]");
32 warningLog.setProceedingText(
"[WARNING GRP]");
33 testingLog.setProceedingText(
"[TEST GRP]");
40 debugLog.setProceedingText(
"[DEBUG GRP]");
41 errorLog.setProceedingText(
"[ERROR GRP]");
42 warningLog.setProceedingText(
"[WARNING GRP]");
43 testingLog.setProceedingText(
"[TEST GRP]");
56 this->initialized = rhs.initialized;
57 this->trained = rhs.trained;
58 this->info = rhs.info;
59 this->inputVectorDimensions = rhs.inputVectorDimensions;
60 this->outputVectorDimensions = rhs.outputVectorDimensions;
61 this->predictedClassLabel = rhs.predictedClassLabel;
62 this->predictedClusterLabel = rhs.predictedClusterLabel;
63 this->pipelineMode = rhs.pipelineMode;
64 this->predictionModuleIndex = rhs.predictionModuleIndex;
65 this->numTrainingSamples = rhs.numTrainingSamples;
66 this->numTestSamples = rhs.numTestSamples;
67 this->testAccuracy = rhs.testAccuracy;
68 this->testRMSError = rhs.testRMSError;
69 this->testSquaredError = rhs.testSquaredError;
70 this->testTime = rhs.testTime;
71 this->trainingTime = rhs.trainingTime;
72 this->testFMeasure = rhs.testFMeasure;
73 this->testPrecision = rhs.testPrecision;
74 this->testRecall = rhs.testRecall;
75 this->regressionData = rhs.regressionData;
76 this->testRejectionPrecision = rhs.testRejectionPrecision;
77 this->testRejectionRecall = rhs.testRejectionRecall;
78 this->testConfusionMatrix = rhs.testConfusionMatrix;
79 this->crossValidationResults = rhs.crossValidationResults;
80 this->testResults = rhs.testResults;
83 this->debugLog = rhs.debugLog;
84 this->errorLog = rhs.errorLog;
85 this->trainingLog = rhs.trainingLog;
86 this->testingLog = rhs.testingLog;
87 this->warningLog = rhs.warningLog;
89 for(
unsigned int i=0; i<rhs.preProcessingModules.size(); i++){
93 for(
unsigned int i=0; i<rhs.featureExtractionModules.size(); i++){
109 for(
unsigned int i=0; i<rhs.postProcessingModules.size(); i++){
113 for(
unsigned int k=0; k<NUM_CONTEXT_LEVELS; k++){
114 for(
unsigned int i=0; i<rhs.contextModules[k].size(); i++){
120 this->trained = rhs.trained;
169 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
174 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << std::endl;
190 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
192 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
205 bool okToAddProcessedData =
true;
206 classLabel = trainingData[i].getClassLabel();
207 trainingSample = trainingData[i].getSample();
211 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
212 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
213 errorLog <<
"train(ClassificationData trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
214 errorLog << moduleIndex;
215 errorLog << std::endl;
218 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
224 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
225 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
226 errorLog <<
"train(ClassificationData trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
227 errorLog << moduleIndex;
228 errorLog << std::endl;
231 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
232 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
234 okToAddProcessedData =
false;
240 if( okToAddProcessedData ){
242 processedTrainingData.
addSample(classLabel, trainingSample);
248 warningLog <<
"train(ClassificationData trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
255 trained = classifier->
train_( processedTrainingData );
257 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
274 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
279 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << std::endl;
301 Float crossValidationAccuracy = 0;
306 for(UINT k=0; k<kFoldValue; k++){
310 if( !
train( foldTrainingData ) ){
317 if( !
test( foldTestData ) ){
329 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
330 crossValidationResults = cvResults;
345 errorLog <<
"train(const TimeSeriesClassificationData &trainingData) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
350 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << std::endl;
368 bool allowNullGestureClass =
true;
370 timeseriesClassificationData.setAllowNullGestureClass( allowNullGestureClass );
378 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
381 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
383 timeseriesClassificationData.setNumDimensions( trainingDataInputDimensionSize );
387 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
390 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
397 UINT classLabel = trainingData[i].getClassLabel();
398 MatrixFloat trainingSample = trainingData[i].getData();
403 bool resetPreprocessingModule =
true;
404 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
407 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
409 if( resetPreprocessingModule ){
410 preProcessingModules[moduleIndex]->reset();
414 if( preProcessingModules[moduleIndex]->getNumInputDimensions() != preProcessingModules[moduleIndex]->getNumOutputDimensions() ){
415 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. The number of inputDimensions (";
416 errorLog << preProcessingModules[moduleIndex]->getNumInputDimensions();
417 errorLog <<
") in PreProcessingModule ";
418 errorLog << moduleIndex;
419 errorLog <<
" do not match the number of outputDimensions (";
420 errorLog << preProcessingModules[moduleIndex]->getNumOutputDimensions();
421 errorLog << std::endl;
425 if( !preProcessingModules[moduleIndex]->process( sample ) ){
426 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. PreProcessingModuleIndex: ";
427 errorLog << moduleIndex;
428 errorLog << std::endl;
431 sample = preProcessingModules[moduleIndex]->getProcessedData();
435 resetPreprocessingModule =
false;
438 for(UINT c=0; c<sample.size(); c++){
439 trainingSample[r][c] = sample[c];
446 processedTrainingData.addSample(classLabel,trainingSample);
451 for(UINT i=0; i<processedTrainingData.getNumSamples(); i++){
452 UINT classLabel = processedTrainingData[i].getClassLabel();
454 bool featureDataReady =
false;
455 bool resetFeatureExtractionModules =
true;
460 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
461 inputVector = trainingSample.
getRow( r );
462 featureDataReady =
true;
467 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
469 if( resetFeatureExtractionModules ){
470 featureExtractionModules[moduleIndex]->reset();
473 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
474 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: ";
475 errorLog << moduleIndex;
476 errorLog << std::endl;
482 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
483 featureDataReady = featureExtractionModules[moduleIndex]->getFeatureDataReady();
486 if( !featureDataReady ) {
break; }
490 resetFeatureExtractionModules =
false;
492 if( featureDataReady ){
495 if( !featureData.
push_back( inputVector ) ){
496 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
499 }
else classificationData.
addSample(classLabel, inputVector);
504 if( !featureData.
push_back( inputVector ) ){
505 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
509 else classificationData.
addSample(classLabel, inputVector);
519 numTrainingSamples = timeseriesClassificationData.getNumSamples();
520 trained = classifier->
train( timeseriesClassificationData );
523 trained = classifier->
train( classificationData );
527 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier" << classifier->
getLastErrorMessage() << std::endl;
544 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
549 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << std::endl;
565 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Spilt Dataset into KFolds!" << std::endl;
570 Float crossValidationAccuracy = 0;
574 for(UINT k=0; k<kFoldValue; k++){
578 if( !
train( foldTrainingData ) ){
579 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to train pipeline for fold " << k <<
"." << std::endl;
586 if( !
test( foldTestData ) ){
587 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to test pipeline for fold " << k <<
"." << std::endl;
598 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
613 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To train Classifier, the classifier has not been set!" << std::endl;
618 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To train Classifier, there is no training data!" << std::endl;
629 UINT numDimensions = inputVectorDimensions;
634 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
636 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
649 bool okToAddProcessedData =
true;
650 classLabel = trainingData[i].getClassLabel();
651 trainingSample = trainingData[i].getSample();
655 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
656 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
657 errorLog <<
"train(ClassificationDataStream trainingData) - Failed to PreProcess training Data. PreProcessingModuleIndex: ";
658 errorLog << moduleIndex;
659 errorLog << std::endl;
662 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
668 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
669 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
670 errorLog <<
"train(ClassificationDataStream trainingData) - Failed to Compute Features from training Data. FeatureExtractionModuleIndex ";
671 errorLog << moduleIndex;
672 errorLog << std::endl;
675 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
676 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
678 okToAddProcessedData =
false;
684 if( okToAddProcessedData ){
686 processedTrainingData.
addSample(classLabel, trainingSample);
692 warningLog <<
"train(ClassificationDataStream trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
699 trained = classifier->
train_( processedTrainingData );
701 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
738 numInputs = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
742 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
746 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
753 VectorFloat inputVector = trainingData[i].getInputVector();
754 VectorFloat targetVector = trainingData[i].getTargetVector();
757 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
758 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
759 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. PreProcessingModuleIndex: " << moduleIndex << std::endl;
763 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
768 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
769 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
770 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
774 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
779 if( !processedTrainingData.
addSample(inputVector,targetVector) ){
780 errorLog <<
"train(const RegressionData &trainingData) - Failed to add processed training sample to training data" << std::endl;
790 trained = regressifier->
train( processedTrainingData );
792 errorLog <<
"train(const RegressionData &trainingData) - Failed To Train Regressifier: " << regressifier->
getLastErrorMessage() << std::endl;
796 errorLog <<
"train(const RegressionData &trainingData) - Classifier is not set" << std::endl;
813 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, the regressifier has not been set!" << std::endl;
818 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, there is no training data!" << std::endl;
840 Float crossValidationAccuracy = 0;
843 for(UINT k=0; k<kFoldValue; k++){
847 if( !
train( foldTrainingData ) ){
854 if( !
test( foldTestData ) ){
865 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
880 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, the clusterer has not been set!" << std::endl;
885 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, there is no training data!" << std::endl;
901 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
903 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
914 bool okToAddProcessedData =
true;
919 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
920 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
921 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
922 errorLog << moduleIndex;
923 errorLog << std::endl;
926 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
932 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
933 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
934 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
935 errorLog << moduleIndex;
936 errorLog << std::endl;
939 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
940 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
942 okToAddProcessedData =
false;
948 if( okToAddProcessedData ){
950 processedTrainingData.
addSample(trainingSample);
957 warningLog <<
"train(const ClassificationData &trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
964 trained = clusterer->
train_( processedTrainingData );
966 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer: " << clusterer->
getLastErrorMessage() << std::endl;
983 errorLog <<
"test(const ClassificationData &testData) - Classifier is not trained" << std::endl;
989 errorLog <<
"test(const ClassificationData &testData) - The dimensionality of the test data (" +
Util::toString(testData.
getNumDimensions()) +
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
994 errorLog <<
"test(const ClassificationData &testData) - The classifier has not been set" << std::endl;
1002 bool classLabelValidationPassed =
true;
1004 bool labelFound =
false;
1013 classLabelValidationPassed =
false;
1014 errorLog <<
"test(const ClassificationData &testData) - The test dataset contains a class label (" << testData.
getClassTracker()[i].classLabel <<
") that is not in the model!" << std::endl;
1018 if( !classLabelValidationPassed ){
1019 errorLog <<
"test(const ClassificationData &testData) - Model Class Labels: ";
1023 errorLog << std::endl;
1027 Float rejectionPrecisionCounter = 0;
1028 Float rejectionRecallCounter = 0;
1032 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1035 testConfusionMatrix.
resize(confusionMatrixSize, confusionMatrixSize);
1039 testPrecision.clear();
1041 testFMeasure.clear();
1053 for(UINT i=0; i<numTestSamples; i++){
1054 UINT classLabel = testData[i].getClassLabel();
1059 errorLog <<
"test(const ClassificationData &testData) - Prediction failed for test sample at index: " << i << std::endl;
1066 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1067 errorLog <<
"test(const ClassificationData &testData) - Failed to update test metrics at test sample index: " << i << std::endl;
1079 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, numTestSamples) ){
1080 errorLog <<
"test(const ClassificationData &testData) - Failed to compute test metrics!" << std::endl;
1096 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been trained" << std::endl;
1102 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The dimensionality of the test data (" << testData.
getNumDimensions() <<
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
1107 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been set" << std::endl;
1114 Float rejectionPrecisionCounter = 0;
1115 Float rejectionRecallCounter = 0;
1120 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1123 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1127 testPrecision.
resize(K, 0);
1129 testFMeasure.
resize(K, 0);
1138 for(UINT i=0; i<M; i++){
1139 UINT classLabel = testData[i].getClassLabel();
1144 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to run prediction for test sample index: " << i << std::endl;
1151 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1152 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to update test metrics at test sample index: " << i << std::endl;
1158 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, M) ){
1159 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to compute test metrics!" << std::endl;
1175 errorLog <<
"test(const ClassificationDataStream &testData) - The classifier has not been trained" << std::endl;
1181 errorLog <<
"test(const ClassificationDataStream &testData) - The dimensionality of the test data (" +
Util::toString(testData.
getNumDimensions()) +
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
1186 errorLog <<
"test(const ClassificationDataStream &testData) - The classifier has not been set" << std::endl;
1198 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1201 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1224 UINT classLabel = sample.getClassLabel();
1229 errorLog <<
"test(const ClassificationDataStream &testData) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1243 if( classLabel == predictedClassLabel ) testAccuracy++;
1251 testingLog <<
"test iteration: " << i;
1252 testingLog <<
"\tClassLabel: " << classLabel;
1253 testingLog <<
"\tPredictedClassLabel: " << predictedClassLabel;
1265 testAccuracy = testAccuracy / Float( testData.
getNumSamples() ) * 100.0;
1267 testingLog <<
"Test complete. Total testing time: " << testTime << std::endl;
1279 errorLog <<
"test(const RegressionData &testData) - Regressifier is not trained" << std::endl;
1285 errorLog <<
"test(const RegressionData &testData) - The dimensionality of the test data (" << testData.
getNumInputDimensions() <<
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
1290 errorLog <<
"test(const RegressionData &testData) - The regressifier has not been set" << std::endl;
1295 errorLog <<
"test(const RegressionData &testData) - The size of the output of the regressifier (" << regressifier->
getNumOutputDimensions() <<
") does not match that of the size of the number of target dimensions (" << testData.
getNumTargetDimensions() <<
")" << std::endl;
1303 testResults.
resize( numTestSamples );
1310 testSquaredError = 0;
1312 for(UINT i=0; i<numTestSamples; i++){
1313 VectorFloat inputVector = testData[i].getInputVector();
1314 VectorFloat targetVector = testData[i].getTargetVector();
1317 if( !
map( inputVector ) ){
1318 errorLog <<
"test(const RegressionData &testData) - Failed to map input Vector!" << std::endl;
1325 for(UINT j=0; j<targetVector.size(); j++){
1326 sum += grt_sqr( regressionData[j]-targetVector[j] );
1329 testSquaredError += sum;
1332 testResults[i].setRegressionResult(i,regressionData,targetVector);
1339 testRMSError = sqrt( testSquaredError / Float( testData.
getNumSamples() ) );
1350 errorLog <<
"predict(const VectorFloat &inputVector) - The classifier has not been trained" << std::endl;
1355 if( inputVector.size() != inputVectorDimensions ){
1356 errorLog <<
"predict(const VectorFloat &inputVector) - The dimensionality of the input Vector (" << int(inputVector.size()) <<
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
1361 return predict_classifier( inputVector );
1365 return predict_regressifier( inputVector );
1369 return predict_clusterer( inputVector );
1372 errorLog <<
"predict(const VectorFloat &inputVector) - Neither a classifier, regressifer or clusterer is set" << std::endl;
1380 errorLog <<
"predict(const MatrixFloat &inputMatrix) - The classifier has not been trained!" << std::endl;
1385 if( input.
getNumCols() != inputVectorDimensions ){
1386 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - The dimensionality of the input matrix (" << input.
getNumCols() <<
") does not match that of the input Vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << std::endl;
1391 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - A classifier has not been set" << std::endl;
1399 const void *data =
static_cast< const void*
>( &inputMatrix );
1400 DataType dataType = DATA_TYPE_MATRIX;
1407 predictionModuleIndex = START_OF_PIPELINE;
1431 predictionModuleIndex = AFTER_PREPROCESSING;
1435 const void *feInput = data;
1436 const void *feOutput = NULL;
1437 const UINT numFeatureExtractionModules = featureExtractionModules.
getSize();
1438 DataType inputType = DATA_TYPE_UNKNOWN;
1439 DataType outputType = DATA_TYPE_UNKNOWN;
1440 for(UINT moduleIndex=0; moduleIndex<numFeatureExtractionModules; moduleIndex++){
1442 inputType = featureExtractionModules[ moduleIndex ]->getInputType();
1443 outputType = featureExtractionModules[ moduleIndex ]->getOutputType();
1446 switch( inputType ){
1447 case DATA_TYPE_VECTOR:
1448 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const VectorFloat* >( feInput ) ) ){
1449 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1453 case DATA_TYPE_MATRIX:
1454 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const MatrixFloat* >( feInput ) ) ){
1455 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1460 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1466 switch( outputType ){
1467 case DATA_TYPE_VECTOR:
1468 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureVector() );
1470 case DATA_TYPE_MATRIX:
1471 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureMatrix() );
1474 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1480 if( moduleIndex+1 < numFeatureExtractionModules ){
1487 dataType = outputType;
1491 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1495 case DATA_TYPE_VECTOR:
1497 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1501 case DATA_TYPE_MATRIX:
1503 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1508 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to run prediction. Unknown data type!" << std::endl;
1519 predictionModuleIndex = AFTER_CLASSIFIER;
1573 predictionModuleIndex = END_OF_PIPELINE;
1578 return predict_regressifier( inputVector );
1581 bool GestureRecognitionPipeline::predict_classifier(
const VectorFloat &input){
1583 predictedClassLabel = 0;
1587 predictionModuleIndex = START_OF_PIPELINE;
1588 if( contextModules[ START_OF_PIPELINE ].size() > 0 ){
1589 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1590 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1591 errorLog <<
"predict_classifier(const VectorFloat &inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1594 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1597 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1603 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1604 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1605 errorLog <<
"predict_classifier(const VectorFloat &inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1608 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1613 predictionModuleIndex = AFTER_PREPROCESSING;
1614 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1615 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1616 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1617 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1620 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1621 predictionModuleIndex = AFTER_PREPROCESSING;
1624 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1630 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1631 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1632 errorLog <<
"predict_classifier(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1635 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1640 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1641 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1642 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1643 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1644 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1647 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1648 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1651 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1656 if( !classifier->
predict(inputVector) ){
1657 errorLog <<
"predict_classifier(VectorFloat inputVector) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1663 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1664 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1665 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1666 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1669 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1670 predictionModuleIndex = AFTER_CLASSIFIER;
1673 predictedClassLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1678 predictionModuleIndex = AFTER_CLASSIFIER;
1681 if( pipelineMode != CLASSIFICATION_MODE){
1682 errorLog <<
"predict_classifier(VectorFloat inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1687 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1690 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1693 data[0] = predictedClassLabel;
1696 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1697 errorLog <<
"predict_classifier(VectorFloat inputVector) - The size of the data Vector (" << int(data.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << std::endl;
1702 if( !postProcessingModules[moduleIndex]->process( data ) ){
1703 errorLog <<
"predict_classifier(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1708 data = postProcessingModules[moduleIndex]->getProcessedData();
1712 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1714 data = postProcessingModules[moduleIndex]->getProcessedData();
1717 if( data.size() != 1 ){
1718 errorLog <<
"predict_classifier(VectorFloat inputVector) - The size of the processed data Vector (" << int(data.size()) <<
") from postProcessingModule at the moduleIndex: " << moduleIndex <<
" is not equal to 1 even though it is in OutputModePredictedClassLabel!" << std::endl;
1723 predictedClassLabel = (UINT)data[0];
1730 predictionModuleIndex = END_OF_PIPELINE;
1731 if( contextModules[ END_OF_PIPELINE ].size() ){
1732 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1733 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1734 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1737 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1738 predictionModuleIndex = END_OF_PIPELINE;
1741 predictedClassLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
1748 bool GestureRecognitionPipeline::predict_regressifier(
const VectorFloat &input){
1753 predictionModuleIndex = START_OF_PIPELINE;
1754 if( contextModules[ START_OF_PIPELINE ].size() ){
1755 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1756 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1757 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1760 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1763 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1769 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1770 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1771 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1774 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1779 predictionModuleIndex = AFTER_PREPROCESSING;
1780 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1781 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1782 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1783 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1786 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1787 predictionModuleIndex = AFTER_PREPROCESSING;
1790 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1796 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1797 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1798 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1801 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1806 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1807 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1808 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1809 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1810 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1813 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1814 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1817 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1822 if( !regressifier->
predict(inputVector) ){
1823 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Prediction Failed! " << regressifier->
getLastErrorMessage() << std::endl;
1829 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1830 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1831 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( regressionData ) ){
1832 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1835 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1836 predictionModuleIndex = AFTER_CLASSIFIER;
1839 regressionData = contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData();
1844 predictionModuleIndex = AFTER_CLASSIFIER;
1847 if( pipelineMode != REGRESSION_MODE ){
1848 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Pipeline Mode Is Not In RegressionMode!" << std::endl;
1852 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1853 if( regressionData.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1854 errorLog <<
"predict_regressifier(VectorFloat inputVector) - The size of the regression Vector (" << int(regressionData.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << std::endl;
1858 if( !postProcessingModules[moduleIndex]->process( regressionData ) ){
1859 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1862 regressionData = postProcessingModules[moduleIndex]->getProcessedData();
1868 predictionModuleIndex = END_OF_PIPELINE;
1869 if( contextModules[ END_OF_PIPELINE ].size() ){
1870 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1871 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1872 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1875 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1876 predictionModuleIndex = END_OF_PIPELINE;
1879 regressionData = contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData();
1886 bool GestureRecognitionPipeline::predict_clusterer(
const VectorFloat &input){
1889 predictedClusterLabel = 0;
1892 predictionModuleIndex = START_OF_PIPELINE;
1893 if( contextModules[ START_OF_PIPELINE ].size() ){
1894 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1895 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1896 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1899 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1902 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1908 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1909 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1910 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1913 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1918 predictionModuleIndex = AFTER_PREPROCESSING;
1919 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1920 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1921 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1922 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1925 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1926 predictionModuleIndex = AFTER_PREPROCESSING;
1929 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1935 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1936 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1937 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1940 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1945 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1946 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1947 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1948 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1949 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1952 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1953 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1956 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1961 if( !clusterer->
predict(inputVector) ){
1962 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Prediction Failed! " << clusterer->
getLastErrorMessage() << std::endl;
1968 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1969 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1970 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClusterLabel) ) ){
1971 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1974 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1975 predictionModuleIndex = AFTER_CLASSIFIER;
1978 predictedClusterLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1983 predictionModuleIndex = AFTER_CLASSIFIER;
1986 if( pipelineMode != CLASSIFICATION_MODE){
1987 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1992 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1995 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1998 data[0] = predictedClusterLabel;
2001 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
2002 errorLog <<
"predict_clusterer(VectorFloat inputVector) - The size of the data Vector (" << int(data.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << std::endl;
2007 if( !postProcessingModules[moduleIndex]->process( data ) ){
2008 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
2013 data = postProcessingModules[moduleIndex]->getProcessedData();
2017 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
2019 data = postProcessingModules[moduleIndex]->getProcessedData();
2022 if( data.size() != 1 ){
2023 errorLog <<
"predict_clusterer(VectorFloat inputVector) - The size of the processed data Vector (" << int(data.size()) <<
") from postProcessingModule at the moduleIndex: " << moduleIndex <<
" is not equal to 1 even though it is in OutputModePredictedClassLabel!" << std::endl;
2028 predictedClusterLabel = (UINT)data[0];
2035 predictionModuleIndex = END_OF_PIPELINE;
2036 if( contextModules[ END_OF_PIPELINE ].size() ){
2037 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
2038 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
2039 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
2042 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
2043 predictionModuleIndex = END_OF_PIPELINE;
2046 predictedClusterLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
2057 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
2058 if( !preProcessingModules[ moduleIndex ]->
reset() ){
2059 errorLog <<
"Failed To Reset PreProcessingModule " << moduleIndex << std::endl;
2067 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
2068 if( !featureExtractionModules[ moduleIndex ]->
reset() ){
2069 errorLog <<
"Failed To Reset FeatureExtractionModule " << moduleIndex << std::endl;
2077 if( !classifier->
reset() ){
2078 errorLog <<
"Failed To Reset Classifier! " << classifier->
getLastErrorMessage() << std::endl;
2085 if( !regressifier->
reset() ){
2086 errorLog <<
"Failed To Reset Regressifier! " << regressifier->
getLastErrorMessage() << std::endl;
2093 if( !clusterer->
reset() ){
2094 errorLog <<
"Failed To Reset clusterer! " << clusterer->
getLastErrorMessage() << std::endl;
2101 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
2102 if( !postProcessingModules[ moduleIndex ]->
reset() ){
2103 errorLog <<
"Failed To Reset PostProcessingModule " << moduleIndex << std::endl;
2112 bool GestureRecognitionPipeline::clearAll(){
return clear(); }
2118 deleteAllPreProcessingModules();
2119 deleteAllFeatureExtractionModules();
2121 deleteRegressifier();
2123 deleteAllPostProcessingModules();
2124 deleteAllContextModules();
2134 preProcessingModules[i]->clear();
2139 featureExtractionModules[i]->clear();
2143 switch( pipelineMode ){
2144 case PIPELINE_MODE_NOT_SET:
2146 case CLASSIFICATION_MODE:
2148 classifier->
clear();
2151 case REGRESSION_MODE:
2153 regressifier->
clear();
2167 postProcessingModules[i]->clear();
2180 errorLog <<
"Failed to write pipeline to file as the pipeline has not been initialized yet!" << std::endl;
2186 file.open(filename.c_str(), std::iostream::out );
2188 if( !file.is_open() ){
2189 errorLog <<
"Failed to open file with filename: " << filename << std::endl;
2194 file <<
"GRT_PIPELINE_FILE_V3.0\n";
2199 file <<
"Trained: " <<
getTrained() << std::endl;
2200 file <<
"Info: " << info << std::endl;
2203 file <<
"PreProcessingModuleDatatypes:";
2205 file <<
"\t" << preProcessingModules[i]->getPreProcessingType();
2209 file <<
"FeatureExtractionModuleDatatypes:";
2211 file <<
"\t" << featureExtractionModules[i]->getFeatureExtractionType();
2215 switch( pipelineMode ){
2216 case PIPELINE_MODE_NOT_SET:
2218 case CLASSIFICATION_MODE:
2220 else file <<
"ClassificationModuleDatatype:\tCLASSIFIER_NOT_SET" << std::endl;
2222 case REGRESSION_MODE:
2224 else file <<
"RegressionModuleDatatype:\tREGRESSIFIER_NOT_SET" << std::endl;
2228 else file <<
"ClusterModuleDatatype:\tCLUSTERER_NOT_SET" << std::endl;
2234 file <<
"PostProcessingModuleDatatypes:";
2236 file <<
"\t" << postProcessingModules[i]->getPostProcessingType();
2243 if( !preProcessingModules[i]->
save( file ) ){
2244 errorLog <<
"Failed to write preprocessing module " << i <<
" settings to file!" << std::endl;
2253 if( !featureExtractionModules[i]->
save( file ) ){
2254 errorLog <<
"Failed to write feature extraction module " << i <<
" settings to file!" << std::endl;
2260 switch( pipelineMode ){
2261 case PIPELINE_MODE_NOT_SET:
2263 case CLASSIFICATION_MODE:
2265 if( !classifier->
save( file ) ){
2266 errorLog <<
"Failed to write classifier model to file!" << std::endl;
2272 case REGRESSION_MODE:
2274 if( !regressifier->
save( file ) ){
2275 errorLog <<
"Failed to write regressifier model to file!" << std::endl;
2283 if( !clusterer->
save( file ) ){
2284 errorLog <<
"Failed to write clusterer model to file!" << std::endl;
2297 if( !postProcessingModules[i]->
save( file ) ){
2298 errorLog <<
"Failed to write post processing module " << i <<
" settings to file!" << std::endl;
2321 file.open(filename.c_str(), std::iostream::in );
2323 if( !file.is_open() ){
2324 errorLog <<
"loadPipelineFromFile(string filename) - Failed to open file with filename: " << filename << std::endl;
2332 if( word !=
"GRT_PIPELINE_FILE_V3.0" ){
2333 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read file header" << std::endl;
2340 if( word !=
"PipelineMode:" ){
2341 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PipelineMode" << std::endl;
2350 if( word !=
"NumPreprocessingModules:" ){
2351 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPreprocessingModules header" << std::endl;
2355 unsigned int numPreprocessingModules;
2356 file >> numPreprocessingModules;
2360 if( word !=
"NumFeatureExtractionModules:" ){
2361 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumFeatureExtractionModules header" << std::endl;
2365 unsigned int numFeatureExtractionModules;
2366 file >> numFeatureExtractionModules;
2370 if( word !=
"NumPostprocessingModules:" ){
2371 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPostprocessingModules header" << std::endl;
2375 unsigned int numPostprocessingModules;
2376 file >> numPostprocessingModules;
2380 if( word !=
"Trained:" ){
2381 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Trained header" << std::endl;
2389 if( word !=
"Info:" ){
2390 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Info header" << std::endl;
2397 while( word !=
"PreProcessingModuleDatatypes:" ){
2403 if( numPreprocessingModules > 0 ) preProcessingModules.
resize(numPreprocessingModules,NULL);
2404 if( numFeatureExtractionModules > 0 ) featureExtractionModules.
resize(numFeatureExtractionModules,NULL);
2405 if( numPostprocessingModules > 0 ) postProcessingModules.
resize(numPostprocessingModules,NULL);
2408 if( word !=
"PreProcessingModuleDatatypes:" ){
2409 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PreProcessingModuleDatatypes" << std::endl;
2413 for(UINT i=0; i<numPreprocessingModules; i++){
2416 if( preProcessingModules[i] == NULL ){
2417 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create preprocessing instance from string: " << word << std::endl;
2425 if( word !=
"FeatureExtractionModuleDatatypes:" ){
2426 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read FeatureExtractionModuleDatatypes" << std::endl;
2430 for(UINT i=0; i<numFeatureExtractionModules; i++){
2432 featureExtractionModules[i] = FeatureExtraction::createInstanceFromString( word );
2433 if( featureExtractionModules[i] == NULL ){
2434 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create feature extraction instance from string: " << word << std::endl;
2440 switch( pipelineMode ){
2441 case PIPELINE_MODE_NOT_SET:
2443 case CLASSIFICATION_MODE:
2445 if( word !=
"ClassificationModuleDatatype:" ){
2446 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClassificationModuleDatatype" << std::endl;
2455 if( classifier == NULL ){
2456 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create classifier instance from string: " << word << std::endl;
2461 case REGRESSION_MODE:
2463 if( word !=
"RegressionModuleDatatype:" ){
2464 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read RegressionModuleDatatype" << std::endl;
2473 if( regressifier == NULL ){
2474 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create regressifier instance from string: " << word << std::endl;
2481 if( word !=
"ClusterModuleDatatype:" ){
2482 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClusterModuleDatatype" << std::endl;
2491 if( clusterer == NULL ){
2492 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create clusterer instance from string: " << word << std::endl;
2503 if( word !=
"PostProcessingModuleDatatypes:" ){
2504 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PostProcessingModuleDatatypes" << std::endl;
2508 for(UINT i=0; i<numPostprocessingModules; i++){
2514 for(UINT i=0; i<numPreprocessingModules; i++){
2517 if( !preProcessingModules[i]->
load( file ) ){
2518 errorLog <<
"Failed to load preprocessing module " << i <<
" settings from file!" << std::endl;
2525 for(UINT i=0; i<numFeatureExtractionModules; i++){
2528 if( !featureExtractionModules[i]->
load( file ) ){
2529 errorLog <<
"Failed to load feature extraction module " << i <<
" settings from file!" << std::endl;
2536 switch( pipelineMode ){
2537 case PIPELINE_MODE_NOT_SET:
2539 case CLASSIFICATION_MODE:
2540 if( !classifier->
load( file ) ){
2541 errorLog <<
"Failed to load classifier model from file!" << std::endl;
2546 case REGRESSION_MODE:
2547 if( !regressifier->
load( file ) ){
2548 errorLog <<
"Failed to load regressifier model from file!" << std::endl;
2554 if( !clusterer->
load( file ) ){
2555 errorLog <<
"Failed to load cluster model from file!" << std::endl;
2565 for(UINT i=0; i<numPostprocessingModules; i++){
2568 if( !postProcessingModules[i]->
load( file ) ){
2569 errorLog <<
"Failed to load post processing module " << i <<
" settings from file!" << std::endl;
2579 inputVectorDimensions = 0;
2581 if( numPreprocessingModules > 0 ){
2582 inputVectorDimensions = preProcessingModules[0]->getNumInputDimensions();
2584 if( numFeatureExtractionModules > 0 ){
2585 inputVectorDimensions = featureExtractionModules[0]->getNumInputDimensions();
2587 switch( pipelineMode ){
2588 case PIPELINE_MODE_NOT_SET:
2590 case CLASSIFICATION_MODE:
2593 case REGRESSION_MODE:
2614 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
2616 if( inputVector.size() != preProcessingModules[ moduleIndex ]->getNumInputDimensions() ){
2617 errorLog <<
"preProcessData(VectorFloat inputVector) - The size of the input Vector (" << preProcessingModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the PreProcessing Module at moduleIndex: " << moduleIndex << std::endl;
2621 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
2622 errorLog <<
"preProcessData(VectorFloat inputVector) - Failed To PreProcess Input Vector. PreProcessing moduleIndex: " << moduleIndex << std::endl;
2625 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
2631 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
2632 if( inputVector.size() != featureExtractionModules[ moduleIndex ]->getNumInputDimensions() ){
2633 errorLog <<
"FeatureExtraction(VectorFloat inputVector) - The size of the input Vector (" << featureExtractionModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the FeatureExtraction Module at moduleIndex: " << moduleIndex << std::endl;
2637 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
2638 errorLog <<
"FeatureExtraction(VectorFloat inputVector) - Failed To Compute Features from Input Vector. FeatureExtraction moduleIndex: " << moduleIndex << std::endl;
2641 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
2658 return preProcessingModules.size() > 0;
2662 return featureExtractionModules.size() > 0;
2666 return (classifier!=NULL);
2670 return (regressifier!=NULL);
2674 return (clusterer!=NULL);
2678 return postProcessingModules.size() > 0;
2682 for(UINT i=0; i<NUM_CONTEXT_LEVELS; i++){
2683 if( contextModules[i].size() > 0 )
return true;
2689 return (pipelineMode!=PIPELINE_MODE_NOT_SET);
2693 return (pipelineMode==CLASSIFICATION_MODE);
2697 return pipelineMode==REGRESSION_MODE;
2703 return preProcessingModules[0]->getNumInputDimensions();
2707 return featureExtractionModules[0]->getNumInputDimensions();
2732 UINT numClasses = 0;
2743 return preProcessingModules.
getSize();
2747 return featureExtractionModules.
getSize();
2751 return postProcessingModules.
getSize();
2755 return predictionModuleIndex;
2761 return predictedClassLabel;
2764 return predictedClusterLabel;
2780 return numTrainingSamples;
2784 return numTestSamples;
2809 return testAccuracy;
2813 return testRMSError;
2817 return testSquaredError;
2825 for(UINT i=0; i<testFMeasure.size(); i++){
2827 return testFMeasure[i];
2838 for(UINT i=0; i<testPrecision.size(); i++){
2840 return testPrecision[i];
2851 for(UINT i=0; i<testRecall.
getSize(); i++){
2853 return testRecall[i];
2860 return testRejectionPrecision;
2864 return testRejectionRecall;
2872 return trainingTime;
2884 return testConfusionMatrix;
2888 TestResult testResults;
2889 testResults.numTrainingSamples = numTrainingSamples;
2890 testResults.numTestSamples = numTestSamples;
2891 testResults.accuracy = testAccuracy;
2892 testResults.rmsError = testRMSError;
2893 testResults.totalSquaredError = testSquaredError;
2894 testResults.trainingTime = trainingTime;
2895 testResults.testTime = testTime;
2896 testResults.rejectionPrecision = testRejectionPrecision;
2897 testResults.rejectionRecall = testRejectionRecall;
2898 testResults.precision = testPrecision;
2899 testResults.recall = testRecall;
2900 testResults.fMeasure = testFMeasure;
2901 testResults.confusionMatrix = testConfusionMatrix;
2906 return testPrecision;
2914 return testFMeasure;
2935 return regressionData;
2947 return preProcessingModules[ preProcessingModules.size()-1 ]->getProcessedData();
2954 if( moduleIndex < preProcessingModules.size() ){
2955 return preProcessingModules[ moduleIndex ]->getProcessedData();
2963 return featureExtractionModules[ featureExtractionModules.size()-1 ]->getFeatureVector();
2970 if( moduleIndex < featureExtractionModules.size() ){
2971 return featureExtractionModules[ moduleIndex ]->getFeatureVector();
2974 warningLog <<
"getFeatureExtractionData(UINT moduleIndex) - Failed to get class labels!" << std::endl;
2985 warningLog <<
"getClassLabels() - Failed to get class labels!" << std::endl;
2994 return crossValidationResults;
2998 if( moduleIndex < preProcessingModules.size() ){
2999 return preProcessingModules[ moduleIndex ];
3001 warningLog <<
"getPreProcessingModule(const UINT moduleIndex) - Failed to get pre processing module!" << std::endl;
3006 if( moduleIndex < featureExtractionModules.size() ){
3007 return featureExtractionModules[ moduleIndex ];
3009 warningLog <<
"getFeatureExtractionModule(const UINT moduleIndex) - Failed to get feature extraction module!" << std::endl;
3018 return regressifier;
3026 if( moduleIndex < postProcessingModules.size() ){
3027 return postProcessingModules[ moduleIndex ];
3029 warningLog <<
"getPostProcessingModule(UINT moduleIndex) - Failed to get post processing module!" << std::endl;
3034 if( contextLevel < contextModules.size() ){
3035 if( moduleIndex < contextModules[ contextLevel ].size() ){
3036 return contextModules[ contextLevel ][ moduleIndex ];
3039 warningLog <<
"getContextModule(UINT contextLevel,UINT moduleIndex) - Failed to get context module!" << std::endl;
3051 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - Invalid insertIndex value!" << std::endl;
3059 if( !newInstance->
deepCopyFrom( &preProcessingModule ) ){
3062 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - PreProcessing Module Not Set!" << std::endl;
3070 else iter = preProcessingModules.begin() + insertIndex;
3072 preProcessingModules.insert(iter, newInstance);
3088 if( insertIndex !=
INSERT_AT_END_INDEX && insertIndex >= featureExtractionModules.size() ){
3089 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule) - Invalid insertIndex value!" << std::endl;
3097 if( !newInstance->
deepCopyFrom( &featureExtractionModule ) ){
3100 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule - FeatureExtraction Module Not Set!" << std::endl;
3108 else iter = featureExtractionModules.begin() + insertIndex;
3110 featureExtractionModules.insert(iter, newInstance);
3127 deleteRegressifier();
3133 if( this->classifier == NULL ){
3134 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << std::endl;
3141 pipelineMode = PIPELINE_MODE_NOT_SET;
3142 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << std::endl;
3147 pipelineMode = CLASSIFICATION_MODE;
3157 }
else trained =
false;
3166 deleteRegressifier();
3170 pipelineMode = REGRESSION_MODE;
3176 if( !this->regressifier->
deepCopyFrom( ®ressifier ) ){
3177 deleteRegressifier();
3178 pipelineMode = PIPELINE_MODE_NOT_SET;
3179 errorLog <<
"setRegressifier(const Regressifier ®ressifier) - Regressifier Module Not Set!" << std::endl;
3190 }
else trained =
false;
3199 deleteRegressifier();
3203 pipelineMode = CLUSTER_MODE;
3211 pipelineMode = PIPELINE_MODE_NOT_SET;
3212 errorLog <<
"setClusterer(const Clusterer &clusterer) - Clusterer Module Not Set!" << std::endl;
3223 }
else trained =
false;
3232 errorLog <<
"addPostProcessingModule((const PostProcessing &postProcessingModule) - Invalid insertIndex value!" << std::endl;
3240 if( !newInstance->
deepCopyFrom( &postProcessingModule ) ){
3243 errorLog <<
"addPostProcessingModule(const PostProcessing &postProcessingModule) - PostProcessing Module Not Set!" << std::endl;
3251 else iter = postProcessingModules.begin() + insertIndex;
3253 postProcessingModules.insert(iter, newInstance);
3268 if( contextLevel >= contextModules.size() ){
3269 errorLog <<
"addContextModule(...) - Invalid contextLevel value!" << std::endl;
3274 if( insertIndex !=
INSERT_AT_END_INDEX && insertIndex >= contextModules[contextLevel].size() ){
3275 errorLog <<
"addContextModule(...) - Invalid insertIndex value!" << std::endl;
3283 if( !newInstance->deepCopyFrom( &contextModule ) ){
3286 errorLog <<
"addContextModule(...) - Context Module Not Set!" << std::endl;
3294 else iter = contextModules[ contextLevel ].begin() + insertIndex;
3296 contextModules[ contextLevel ].insert(iter, newInstance);
3304 if( contextLevel >= contextModules.size() ){
3305 errorLog <<
"updateContextModule(...) - Context Level is out of bounds!" << std::endl;
3310 if( moduleIndex >= contextModules[contextLevel].size() ){
3311 errorLog <<
"updateContextModule(...) - Invalid contextLevel value!" << std::endl;
3315 return contextModules[contextLevel][moduleIndex]->updateContext( value );
3319 deleteAllPreProcessingModules();
3324 if( moduleIndex >= preProcessingModules.size() ){
3325 errorLog <<
"removePreProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the preProcessingModules Vector is " << int(preProcessingModules.size()) << std::endl;
3330 delete preProcessingModules[ moduleIndex ];
3331 preProcessingModules[ moduleIndex ] = NULL;
3332 preProcessingModules.erase( preProcessingModules.begin() + moduleIndex );
3341 deleteAllFeatureExtractionModules();
3346 if( moduleIndex >= featureExtractionModules.size() ){
3347 errorLog <<
"removeFeatureExtractionModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the featureExtractionModules Vector is " << int(featureExtractionModules.size()) << std::endl;
3352 delete featureExtractionModules[ moduleIndex ];
3353 featureExtractionModules[ moduleIndex ] = NULL;
3354 featureExtractionModules.erase( featureExtractionModules.begin() + moduleIndex );
3363 deleteAllPostProcessingModules();
3368 if( moduleIndex >= postProcessingModules.size() ){
3369 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the postProcessingModules Vector is " << int(postProcessingModules.size()) << std::endl;
3374 delete postProcessingModules[ moduleIndex ];
3375 postProcessingModules[ moduleIndex ] = NULL;
3376 postProcessingModules.erase( postProcessingModules.begin() + moduleIndex );
3385 if( contextLevel >= NUM_CONTEXT_LEVELS ){
3386 errorLog <<
"removeContextModule(UINT contextLevel,UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
" is out of bounds!" << std::endl;
3390 if( moduleIndex >= contextModules[contextLevel].size() ){
3391 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the contextModules Vector at context level " <<
" is " << int(contextModules[contextLevel].size()) << std::endl;
3396 delete contextModules[contextLevel][moduleIndex];
3397 contextModules[contextLevel][moduleIndex] = NULL;
3398 contextModules[contextLevel].erase( contextModules[contextLevel].begin() + moduleIndex );
3403 deleteAllContextModules();
3412 testSquaredError = 0;
3414 testFMeasure.clear();
3415 testPrecision.clear();
3417 testRejectionPrecision = 0;
3418 testRejectionRecall = 0;
3419 testConfusionMatrix.
clear();
3420 testResults.clear();
3421 crossValidationResults.clear();
3435 void GestureRecognitionPipeline::deleteAllPreProcessingModules(){
3436 if( preProcessingModules.size() != 0 ){
3437 for(UINT i=0; i<preProcessingModules.size(); i++){
3438 delete preProcessingModules[i];
3439 preProcessingModules[i] = NULL;
3441 preProcessingModules.clear();
3446 void GestureRecognitionPipeline::deleteAllFeatureExtractionModules(){
3447 if( featureExtractionModules.size() != 0 ){
3448 for(UINT i=0; i<featureExtractionModules.size(); i++){
3449 delete featureExtractionModules[i];
3450 featureExtractionModules[i] = NULL;
3452 featureExtractionModules.clear();
3457 void GestureRecognitionPipeline::deleteClassifier(){
3458 if( classifier != NULL ){
3463 initialized =
false;
3466 void GestureRecognitionPipeline::deleteRegressifier(){
3467 if( regressifier != NULL ){
3468 delete regressifier;
3469 regressifier = NULL;
3472 initialized =
false;
3475 void GestureRecognitionPipeline::deleteClusterer(){
3476 if( clusterer != NULL ){
3481 initialized =
false;
3484 void GestureRecognitionPipeline::deleteAllPostProcessingModules(){
3485 if( postProcessingModules.size() != 0 ){
3486 for(UINT i=0; i<postProcessingModules.size(); i++){
3487 delete postProcessingModules[i];
3488 postProcessingModules[i] = NULL;
3490 postProcessingModules.clear();
3495 void GestureRecognitionPipeline::deleteAllContextModules(){
3496 for(UINT i=0; i<contextModules.size(); i++){
3497 for(UINT j=0; j<contextModules[i].size(); j++){
3498 delete contextModules[i][j];
3499 contextModules[i][j] = NULL;
3501 contextModules[i].clear();
3505 bool GestureRecognitionPipeline::init(){
3506 initialized =
false;
3509 pipelineMode = PIPELINE_MODE_NOT_SET;
3510 inputVectorDimensions = 0;
3511 outputVectorDimensions = 0;
3512 predictedClassLabel = 0;
3513 predictedClusterLabel = 0;
3514 predictionModuleIndex = 0;
3515 numTrainingSamples = 0;
3519 testSquaredError = 0;
3520 testRejectionPrecision = 0;
3521 testRejectionRecall = 0;
3525 regressifier = NULL;
3527 contextModules.
resize( NUM_CONTEXT_LEVELS );
3531 bool GestureRecognitionPipeline::updateTestMetrics(
const UINT classLabel,
const UINT predictedClassLabel,
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter){
3536 UINT predictedClassLabelIndex =0;
3537 bool predictedClassLabelIndexFound =
false;
3540 predictedClassLabelIndex = k;
3541 predictedClassLabelIndexFound =
true;
3546 if( !predictedClassLabelIndexFound && (nullRejectionEnabled ==
false || predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL) ){
3547 errorLog <<
"Failed to find class label index for label: " << predictedClassLabel << std::endl;
3552 UINT actualClassLabelIndex = 0;
3555 actualClassLabelIndex = k;
3561 if( classLabel == predictedClassLabel ){
3565 if( nullRejectionEnabled ==
false ){
3568 if( classLabel == predictedClassLabel ){
3570 testPrecision[ predictedClassLabelIndex ]++;
3573 precisionCounter[ predictedClassLabelIndex ]++;
3576 if( classLabel == predictedClassLabel ){
3578 testRecall[ predictedClassLabelIndex ]++;
3581 recallCounter[ actualClassLabelIndex ]++;
3584 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3585 confusionMatrixCounter[ actualClassLabelIndex ]++;
3589 if( predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3590 if( classLabel == predictedClassLabel ){
3592 testPrecision[ predictedClassLabelIndex ]++;
3595 precisionCounter[ predictedClassLabelIndex ]++;
3599 if( classLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3600 if( classLabel == predictedClassLabel ){
3602 testRecall[ predictedClassLabelIndex ]++;
3605 recallCounter[ actualClassLabelIndex ]++;
3609 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3610 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionPrecision++;
3611 rejectionPrecisionCounter++;
3615 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3616 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionRecall++;
3617 rejectionRecallCounter++;
3621 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) actualClassLabelIndex = 0;
3622 else actualClassLabelIndex++;
3623 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) predictedClassLabelIndex = 0;
3624 else predictedClassLabelIndex++;
3625 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3626 confusionMatrixCounter[ actualClassLabelIndex ]++;
3632 bool GestureRecognitionPipeline::computeTestMetrics(
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter,
const UINT numTestSamples){
3635 testAccuracy = testAccuracy/Float(numTestSamples) * 100.0;
3638 if( precisionCounter[k] > 0 ) testPrecision[k] /= precisionCounter[k];
3639 else testPrecision[k] = 0;
3640 if( recallCounter[k] > 0 ) testRecall[k] /= recallCounter[k];
3641 else testRecall[k] = 0;
3643 if( precisionCounter[k] + recallCounter[k] > 0 )
3644 testFMeasure[k] = 2 * ((testPrecision[k]*testRecall[k])/(testPrecision[k]+testRecall[k]));
3645 else testFMeasure[k] = 0;
3647 if( rejectionPrecisionCounter > 0 ) testRejectionPrecision /= rejectionPrecisionCounter;
3648 if( rejectionRecallCounter > 0 ) testRejectionRecall /= rejectionRecallCounter;
3651 for(UINT r=0; r<confusionMatrixCounter.size(); r++){
3652 if( confusionMatrixCounter[r] > 0 ){
3653 for(UINT c=0; c<testConfusionMatrix.
getNumCols(); c++){
3654 testConfusionMatrix[r][c] /= confusionMatrixCounter[r];
3663 std::string model =
"";
3665 switch( pipelineMode ){
3666 case PIPELINE_MODE_NOT_SET:
3668 case CLASSIFICATION_MODE:
3674 case REGRESSION_MODE:
3688 switch( pipelineMode ){
3689 case PIPELINE_MODE_NOT_SET:
3690 return "PIPELINE_MODE_NOT_SET";
3692 case CLASSIFICATION_MODE:
3693 return "CLASSIFICATION_MODE";
3695 case REGRESSION_MODE:
3696 return "REGRESSION_MODE";
3699 return "ERROR_UNKNWON_PIPELINE_MODE";
3703 return "ERROR_UNKNWON_PIPELINE_MODE";
3706 std::string GestureRecognitionPipeline::getInfo()
const{
3711 if( pipelineModeAsString ==
"PIPELINE_MODE_NOT_SET" ){
3712 return PIPELINE_MODE_NOT_SET;
3714 if( pipelineModeAsString ==
"CLASSIFICATION_MODE" ){
3715 return CLASSIFICATION_MODE;
3717 if( pipelineModeAsString ==
"REGRESSION_MODE" ){
3718 return REGRESSION_MODE;
3720 return PIPELINE_MODE_NOT_SET;
bool removePostProcessingModule(const UINT moduleIndex)
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
Float getTrainingSSError() const
UINT getOutputVectorDimensionsSize() const
virtual bool predict(VectorFloat inputVector)
UINT getNumPreProcessingModules() const
VectorFloat getNullRejectionThresholds() const
bool removeAllContextModules()
GestureRecognitionPipeline & operator<<(const PreProcessing &module)
static std::string toString(const int &i)
bool getIsPipelineInClassificationMode() const
VectorFloat getClassDistances() const
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
bool addSample(const VectorFloat &sample)
UINT getNumSamples() const
bool train(const ClassificationData &trainingData)
Float getTestRMSError() const
TestResult getTestResults() const
virtual bool deepCopyFrom(const PreProcessing *rhs)
bool getIsPipelineModeSet() const
virtual bool predict_(VectorFloat &inputVector)
bool getIsPipelineInRegressionMode() const
bool addSample(UINT classLabel, const VectorFloat &sample)
Vector< UINT > getClassLabels() const
ClassificationData getTestFoldData(const UINT foldIndex) const
MatrixFloat getTestConfusionMatrix() const
VectorFloat getNullRejectionThresholds() const
UINT getNumPostProcessingModules() const
bool removeContextModule(const UINT contextLevel, const UINT moduleIndex)
PreProcessing * createNewInstance() const
std::string getClassifierType() const
Vector< ClassTracker > getClassTracker() const
virtual UINT getNumClasses() const
VectorFloat getClusterLikelihoods() const
Float getMaximumLikelihood() const
bool getTimeseriesCompatible() const
Float getTestTime() const
std::string getClustererType() const
bool resetPlaybackIndex(const UINT playbackIndex)
VectorFloat getPreProcessedData() const
Float getTestRejectionRecall() const
UINT getNumDimensions() const
virtual bool resize(const unsigned int size)
bool setNumDimensions(UINT numDimensions)
RegressionData getTrainingFoldData(const UINT foldIndex) const
virtual bool train(ClassificationData trainingData)
virtual bool deepCopyFrom(const Clusterer *clusterer)
Float getTestAccuracy() const
bool removeAllFeatureExtractionModules()
Float getRootMeanSquaredTrainingError() const
UINT getNumSamples() const
UINT getNumOutputDimensions() const
Regressifier * createNewInstance() const
bool addContextModule(const Context &contextModule, UINT contextLevel, UINT insertIndex=INSERT_AT_END_INDEX)
bool preProcessData(VectorFloat inputVector, bool computeFeatures=true)
Float getCrossValidationAccuracy() const
static Regressifier * createInstanceFromString(const std::string ®ressifierType)
UINT getInputVectorDimensionsSize() const
bool setRegressifier(const Regressifier ®ressifier)
UINT getPredictionModuleIndexPosition() const
UINT getNumInputDimensions() const
Classifier * getClassifier() const
bool setAllowNullGestureClass(bool allowNullGestureClass)
bool removeFeatureExtractionModule(UINT moduleIndex)
bool removeAllPreProcessingModules()
static std::string intToString(const int &i)
std::string getLastErrorMessage() const
bool setClassifier(const Classifier &classifier)
signed long getMilliSeconds()
Vector< TestInstanceResult > getTestInstanceResults() const
This file contains the GestureRecognitionPipeline class.
UINT getNumTrainingSamples() const
std::string getPipelineModeAsString() const
static PreProcessing * createInstanceFromString(std::string const &preProcessingType)
bool setAllValues(const T &value)
bool setInputAndTargetDimensions(const UINT numInputDimensions, const UINT numTargetDimensions)
virtual bool save(const std::string filename) const
virtual bool deepCopyFrom(const Regressifier *regressifier)
Clusterer * getClusterer() const
UINT getNumDimensions() const
bool getIsPreProcessingSet() const
virtual bool load(const std::string filename)
virtual bool deepCopyFrom(const Classifier *classifier)
bool getIsClustererSet() const
bool predict(const VectorFloat &inputVector)
UINT getNumSamples() const
bool load(const std::string &filename)
UINT getNumTargetDimensions() const
ClassificationSample getNextSample()
UINT getUnProcessedPredictedClassLabel() const
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
UINT getNumClassesInModel() const
Float getTotalSquaredTrainingError() const
Vector< UINT > getClusterLabels() const
bool addPreProcessingModule(const PreProcessing &preProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool getNullRejectionEnabled() const
bool setClusterer(const Clusterer &clusterer)
std::string getRegressifierType() const
UINT getPredictedClassLabel() const
GestureRecognitionPipeline & operator=(const GestureRecognitionPipeline &rhs)
Float getTrainingRMSError() const
bool savePipelineToFile(const std::string &filename) const
UINT getPipelineModeFromString(std::string pipelineMode) const
bool getIsFeatureExtractionSet() const
UINT getNumTestSamples() const
static Classifier * createInstanceFromString(std::string const &classifierType)
bool save(const std::string &filename) const
bool reserve(const UINT N)
bool getIsContextSet() const
bool getIsClassifierSet() const
unsigned int getNumRows() const
UINT getNumDimensions() const
UINT getNumClasses() const
virtual std::string getModelAsString() const
unsigned int getNumCols() const
UINT getPredictedClusterLabel() const
Context * getContextModule(const UINT contextLevel, const UINT moduleIndex) const
bool removeAllPostProcessingModules()
Float getMaximumLikelihood() const
Context * createNewInstance() const
bool setFeatureExtractionModule(const FeatureExtraction &featureExtractionModule)
bool addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool loadPipelineFromFile(const std::string &filename)
UINT getNumInputFeatures() const
UINT getNumClasses() const
Vector< TestResult > getCrossValidationResults() const
FeatureExtraction * getFeatureExtractionModule(const UINT moduleIndex) const
bool getIsPostProcessingSet() const
bool setInfo(const std::string &info)
bool map(const VectorFloat &inputVector)
VectorFloat getClassLikelihoods() const
VectorFloat getRow(const unsigned int r) const
VectorFloat getClassDistances() const
virtual bool train_(ClassificationData &trainingData)
virtual ~GestureRecognitionPipeline(void)
bool notifyTestResultsObservers(const TestInstanceResult &data)
bool addPostProcessingModule(const PostProcessing &postProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool removePreProcessingModule(UINT moduleIndex)
UINT getNumClusters() const
UINT getNumDimensions() const
UINT getPredictedClassLabel() const
bool updateContextModule(bool value, UINT contextLevel=0, UINT moduleIndex=0)
VectorFloat getClassLikelihoods() const
bool setPostProcessingModule(const PostProcessing &postProcessingModule)
Vector< UINT > getClassLabels() const
virtual bool train_(MatrixFloat &trainingData)
VectorFloat getRegressionData() const
static PostProcessing * createInstanceFromString(std::string const &postProcessingType)
VectorFloat getRegressionData() const
PostProcessing * getPostProcessingModule(UINT moduleIndex) const
#define INSERT_AT_END_INDEX
virtual bool resize(const unsigned int r, const unsigned int c)
VectorFloat getTestFMeasure() const
Float getTestRejectionPrecision() const
PreProcessing * getPreProcessingModule(const UINT moduleIndex) const
VectorFloat getUnProcessedRegressionData() const
UINT getNumInputDimensions() const
UINT getNumFeatureExtractionModules() const
static Clusterer * createInstanceFromString(std::string const &ClustererType)
Regressifier * getRegressifier() const
VectorFloat getClusterDistances() const
VectorFloat getTestRecall() const
ClassificationData getTrainingFoldData(const UINT foldIndex) const
UINT getNumSamples() const
RegressionData getTestFoldData(const UINT foldIndex) const
bool test(const ClassificationData &testData)
bool push_back(const Vector< T > &sample)
Float getTestSSError() const
GestureRecognitionPipeline(void)
std::string getModelAsString() const
TimeSeriesClassificationData getTrainingFoldData(const UINT foldIndex) const
Float getMaximumLikelihood() const
bool getIsRegressifierSet() const
bool setPreProcessingModule(const PreProcessing &preProcessingModule)
VectorFloat getTestPrecision() const
bool addSample(const VectorFloat &inputVector, const VectorFloat &targetVector)
Classifier * createNewInstance() const
bool getIsInitialized() const
Float getTrainingTime() const
bool spiltDataIntoKFolds(const UINT K)
VectorFloat getFeatureExtractionData() const
UINT getNumSamples() const
Clusterer * createNewInstance() const
PostProcessing * createNewInstance() const
TimeSeriesClassificationData getTestFoldData(const UINT foldIndex) const