30 pipelineMode = PIPELINE_MODE_NOT_SET;
31 inputVectorDimensions = 0;
32 outputVectorDimensions = 0;
33 predictedClassLabel = 0;
34 predictedClusterLabel = 0;
35 predictionModuleIndex = 0;
36 numTrainingSamples = 0;
41 testRejectionPrecision = 0;
42 testRejectionRecall = 0;
48 contextModules.resize( NUM_CONTEXT_LEVELS );
50 debugLog.setProceedingText(
"[DEBUG GRP]");
51 errorLog.setProceedingText(
"[ERROR GRP]");
52 warningLog.setProceedingText(
"[WARNING GRP]");
53 testingLog.setProceedingText(
"[TEST GRP]");
61 pipelineMode = PIPELINE_MODE_NOT_SET;
62 inputVectorDimensions = 0;
63 outputVectorDimensions = 0;
64 predictedClassLabel = 0;
65 predictedClusterLabel = 0;
66 predictionModuleIndex = 0;
67 numTrainingSamples = 0;
72 testRejectionPrecision = 0;
73 testRejectionRecall = 0;
79 contextModules.resize( NUM_CONTEXT_LEVELS );
81 debugLog.setProceedingText(
"[DEBUG GRP]");
82 errorLog.setProceedingText(
"[ERROR GRP]");
83 warningLog.setProceedingText(
"[WARNING GRP]");
84 testingLog.setProceedingText(
"[TEST GRP]");
97 this->initialized = rhs.initialized;
98 this->trained = rhs.trained;
99 this->info = rhs.info;
100 this->inputVectorDimensions = rhs.inputVectorDimensions;
101 this->outputVectorDimensions = rhs.outputVectorDimensions;
102 this->predictedClassLabel = rhs.predictedClassLabel;
103 this->predictedClusterLabel = rhs.predictedClusterLabel;
104 this->pipelineMode = rhs.pipelineMode;
105 this->predictionModuleIndex = rhs.predictionModuleIndex;
106 this->numTrainingSamples = rhs.numTrainingSamples;
107 this->numTestSamples = rhs.numTestSamples;
108 this->testAccuracy = rhs.testAccuracy;
109 this->testRMSError = rhs.testRMSError;
110 this->testSquaredError = rhs.testSquaredError;
111 this->testTime = rhs.testTime;
112 this->trainingTime = rhs.trainingTime;
113 this->testFMeasure = rhs.testFMeasure;
114 this->testPrecision = rhs.testPrecision;
115 this->testRecall = rhs.testRecall;
116 this->regressionData = rhs.regressionData;
117 this->testRejectionPrecision = rhs.testRejectionPrecision;
118 this->testRejectionRecall = rhs.testRejectionRecall;
119 this->testConfusionMatrix = rhs.testConfusionMatrix;
120 this->crossValidationResults = rhs.crossValidationResults;
121 this->testResults = rhs.testResults;
124 this->debugLog = rhs.debugLog;
125 this->errorLog = rhs.errorLog;
126 this->trainingLog = rhs.trainingLog;
127 this->testingLog = rhs.testingLog;
128 this->warningLog = rhs.warningLog;
130 for(
unsigned int i=0; i<rhs.preProcessingModules.size(); i++){
134 for(
unsigned int i=0; i<rhs.featureExtractionModules.size(); i++){
150 for(
unsigned int i=0; i<rhs.postProcessingModules.size(); i++){
154 for(
unsigned int k=0; k<NUM_CONTEXT_LEVELS; k++){
155 for(
unsigned int i=0; i<rhs.contextModules[k].size(); i++){
161 this->trained = rhs.trained;
170 deleteAllPreProcessingModules();
171 deleteAllFeatureExtractionModules();
173 deleteRegressifier();
175 deleteAllPostProcessingModules();
176 deleteAllContextModules();
186 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, the classifier has not been set!" << endl;
191 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << endl;
207 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
209 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
220 bool okToAddProcessedData =
true;
221 UINT classLabel = trainingData[i].getClassLabel();
222 VectorDouble trainingSample = trainingData[i].getSample();
226 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
227 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
228 errorLog <<
"train(ClassificationData trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
229 errorLog << moduleIndex;
233 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
239 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
240 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
241 errorLog <<
"train(ClassificationData trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
242 errorLog << moduleIndex;
246 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
247 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
249 okToAddProcessedData =
false;
255 if( okToAddProcessedData ){
257 processedTrainingData.
addSample(classLabel, trainingSample);
264 warningLog <<
"train(ClassificationData trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << endl;
271 trained = classifier->
train_( processedTrainingData );
273 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier: " << classifier->
getLastErrorMessage() << endl;
290 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << endl;
295 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << endl;
317 double crossValidationAccuracy = 0;
320 vector< TestResult > cvResults(kFoldValue);
322 for(UINT k=0; k<kFoldValue; k++){
326 if( !
train( foldTrainingData ) ){
333 if( !
test( foldTestData ) ){
345 testAccuracy = crossValidationAccuracy / double(kFoldValue);
346 crossValidationResults = cvResults;
361 errorLog <<
"train(const TimeSeriesClassificationData &trainingData) - Failed To Train Classifier, the classifier has not been set!" << endl;
366 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << endl;
384 bool allowNullGestureClass =
true;
386 timeseriesClassificationData.setAllowNullGestureClass( allowNullGestureClass );
394 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
397 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
399 timeseriesClassificationData.setNumDimensions( trainingDataInputDimensionSize );
403 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
406 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
413 UINT classLabel = trainingData[i].getClassLabel();
414 MatrixDouble trainingSample = trainingData[i].getData();
419 bool resetPreprocessingModule =
true;
420 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
423 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
425 if( resetPreprocessingModule ){
426 preProcessingModules[moduleIndex]->reset();
430 if( preProcessingModules[moduleIndex]->getNumInputDimensions() != preProcessingModules[moduleIndex]->getNumOutputDimensions() ){
431 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. The number of inputDimensions (";
432 errorLog << preProcessingModules[moduleIndex]->getNumInputDimensions();
433 errorLog <<
") in PreProcessingModule ";
434 errorLog << moduleIndex;
435 errorLog <<
" do not match the number of outputDimensions (";
436 errorLog << preProcessingModules[moduleIndex]->getNumOutputDimensions();
441 if( !preProcessingModules[moduleIndex]->process( sample ) ){
442 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. PreProcessingModuleIndex: ";
443 errorLog << moduleIndex;
447 sample = preProcessingModules[moduleIndex]->getProcessedData();
451 resetPreprocessingModule =
false;
454 for(UINT c=0; c<sample.size(); c++){
455 trainingSample[r][c] = sample[c];
462 processedTrainingData.addSample(classLabel,trainingSample);
467 for(UINT i=0; i<processedTrainingData.getNumSamples(); i++){
468 UINT classLabel = processedTrainingData[i].getClassLabel();
469 MatrixDouble trainingSample = processedTrainingData[i].getData();
470 bool featureDataReady =
false;
471 bool resetFeatureExtractionModules =
true;
473 VectorDouble inputVector;
476 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
478 featureDataReady =
true;
483 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
485 if( resetFeatureExtractionModules ){
486 featureExtractionModules[moduleIndex]->reset();
489 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
490 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: ";
491 errorLog << moduleIndex;
498 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
499 featureDataReady = featureExtractionModules[moduleIndex]->getFeatureDataReady();
503 resetFeatureExtractionModules =
false;
505 if( featureDataReady ){
508 if( !featureData.
push_back( inputVector ) ){
509 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature vector to feature data matrix! FeatureExtractionModuleIndex: " << endl;
512 }
else classificationData.
addSample(classLabel, inputVector);
517 if( !featureData.
push_back( inputVector ) ){
518 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature vector to feature data matrix! FeatureExtractionModuleIndex: " << endl;
522 else classificationData.
addSample(classLabel, inputVector);
532 numTrainingSamples = timeseriesClassificationData.getNumSamples();
533 trained = classifier->
train( timeseriesClassificationData );
536 trained = classifier->
train( classificationData );
540 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier" << classifier->
getLastErrorMessage() << endl;
557 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << endl;
562 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << endl;
578 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Spilt Dataset into KFolds!" << endl;
583 double crossValidationAccuracy = 0;
587 for(UINT k=0; k<kFoldValue; k++){
591 if( !
train( foldTrainingData ) ){
592 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to train pipeline for fold " << k <<
"." << endl;
599 if( !
test( foldTestData ) ){
600 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to test pipeline for fold " << k <<
"." << endl;
611 testAccuracy = crossValidationAccuracy / double(kFoldValue);
646 numInputs = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
650 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
654 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
661 VectorDouble inputVector = trainingData[i].getInputVector();
662 VectorDouble targetVector = trainingData[i].getTargetVector();
665 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
666 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
667 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. PreProcessingModuleIndex: " << moduleIndex << endl;
671 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
676 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
677 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
678 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: " << moduleIndex << endl;
682 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
687 if( !processedTrainingData.
addSample(inputVector,targetVector) ){
688 errorLog <<
"train(const RegressionData &trainingData) - Failed to add processed training sample to training data" << endl;
698 trained = regressifier->
train( processedTrainingData );
700 errorLog <<
"train(const RegressionData &trainingData) - Failed To Train Regressifier: " << regressifier->
getLastErrorMessage() << endl;
704 errorLog <<
"train(const RegressionData &trainingData) - Classifier is not set" << endl;
721 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, the regressifier has not been set!" << endl;
726 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, there is no training data!" << endl;
748 double crossValidationAccuracy = 0;
751 for(UINT k=0; k<kFoldValue; k++){
755 if( !
train( foldTrainingData ) ){
762 if( !
test( foldTestData ) ){
773 testAccuracy = crossValidationAccuracy / double(kFoldValue);
788 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, the clusterer has not been set!" << endl;
793 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, there is no training data!" << endl;
809 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
811 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
822 bool okToAddProcessedData =
true;
823 VectorDouble trainingSample = trainingData[i];
827 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
828 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
829 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
830 errorLog << moduleIndex;
834 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
840 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
841 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
842 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
843 errorLog << moduleIndex;
847 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
848 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
850 okToAddProcessedData =
false;
856 if( okToAddProcessedData ){
858 processedTrainingData.
addSample(trainingSample);
865 warningLog <<
"train(const ClassificationData &trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << endl;
872 trained = clusterer->
train_( processedTrainingData );
874 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer: " << clusterer->
getLastErrorMessage() << endl;
891 errorLog <<
"test(const ClassificationData &testData) - Classifier is not trained" << endl;
897 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 <<
")" << endl;
902 errorLog <<
"test(const ClassificationData &testData) - The classifier has not been set" << endl;
910 bool classLabelValidationPassed =
true;
912 bool labelFound =
false;
921 classLabelValidationPassed =
false;
922 errorLog <<
"test(const ClassificationData &testData) - The test dataset contains a class label (" << testData.
getClassTracker()[i].classLabel <<
") that is not in the model!" << endl;
926 if( !classLabelValidationPassed ){
927 errorLog <<
"test(const ClassificationData &testData) - Model Class Labels: ";
935 double rejectionPrecisionCounter = 0;
936 double rejectionRecallCounter = 0;
938 VectorDouble precisionCounter(classifier->
getNumClasses(), 0);
940 VectorDouble confusionMatrixCounter(confusionMatrixSize,0);
943 testConfusionMatrix.
resize(confusionMatrixSize, confusionMatrixSize);
947 testPrecision.clear();
949 testFMeasure.clear();
961 for(UINT i=0; i<numTestSamples; i++){
962 UINT classLabel = testData[i].getClassLabel();
963 VectorDouble testSample = testData[i].getSample();
967 errorLog <<
"test(const ClassificationData &testData) - Prediction failed for test sample at index: " << i << endl;
974 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
975 errorLog <<
"test(const ClassificationData &testData) - Failed to update test metrics at test sample index: " << i << endl;
986 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, numTestSamples) ){
987 errorLog <<
"test(const ClassificationData &testData) - Failed to compute test metrics!" << endl;
1003 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been trained" << endl;
1009 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 <<
")" << endl;
1014 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been set" << endl;
1021 double rejectionPrecisionCounter = 0;
1022 double rejectionRecallCounter = 0;
1025 VectorDouble precisionCounter(K, 0);
1026 VectorDouble recallCounter(K, 0);
1027 VectorDouble confusionMatrixCounter(confusionMatrixSize,0);
1030 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1034 testPrecision.resize(K, 0);
1035 testRecall.resize(K, 0);
1036 testFMeasure.resize(K, 0);
1045 for(UINT i=0; i<M; i++){
1046 UINT classLabel = testData[i].getClassLabel();
1051 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to run prediction for test sample index: " << i << endl;
1058 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1059 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to update test metrics at test sample index: " << i << endl;
1065 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, M) ){
1066 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to compute test metrics!" << endl;
1082 errorLog <<
"test(const TimeSeriesClassificationDataStream &testData) - The classifier has not been trained" << endl;
1088 errorLog <<
"test(const TimeSeriesClassificationDataStream &testData) - The dimensionality of the test data (" +
Util::toString(testData.
getNumDimensions()) +
") does not match that of the input vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << endl;
1093 errorLog <<
"test(const TimeSeriesClassificationDataStream &testData) - The classifier has not been set" << endl;
1105 VectorDouble confusionMatrixCounter(confusionMatrixSize,0);
1108 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1131 UINT classLabel = sample.getClassLabel();
1132 VectorDouble testSample = sample.getSample();
1136 errorLog <<
"test(const TimeSeriesClassificationDataStream &testData) - Prediction Failed! " << classifier->
getLastErrorMessage() << endl;
1150 if( classLabel == predictedClassLabel ) testAccuracy++;
1158 testingLog <<
"test iteration: " << i;
1159 testingLog <<
"\tClassLabel: " << classLabel;
1160 testingLog <<
"\tPredictedClassLabel: " << predictedClassLabel;
1172 testAccuracy = testAccuracy / double( testData.
getNumSamples() ) * 100.0;
1174 testingLog <<
"Test complete. Total testing time: " << testTime << endl;
1186 errorLog <<
"test(const RegressionData &testData) - Regressifier is not trained" << endl;
1192 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 <<
")" << endl;
1197 errorLog <<
"test(const RegressionData &testData) - The regressifier has not been set" << endl;
1202 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() <<
")" << endl;
1210 testResults.resize( numTestSamples );
1217 testSquaredError = 0;
1219 for(UINT i=0; i<numTestSamples; i++){
1220 VectorDouble inputVector = testData[i].getInputVector();
1221 VectorDouble targetVector = testData[i].getTargetVector();
1224 if( !
map( inputVector ) ){
1225 errorLog <<
"test(const RegressionData &testData) - Failed to map input vector!" << endl;
1232 for(UINT j=0; j<targetVector.size(); j++){
1233 sum += SQR( regressionData[j]-targetVector[j] );
1236 testSquaredError += sum;
1239 testResults[i].setRegressionResult(i,regressionData,targetVector);
1246 testRMSError = sqrt( testSquaredError /
double( testData.
getNumSamples() ) );
1257 errorLog <<
"predict(const VectorDouble &inputVector) - The classifier has not been trained" << endl;
1262 if( inputVector.size() != inputVectorDimensions ){
1263 errorLog <<
"predict(const VectorDouble &inputVector) - The dimensionality of the input vector (" << int(inputVector.size()) <<
") does not match that of the input vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << endl;
1268 return predict_classifier( inputVector );
1272 return predict_regressifier( inputVector );
1276 return predict_clusterer( inputVector );
1279 errorLog <<
"predict(const VectorDouble &inputVector) - Neither a classifier, regressifer or clusterer is set" << endl;
1287 errorLog <<
"predict(const MatrixDouble &inputMatrix) - The classifier has not been trained" << endl;
1292 if( input.
getNumCols() != inputVectorDimensions ){
1293 errorLog <<
"predict(const MatrixDouble &inputMatrix) - The dimensionality of the input matrix (" << input.
getNumCols() <<
") does not match that of the input vector dimensions of the pipeline (" << inputVectorDimensions <<
")" << endl;
1298 errorLog <<
"predict(const MatrixDouble &inputMatrix) - A classifier has not been set" << endl;
1304 predictedClassLabel = 0;
1307 predictionModuleIndex = START_OF_PIPELINE;
1312 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1313 MatrixDouble tmpMatrix( inputMatrix.
getNumRows(), preProcessingModules[moduleIndex]->getNumOutputDimensions() );
1315 for(UINT i=0; i<inputMatrix.
getNumRows(); i++){
1316 if( !preProcessingModules[moduleIndex]->process( inputMatrix.
getRowVector(i) ) ){
1317 errorLog <<
"predict(const MatrixDouble &inputMatrix) - Failed to PreProcess Input Matrix. PreProcessingModuleIndex: " << moduleIndex << endl;
1320 tmpMatrix.setRowVector( preProcessingModules[moduleIndex]->getProcessedData(), i );
1324 inputMatrix = tmpMatrix;
1329 predictionModuleIndex = AFTER_PREPROCESSING;
1335 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1336 MatrixDouble tmpMatrix( inputMatrix.
getNumRows(), featureExtractionModules[moduleIndex]->getNumOutputDimensions() );
1338 for(UINT i=0; i<inputMatrix.
getNumRows(); i++){
1339 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputMatrix.
getRowVector(i) ) ){
1340 errorLog <<
"predict(const MatrixDouble &inputMatrix) - Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << endl;
1343 tmpMatrix.setRowVector( featureExtractionModules[moduleIndex]->getFeatureVector(), i );
1347 inputMatrix = tmpMatrix;
1352 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1356 if( !classifier->
predict( inputMatrix ) ){
1357 errorLog <<
"predict(const MatrixDouble &inputMatrix) - Prediction Failed! " << classifier->
getLastErrorMessage() << endl;
1366 predictionModuleIndex = AFTER_CLASSIFIER;
1369 if( pipelineMode != CLASSIFICATION_MODE){
1370 errorLog <<
"predict_(const MatrixDouble &inputMatrix) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << endl;
1375 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1378 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1381 data[0] = predictedClassLabel;
1384 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1385 errorLog <<
"predict(const MatrixDouble &inputMatrix) - The size of the data vector (" << int(data.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << endl;
1390 if( !postProcessingModules[moduleIndex]->process( data ) ){
1391 errorLog <<
"predict(const MatrixDouble &inputMatrix) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << endl;
1396 data = postProcessingModules[moduleIndex]->getProcessedData();
1400 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1402 data = postProcessingModules[moduleIndex]->getProcessedData();
1405 if( data.size() != 1 ){
1406 errorLog <<
"predict(const MatrixDouble &inputMatrix) - 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!" << endl;
1411 predictedClassLabel = (UINT)data[0];
1419 predictionModuleIndex = END_OF_PIPELINE;
1425 return predict_regressifier( inputVector );
1428 bool GestureRecognitionPipeline::predict_classifier(
const VectorDouble &input){
1430 predictedClassLabel = 0;
1431 VectorDouble inputVector = input;
1434 predictionModuleIndex = START_OF_PIPELINE;
1435 if( contextModules[ START_OF_PIPELINE ].size() > 0 ){
1436 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1437 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1438 errorLog <<
"predict_classifier(const VectorDouble &inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1441 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1444 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1450 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1451 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1452 errorLog <<
"predict_classifier(const VectorDouble &inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << endl;
1455 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1460 predictionModuleIndex = AFTER_PREPROCESSING;
1461 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1462 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1463 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1464 errorLog <<
"predict_classifier(VectorDouble inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << endl;
1467 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1468 predictionModuleIndex = AFTER_PREPROCESSING;
1471 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1477 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1478 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1479 errorLog <<
"predict_classifier(VectorDouble inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << endl;
1482 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1487 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1488 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1489 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1490 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1491 errorLog <<
"predict_classifier(VectorDouble inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << endl;
1494 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1495 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1498 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1503 if( !classifier->
predict(inputVector) ){
1504 errorLog <<
"predict_classifier(VectorDouble inputVector) - Prediction Failed! " << classifier->
getLastErrorMessage() << endl;
1510 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1511 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1512 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( vector<double>(1,predictedClassLabel) ) ){
1513 errorLog <<
"predict_classifier(VectorDouble inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << endl;
1516 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1517 predictionModuleIndex = AFTER_CLASSIFIER;
1520 predictedClassLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1525 predictionModuleIndex = AFTER_CLASSIFIER;
1528 if( pipelineMode != CLASSIFICATION_MODE){
1529 errorLog <<
"predict_classifier(VectorDouble inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << endl;
1534 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1537 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1540 data[0] = predictedClassLabel;
1543 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1544 errorLog <<
"predict_classifier(VectorDouble inputVector) - The size of the data vector (" << int(data.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << endl;
1549 if( !postProcessingModules[moduleIndex]->process( data ) ){
1550 errorLog <<
"predict_classifier(VectorDouble inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << endl;
1555 data = postProcessingModules[moduleIndex]->getProcessedData();
1559 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1561 data = postProcessingModules[moduleIndex]->getProcessedData();
1564 if( data.size() != 1 ){
1565 errorLog <<
"predict_classifier(VectorDouble 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!" << endl;
1570 predictedClassLabel = (UINT)data[0];
1577 predictionModuleIndex = END_OF_PIPELINE;
1578 if( contextModules[ END_OF_PIPELINE ].size() ){
1579 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1580 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( vector<double>(1,predictedClassLabel) ) ){
1581 errorLog <<
"predict_classifier(VectorDouble inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1584 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1585 predictionModuleIndex = END_OF_PIPELINE;
1588 predictedClassLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
1595 bool GestureRecognitionPipeline::predict_regressifier(
const VectorDouble &input){
1597 VectorDouble inputVector = input;
1600 predictionModuleIndex = START_OF_PIPELINE;
1601 if( contextModules[ START_OF_PIPELINE ].size() ){
1602 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1603 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1604 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1607 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1610 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1616 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1617 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1618 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << endl;
1621 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1626 predictionModuleIndex = AFTER_PREPROCESSING;
1627 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1628 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1629 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1630 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << endl;
1633 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1634 predictionModuleIndex = AFTER_PREPROCESSING;
1637 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1643 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1644 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1645 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << endl;
1648 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1653 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1654 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1655 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1656 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1657 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << endl;
1660 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1661 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1664 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1669 if( !regressifier->
predict(inputVector) ){
1670 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Prediction Failed! " << regressifier->
getLastErrorMessage() << endl;
1676 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1677 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1678 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( regressionData ) ){
1679 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << endl;
1682 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1683 predictionModuleIndex = AFTER_CLASSIFIER;
1686 regressionData = contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData();
1691 predictionModuleIndex = AFTER_CLASSIFIER;
1694 if( pipelineMode != REGRESSION_MODE ){
1695 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Pipeline Mode Is Not In RegressionMode!" << endl;
1699 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1700 if( regressionData.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1701 errorLog <<
"predict_regressifier(VectorDouble inputVector) - The size of the regression vector (" << int(regressionData.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << endl;
1705 if( !postProcessingModules[moduleIndex]->process( regressionData ) ){
1706 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << endl;
1709 regressionData = postProcessingModules[moduleIndex]->getProcessedData();
1715 predictionModuleIndex = END_OF_PIPELINE;
1716 if( contextModules[ END_OF_PIPELINE ].size() ){
1717 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1718 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1719 errorLog <<
"predict_regressifier(VectorDouble inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1722 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1723 predictionModuleIndex = END_OF_PIPELINE;
1726 regressionData = contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData();
1733 bool GestureRecognitionPipeline::predict_clusterer(
const VectorDouble &input){
1735 VectorDouble inputVector = input;
1736 predictedClusterLabel = 0;
1739 predictionModuleIndex = START_OF_PIPELINE;
1740 if( contextModules[ START_OF_PIPELINE ].size() ){
1741 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1742 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1743 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1746 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1749 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1755 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1756 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1757 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << endl;
1760 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1765 predictionModuleIndex = AFTER_PREPROCESSING;
1766 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1767 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1768 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1769 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << endl;
1772 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1773 predictionModuleIndex = AFTER_PREPROCESSING;
1776 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1782 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1783 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1784 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << endl;
1787 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1792 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1793 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1794 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1795 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1796 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << endl;
1799 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1800 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1803 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1808 if( !clusterer->
predict(inputVector) ){
1809 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Prediction Failed! " << clusterer->
getLastErrorMessage() << endl;
1815 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1816 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1817 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( vector<double>(1,predictedClusterLabel) ) ){
1818 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << endl;
1821 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1822 predictionModuleIndex = AFTER_CLASSIFIER;
1825 predictedClusterLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1830 predictionModuleIndex = AFTER_CLASSIFIER;
1833 if( pipelineMode != CLASSIFICATION_MODE){
1834 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << endl;
1839 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1842 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1845 data[0] = predictedClusterLabel;
1848 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1849 errorLog <<
"predict_clusterer(VectorDouble inputVector) - The size of the data vector (" << int(data.size()) <<
") does not match that of the postProcessingModule (" << postProcessingModules[moduleIndex]->getNumInputDimensions() <<
") at the moduleIndex: " << moduleIndex << endl;
1854 if( !postProcessingModules[moduleIndex]->process( data ) ){
1855 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << endl;
1860 data = postProcessingModules[moduleIndex]->getProcessedData();
1864 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1866 data = postProcessingModules[moduleIndex]->getProcessedData();
1869 if( data.size() != 1 ){
1870 errorLog <<
"predict_clusterer(VectorDouble 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!" << endl;
1875 predictedClusterLabel = (UINT)data[0];
1882 predictionModuleIndex = END_OF_PIPELINE;
1883 if( contextModules[ END_OF_PIPELINE ].size() ){
1884 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1885 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( vector<double>(1,predictedClassLabel) ) ){
1886 errorLog <<
"predict_clusterer(VectorDouble inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << endl;
1889 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1890 predictionModuleIndex = END_OF_PIPELINE;
1893 predictedClusterLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
1904 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1905 if( !preProcessingModules[ moduleIndex ]->
reset() ){
1906 errorLog <<
"Failed To Reset PreProcessingModule " << moduleIndex << endl;
1914 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1915 if( !featureExtractionModules[ moduleIndex ]->
reset() ){
1916 errorLog <<
"Failed To Reset FeatureExtractionModule " << moduleIndex << endl;
1924 if( !classifier->
reset() ){
1932 if( !regressifier->
reset() ){
1933 errorLog <<
"Failed To Reset Regressifier! " << regressifier->
getLastErrorMessage() << endl;
1940 if( !clusterer->
reset() ){
1948 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1949 if( !postProcessingModules[ moduleIndex ]->
reset() ){
1950 errorLog <<
"Failed To Reset PostProcessingModule " << moduleIndex << endl;
1966 errorLog <<
"Failed to write pipeline to file as the pipeline has not been initialized yet!" << endl;
1972 file.open(filename.c_str(), iostream::out );
1974 if( !file.is_open() ){
1975 errorLog <<
"Failed to open file with filename: " << filename << endl;
1980 file <<
"GRT_PIPELINE_FILE_V3.0\n";
1986 file <<
"Info: " << info << endl;
1989 file <<
"PreProcessingModuleDatatypes:";
1991 file <<
"\t" << preProcessingModules[i]->getPreProcessingType();
1995 file <<
"FeatureExtractionModuleDatatypes:";
1997 file <<
"\t" << featureExtractionModules[i]->getFeatureExtractionType();
2001 switch( pipelineMode ){
2002 case PIPELINE_MODE_NOT_SET:
2004 case CLASSIFICATION_MODE:
2006 else file <<
"ClassificationModuleDatatype:\tCLASSIFIER_NOT_SET" << endl;
2008 case REGRESSION_MODE:
2010 else file <<
"RegressionModuleDatatype:\tREGRESSIFIER_NOT_SET" << endl;
2014 else file <<
"ClusterModuleDatatype:\tCLUSTERER_NOT_SET" << endl;
2020 file <<
"PostProcessingModuleDatatypes:";
2022 file <<
"\t" << postProcessingModules[i]->getPostProcessingType();
2029 if( !preProcessingModules[i]->saveModelToFile( file ) ){
2030 errorLog <<
"Failed to write preprocessing module " << i <<
" settings to file!" << endl;
2039 if( !featureExtractionModules[i]->saveModelToFile( file ) ){
2040 errorLog <<
"Failed to write feature extraction module " << i <<
" settings to file!" << endl;
2046 switch( pipelineMode ){
2047 case PIPELINE_MODE_NOT_SET:
2049 case CLASSIFICATION_MODE:
2052 errorLog <<
"Failed to write classifier model to file!" << endl;
2058 case REGRESSION_MODE:
2061 errorLog <<
"Failed to write regressifier model to file!" << endl;
2070 errorLog <<
"Failed to write clusterer model to file!" << endl;
2083 if( !postProcessingModules[i]->saveModelToFile( file ) ){
2084 errorLog <<
"Failed to write post processing module " << i <<
" settings to file!" << endl;
2107 file.open(filename.c_str(), iostream::in );
2109 if( !file.is_open() ){
2110 errorLog <<
"loadPipelineFromFile(string filename) - Failed to open file with filename: " << filename << endl;
2118 if( word !=
"GRT_PIPELINE_FILE_V3.0" ){
2119 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read file header" << endl;
2126 if( word !=
"PipelineMode:" ){
2127 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PipelineMode" << endl;
2136 if( word !=
"NumPreprocessingModules:" ){
2137 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPreprocessingModules header" << endl;
2141 unsigned int numPreprocessingModules;
2142 file >> numPreprocessingModules;
2146 if( word !=
"NumFeatureExtractionModules:" ){
2147 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumFeatureExtractionModules header" << endl;
2151 unsigned int numFeatureExtractionModules;
2152 file >> numFeatureExtractionModules;
2156 if( word !=
"NumPostprocessingModules:" ){
2157 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPostprocessingModules header" << endl;
2161 unsigned int numPostprocessingModules;
2162 file >> numPostprocessingModules;
2166 if( word !=
"Trained:" ){
2167 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Trained header" << endl;
2175 if( word !=
"Info:" ){
2176 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Info header" << endl;
2183 while( word !=
"PreProcessingModuleDatatypes:" ){
2189 if( numPreprocessingModules > 0 ) preProcessingModules.resize(numPreprocessingModules,NULL);
2190 if( numFeatureExtractionModules > 0 ) featureExtractionModules.resize(numFeatureExtractionModules,NULL);
2191 if( numPostprocessingModules > 0 ) postProcessingModules.resize(numPostprocessingModules,NULL);
2194 if( word !=
"PreProcessingModuleDatatypes:" ){
2195 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PreProcessingModuleDatatypes" << endl;
2199 for(UINT i=0; i<numPreprocessingModules; i++){
2202 if( preProcessingModules[i] == NULL ){
2203 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create preprocessing instance from string: " << word << endl;
2211 if( word !=
"FeatureExtractionModuleDatatypes:" ){
2212 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read FeatureExtractionModuleDatatypes" << endl;
2216 for(UINT i=0; i<numFeatureExtractionModules; i++){
2218 featureExtractionModules[i] = FeatureExtraction::createInstanceFromString( word );
2219 if( featureExtractionModules[i] == NULL ){
2220 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create feature extraction instance from string: " << word << endl;
2226 switch( pipelineMode ){
2227 case PIPELINE_MODE_NOT_SET:
2229 case CLASSIFICATION_MODE:
2231 if( word !=
"ClassificationModuleDatatype:" ){
2232 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClassificationModuleDatatype" << endl;
2241 if( classifier == NULL ){
2242 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create classifier instance from string: " << word << endl;
2247 case REGRESSION_MODE:
2249 if( word !=
"RegressionModuleDatatype:" ){
2250 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read RegressionModuleDatatype" << endl;
2259 if( regressifier == NULL ){
2260 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create regressifier instance from string: " << word << endl;
2267 if( word !=
"ClusterModuleDatatype:" ){
2268 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClusterModuleDatatype" << endl;
2277 if( clusterer == NULL ){
2278 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create clusterer instance from string: " << word << endl;
2289 if( word !=
"PostProcessingModuleDatatypes:" ){
2290 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PostProcessingModuleDatatypes" << endl;
2294 for(UINT i=0; i<numPostprocessingModules; i++){
2300 for(UINT i=0; i<numPreprocessingModules; i++){
2303 if( !preProcessingModules[i]->loadModelFromFile( file ) ){
2304 errorLog <<
"Failed to load preprocessing module " << i <<
" settings from file!" << endl;
2311 for(UINT i=0; i<numFeatureExtractionModules; i++){
2314 if( !featureExtractionModules[i]->loadModelFromFile( file ) ){
2315 errorLog <<
"Failed to load feature extraction module " << i <<
" settings from file!" << endl;
2322 switch( pipelineMode ){
2323 case PIPELINE_MODE_NOT_SET:
2325 case CLASSIFICATION_MODE:
2327 errorLog <<
"Failed to load classifier model from file!" << endl;
2332 case REGRESSION_MODE:
2334 errorLog <<
"Failed to load regressifier model from file!" << endl;
2341 errorLog <<
"Failed to load cluster model from file!" << endl;
2351 for(UINT i=0; i<numPostprocessingModules; i++){
2354 if( !postProcessingModules[i]->loadModelFromFile( file ) ){
2355 errorLog <<
"Failed to load post processing module " << i <<
" settings from file!" << endl;
2365 inputVectorDimensions = 0;
2367 if( numPreprocessingModules > 0 ){
2368 inputVectorDimensions = preProcessingModules[0]->getNumInputDimensions();
2370 if( numFeatureExtractionModules > 0 ){
2371 inputVectorDimensions = featureExtractionModules[0]->getNumInputDimensions();
2373 switch( pipelineMode ){
2374 case PIPELINE_MODE_NOT_SET:
2376 case CLASSIFICATION_MODE:
2379 case REGRESSION_MODE:
2397 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
2399 if( inputVector.size() != preProcessingModules[ moduleIndex ]->getNumInputDimensions() ){
2400 errorLog <<
"preProcessData(VectorDouble inputVector) - The size of the input vector (" << preProcessingModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the PreProcessing Module at moduleIndex: " << moduleIndex << endl;
2404 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
2405 errorLog <<
"preProcessData(VectorDouble inputVector) - Failed To PreProcess Input Vector. PreProcessing moduleIndex: " << moduleIndex << endl;
2408 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
2414 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
2415 if( inputVector.size() != featureExtractionModules[ moduleIndex ]->getNumInputDimensions() ){
2416 errorLog <<
"preProcessData(VectorDouble inputVector) - The size of the input vector (" << featureExtractionModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the FeatureExtraction Module at moduleIndex: " << moduleIndex << endl;
2420 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
2421 errorLog <<
"preProcessData(VectorDouble inputVector) - Failed To Compute Features from Input Vector. FeatureExtraction moduleIndex: " << moduleIndex << endl;
2424 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
2441 return preProcessingModules.size() > 0;
2445 return featureExtractionModules.size() > 0;
2449 return (classifier!=NULL);
2453 return (regressifier!=NULL);
2457 return (clusterer!=NULL);
2461 return postProcessingModules.size() > 0;
2465 for(UINT i=0; i<NUM_CONTEXT_LEVELS; i++){
2466 if( contextModules[i].size() > 0 )
return true;
2472 return (pipelineMode!=PIPELINE_MODE_NOT_SET);
2476 return (pipelineMode==CLASSIFICATION_MODE);
2480 return pipelineMode==REGRESSION_MODE;
2486 return preProcessingModules[0]->getNumInputDimensions();
2490 return featureExtractionModules[0]->getNumInputDimensions();
2515 UINT numClasses = 0;
2526 return (UINT)preProcessingModules.size();
2530 return (UINT)featureExtractionModules.size();
2534 return (UINT)postProcessingModules.size();
2538 return predictionModuleIndex;
2544 return predictedClassLabel;
2547 return predictedClusterLabel;
2563 return numTrainingSamples;
2567 return numTestSamples;
2592 return testAccuracy;
2596 return testRMSError;
2600 return testSquaredError;
2608 for(UINT i=0; i<testFMeasure.size(); i++){
2610 return testFMeasure[i];
2621 for(UINT i=0; i<testPrecision.size(); i++){
2623 return testPrecision[i];
2634 for(UINT i=0; i<testRecall.size(); i++){
2636 return testRecall[i];
2643 return testRejectionPrecision;
2647 return testRejectionRecall;
2655 return trainingTime;
2667 return testConfusionMatrix;
2672 testResults.numTrainingSamples = numTrainingSamples;
2673 testResults.numTestSamples = numTestSamples;
2674 testResults.accuracy = testAccuracy;
2675 testResults.rmsError = testRMSError;
2676 testResults.totalSquaredError = testSquaredError;
2677 testResults.trainingTime = trainingTime;
2678 testResults.testTime = testTime;
2679 testResults.rejectionPrecision = testRejectionPrecision;
2680 testResults.rejectionRecall = testRejectionRecall;
2681 testResults.precision = testPrecision;
2682 testResults.recall = testRecall;
2683 testResults.fMeasure = testFMeasure;
2684 testResults.confusionMatrix = testConfusionMatrix;
2689 return testPrecision;
2697 return testFMeasure;
2703 else{
return VectorDouble(); }
2709 else{
return VectorDouble(); }
2714 else{
return VectorDouble(); }
2718 return regressionData;
2725 return VectorDouble();
2730 return preProcessingModules[ preProcessingModules.size()-1 ]->getProcessedData();
2732 return VectorDouble();
2737 if( moduleIndex < preProcessingModules.size() ){
2738 return preProcessingModules[ moduleIndex ]->getProcessedData();
2741 return VectorDouble();
2746 return featureExtractionModules[ featureExtractionModules.size()-1 ]->getFeatureVector();
2748 return VectorDouble();
2753 if( moduleIndex < featureExtractionModules.size() ){
2754 return featureExtractionModules[ moduleIndex ]->getFeatureVector();
2757 warningLog <<
"getFeatureExtractionData(UINT moduleIndex) - Failed to get class labels!" << endl;
2758 return VectorDouble();
2768 warningLog <<
"getClassLabels() - Failed to get class labels!" << endl;
2769 return vector< UINT>();
2777 return crossValidationResults;
2781 if( moduleIndex < preProcessingModules.size() ){
2782 return preProcessingModules[ moduleIndex ];
2784 warningLog <<
"getPreProcessingModule(const UINT moduleIndex) - Failed to get pre processing module!" << endl;
2789 if( moduleIndex < featureExtractionModules.size() ){
2790 return featureExtractionModules[ moduleIndex ];
2792 warningLog <<
"getFeatureExtractionModule(const UINT moduleIndex) - Failed to get feature extraction module!" << endl;
2801 return regressifier;
2809 if( moduleIndex < postProcessingModules.size() ){
2810 return postProcessingModules[ moduleIndex ];
2812 warningLog <<
"getPostProcessingModule(UINT moduleIndex) - Failed to get post processing module!" << endl;
2817 if( contextLevel < contextModules.size() ){
2818 if( moduleIndex < contextModules[ contextLevel ].size() ){
2819 return contextModules[ contextLevel ][ moduleIndex ];
2822 warningLog <<
"getContextModule(UINT contextLevel,UINT moduleIndex) - Failed to get context module!" << endl;
2833 if( insertIndex != INSERT_AT_END_INDEX && insertIndex >= preProcessingModules.size() ){
2834 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - Invalid insertIndex value!" << endl;
2842 if( !newInstance->
deepCopyFrom( &preProcessingModule ) ){
2845 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - PreProcessing Module Not Set!" << endl;
2850 vector< PreProcessing* >::iterator iter = preProcessingModules.begin();
2852 if( insertIndex == INSERT_AT_END_INDEX ) iter = preProcessingModules.end();
2853 else iter = preProcessingModules.begin() + insertIndex;
2855 preProcessingModules.insert(iter, newInstance);
2871 if( insertIndex != INSERT_AT_END_INDEX && insertIndex >= featureExtractionModules.size() ){
2872 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule) - Invalid insertIndex value!" << endl;
2880 if( !newInstance->
deepCopyFrom( &featureExtractionModule ) ){
2883 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule - FeatureExtraction Module Not Set!" << endl;
2888 vector< FeatureExtraction* >::iterator iter = featureExtractionModules.begin();
2890 if( insertIndex == INSERT_AT_END_INDEX ) iter = featureExtractionModules.end();
2891 else iter = featureExtractionModules.begin() + insertIndex;
2893 featureExtractionModules.insert(iter, newInstance);
2910 deleteRegressifier();
2916 if( this->classifier == NULL ){
2917 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << endl;
2924 pipelineMode = PIPELINE_MODE_NOT_SET;
2925 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << endl;
2930 pipelineMode = CLASSIFICATION_MODE;
2940 }
else trained =
false;
2949 deleteRegressifier();
2953 pipelineMode = REGRESSION_MODE;
2959 if( !this->regressifier->
deepCopyFrom( ®ressifier ) ){
2960 deleteRegressifier();
2961 pipelineMode = PIPELINE_MODE_NOT_SET;
2962 errorLog <<
"setRegressifier(const Regressifier ®ressifier) - Regressifier Module Not Set!" << endl;
2973 }
else trained =
false;
2982 deleteRegressifier();
2986 pipelineMode = CLUSTER_MODE;
2994 pipelineMode = PIPELINE_MODE_NOT_SET;
2995 errorLog <<
"setClusterer(const Clusterer &clusterer) - Clusterer Module Not Set!" << endl;
3006 }
else trained =
false;
3014 if( insertIndex != INSERT_AT_END_INDEX && insertIndex >= postProcessingModules.size() ){
3015 errorLog <<
"addPostProcessingModule((const PostProcessing &postProcessingModule) - Invalid insertIndex value!" << endl;
3023 if( !newInstance->
deepCopyFrom( &postProcessingModule ) ){
3026 errorLog <<
"addPostProcessingModule(const PostProcessing &postProcessingModule) - PostProcessing Module Not Set!" << endl;
3031 vector< PostProcessing* >::iterator iter = postProcessingModules.begin();
3033 if( insertIndex == INSERT_AT_END_INDEX ) iter = postProcessingModules.end();
3034 else iter = postProcessingModules.begin() + insertIndex;
3036 postProcessingModules.insert(iter, newInstance);
3052 if( contextLevel >= contextModules.size() ){
3053 errorLog <<
"addContextModule(...) - Invalid contextLevel value!" << endl;
3058 if( insertIndex != INSERT_AT_END_INDEX && insertIndex >= contextModules[contextLevel].size() ){
3059 errorLog <<
"addContextModule(...) - Invalid insertIndex value!" << endl;
3067 if( !newInstance->deepCopyFrom( &contextModule ) ){
3070 errorLog <<
"addContextModule(...) - Context Module Not Set!" << endl;
3075 vector< Context* >::iterator iter = contextModules[ contextLevel ].begin();
3077 if( insertIndex == INSERT_AT_END_INDEX ) iter = contextModules[ contextLevel ].end();
3078 else iter = contextModules[ contextLevel ].begin() + insertIndex;
3080 contextModules[ contextLevel ].insert(iter, newInstance);
3088 if( contextLevel >= contextModules.size() ){
3089 errorLog <<
"updateContextModule(...) - Context Level is out of bounds!" << endl;
3094 if( moduleIndex >= contextModules[contextLevel].size() ){
3095 errorLog <<
"updateContextModule(...) - Invalid contextLevel value!" << endl;
3099 return contextModules[contextLevel][moduleIndex]->updateContext( value );
3103 deleteAllPreProcessingModules();
3108 if( moduleIndex >= preProcessingModules.size() ){
3109 errorLog <<
"removePreProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the preProcessingModules vector is " << int(preProcessingModules.size()) << endl;
3114 delete preProcessingModules[ moduleIndex ];
3115 preProcessingModules[ moduleIndex ] = NULL;
3116 preProcessingModules.erase( preProcessingModules.begin() + moduleIndex );
3125 deleteAllFeatureExtractionModules();
3130 if( moduleIndex >= featureExtractionModules.size() ){
3131 errorLog <<
"removeFeatureExtractionModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the featureExtractionModules vector is " << int(featureExtractionModules.size()) << endl;
3136 delete featureExtractionModules[ moduleIndex ];
3137 featureExtractionModules[ moduleIndex ] = NULL;
3138 featureExtractionModules.erase( featureExtractionModules.begin() + moduleIndex );
3147 deleteAllPostProcessingModules();
3152 if( moduleIndex >= postProcessingModules.size() ){
3153 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the postProcessingModules vector is " << int(postProcessingModules.size()) << endl;
3158 delete postProcessingModules[ moduleIndex ];
3159 postProcessingModules[ moduleIndex ] = NULL;
3160 postProcessingModules.erase( postProcessingModules.begin() + moduleIndex );
3169 if( contextLevel >= NUM_CONTEXT_LEVELS ){
3170 errorLog <<
"removeContextModule(UINT contextLevel,UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
" is out of bounds!" << endl;
3174 if( moduleIndex >= contextModules[contextLevel].size() ){
3175 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the contextModules vector at context level " <<
" is " << int(contextModules[contextLevel].size()) << endl;
3180 delete contextModules[contextLevel][moduleIndex];
3181 contextModules[contextLevel][moduleIndex] = NULL;
3182 contextModules[contextLevel].erase( contextModules[contextLevel].begin() + moduleIndex );
3187 deleteAllContextModules();
3209 testSquaredError = 0;
3211 testFMeasure.clear();
3212 testPrecision.clear();
3214 testRejectionPrecision = 0;
3215 testRejectionRecall = 0;
3216 testConfusionMatrix.
clear();
3217 testResults.clear();
3218 crossValidationResults.clear();
3232 void GestureRecognitionPipeline::deleteAllPreProcessingModules(){
3233 if( preProcessingModules.size() != 0 ){
3234 for(UINT i=0; i<preProcessingModules.size(); i++){
3235 delete preProcessingModules[i];
3236 preProcessingModules[i] = NULL;
3238 preProcessingModules.clear();
3243 void GestureRecognitionPipeline::deleteAllFeatureExtractionModules(){
3244 if( featureExtractionModules.size() != 0 ){
3245 for(UINT i=0; i<featureExtractionModules.size(); i++){
3246 delete featureExtractionModules[i];
3247 featureExtractionModules[i] = NULL;
3249 featureExtractionModules.clear();
3254 void GestureRecognitionPipeline::deleteClassifier(){
3255 if( classifier != NULL ){
3260 initialized =
false;
3263 void GestureRecognitionPipeline::deleteRegressifier(){
3264 if( regressifier != NULL ){
3265 delete regressifier;
3266 regressifier = NULL;
3269 initialized =
false;
3272 void GestureRecognitionPipeline::deleteClusterer(){
3273 if( clusterer != NULL ){
3278 initialized =
false;
3281 void GestureRecognitionPipeline::deleteAllPostProcessingModules(){
3282 if( postProcessingModules.size() != 0 ){
3283 for(UINT i=0; i<postProcessingModules.size(); i++){
3284 delete postProcessingModules[i];
3285 postProcessingModules[i] = NULL;
3287 postProcessingModules.clear();
3292 void GestureRecognitionPipeline::deleteAllContextModules(){
3293 for(UINT i=0; i<contextModules.size(); i++){
3294 for(UINT j=0; j<contextModules[i].size(); j++){
3295 delete contextModules[i][j];
3296 contextModules[i][j] = NULL;
3298 contextModules[i].clear();
3302 bool GestureRecognitionPipeline::updateTestMetrics(
const UINT classLabel,
const UINT predictedClassLabel,VectorDouble &precisionCounter,VectorDouble &recallCounter,
double &rejectionPrecisionCounter,
double &rejectionRecallCounter,VectorDouble &confusionMatrixCounter){
3305 UINT predictedClassLabelIndex =0;
3306 bool predictedClassLabelIndexFound =
false;
3307 if( predictedClassLabel != 0 ){
3310 predictedClassLabelIndex = k;
3311 predictedClassLabelIndexFound =
true;
3316 if( !predictedClassLabelIndexFound ){
3317 errorLog <<
"Failed to find class label index for label: " << predictedClassLabel << endl;
3323 UINT actualClassLabelIndex = 0;
3324 if( classLabel != 0 ){
3327 actualClassLabelIndex = k;
3334 if( classLabel == predictedClassLabel ){
3339 if( predictedClassLabel != 0 ){
3340 if( classLabel == predictedClassLabel ){
3342 testPrecision[ predictedClassLabelIndex ]++;
3345 precisionCounter[ predictedClassLabelIndex ]++;
3349 if( classLabel != 0 ){
3350 if( classLabel == predictedClassLabel ){
3352 testRecall[ predictedClassLabelIndex ]++;
3355 recallCounter[ actualClassLabelIndex ]++;
3359 if( predictedClassLabel == 0 ){
3360 if( classLabel == 0 ) testRejectionPrecision++;
3361 rejectionPrecisionCounter++;
3365 if( classLabel == 0 ){
3366 if( predictedClassLabel == 0 ) testRejectionRecall++;
3367 rejectionRecallCounter++;
3372 if( classLabel == 0 ) actualClassLabelIndex = 0;
3373 else actualClassLabelIndex++;
3374 if( predictedClassLabel == 0 ) predictedClassLabelIndex = 0;
3375 else predictedClassLabelIndex++;
3377 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3378 confusionMatrixCounter[ actualClassLabelIndex ]++;
3383 bool GestureRecognitionPipeline::computeTestMetrics(VectorDouble &precisionCounter,VectorDouble &recallCounter,
double &rejectionPrecisionCounter,
double &rejectionRecallCounter,VectorDouble &confusionMatrixCounter,
const UINT numTestSamples){
3386 testAccuracy = testAccuracy/double(numTestSamples) * 100.0;
3389 if( precisionCounter[k] > 0 ) testPrecision[k] /= precisionCounter[k];
3390 else testPrecision[k] = 0;
3391 if( recallCounter[k] > 0 ) testRecall[k] /= recallCounter[k];
3392 else testRecall[k] = 0;
3394 if( precisionCounter[k] + recallCounter[k] > 0 )
3395 testFMeasure[k] = 2 * ((testPrecision[k]*testRecall[k])/(testPrecision[k]+testRecall[k]));
3396 else testFMeasure[k] = 0;
3398 if( rejectionPrecisionCounter > 0 ) testRejectionPrecision /= rejectionPrecisionCounter;
3399 if( rejectionRecallCounter > 0 ) testRejectionRecall /= rejectionRecallCounter;
3402 for(UINT r=0; r<confusionMatrixCounter.size(); r++){
3403 if( confusionMatrixCounter[r] > 0 ){
3404 for(UINT c=0; c<testConfusionMatrix.
getNumCols(); c++){
3405 testConfusionMatrix[r][c] /= confusionMatrixCounter[r];
3416 switch( pipelineMode ){
3417 case PIPELINE_MODE_NOT_SET:
3419 case CLASSIFICATION_MODE:
3425 case REGRESSION_MODE:
3439 switch( pipelineMode ){
3440 case PIPELINE_MODE_NOT_SET:
3441 return "PIPELINE_MODE_NOT_SET";
3443 case CLASSIFICATION_MODE:
3444 return "CLASSIFICATION_MODE";
3446 case REGRESSION_MODE:
3447 return "REGRESSION_MODE";
3450 return "ERROR_UNKNWON_PIPELINE_MODE";
3454 return "ERROR_UNKNWON_PIPELINE_MODE";
3457 string GestureRecognitionPipeline::getInfo()
const{
3462 if( pipelineModeAsString ==
"PIPELINE_MODE_NOT_SET" ){
3463 return PIPELINE_MODE_NOT_SET;
3465 if( pipelineModeAsString ==
"CLASSIFICATION_MODE" ){
3466 return CLASSIFICATION_MODE;
3468 if( pipelineModeAsString ==
"REGRESSION_MODE" ){
3469 return REGRESSION_MODE;
3471 return PIPELINE_MODE_NOT_SET;
UINT getNumDimensions() const
bool getIsClustererSet() const
UINT getNumSamples() const
ClassificationSample getNextSample()
UINT getNumFeatureExtractionModules() const
UINT getInputVectorDimensionsSize() const
double getCrossValidationAccuracy() const
virtual bool saveModelToFile(string filename) const
static std::string toString(const int &i)
static Regressifier * createInstanceFromString(string const ®ressifierType)
string getLastErrorMessage() const
static Classifier * createInstanceFromString(string const &classifierType)
MatrixDouble getTestConfusionMatrix() const
bool map(const VectorDouble &inputVector)
bool resetPlaybackIndex(const UINT playbackIndex)
double getTrainingTime() const
bool setAllowNullGestureClass(bool allowNullGestureClass)
bool getTimeseriesCompatible() const
bool setRegressifier(const Regressifier ®ressifier)
virtual ~GestureRecognitionPipeline(void)
VectorDouble getRegressionData() const
double getRootMeanSquaredTrainingError() const
UINT getNumSamples() const
bool setAllValues(const T &value)
VectorDouble getNullRejectionThresholds() const
TestResult getTestResults() const
virtual bool deepCopyFrom(const Classifier *classifier)
VectorDouble getRegressionData() const
double getMaximumLikelihood() const
double getMaximumLikelihood() const
virtual bool loadModelFromFile(string filename)
bool removeRegressifier()
UINT getPredictedClassLabel() const
Context * getContextModule(const UINT contextLevel, const UINT moduleIndex) const
UINT getNumDimensions() const
bool test(const ClassificationData &testData)
Clusterer * createNewInstance() const
UINT getNumDimensions() const
bool setPostProcessingModule(const PostProcessing &postProcessingModule)
ClassificationData getTrainingFoldData(const UINT foldIndex) const
bool push_back(const std::vector< T > &sample)
bool setInputAndTargetDimensions(const UINT numInputDimensions, const UINT numTargetDimensions)
bool setNumDimensions(UINT numDimensions)
UINT getOutputVectorDimensionsSize() const
unsigned int getNumCols() const
bool addPostProcessingModule(const PostProcessing &postProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool addSample(const VectorDouble &sample)
UINT getNumSamples() const
bool getIsFeatureExtractionSet() const
VectorDouble getTestFMeasure() const
UINT getNumSamples() const
static std::string intToString(const int &i)
virtual UINT getNumClasses() const
virtual bool train(ClassificationData trainingData)
double getTestAccuracy() const
VectorDouble getClassLikelihoods() const
bool getIsInitialized() const
UINT getNumInputFeatures() const
UINT getNumPostProcessingModules() const
vector< ClassTracker > getClassTracker() const
bool removePreProcessingModule(UINT moduleIndex)
VectorDouble getPreProcessedData() const
UINT getNumClasses() const
vector< UINT > getClusterLabels() const
UINT getNumInputDimensions() const
double getTestTime() const
virtual bool deepCopyFrom(const PreProcessing *rhs)
string getPipelineModeAsString() const
UINT getNumClassesInModel() const
double getTestRejectionRecall() const
VectorDouble getClassDistances() const
static Clusterer * createInstanceFromString(string const &ClustererType)
bool save(const string &filename) const
double getMaximumLikelihood() const
This file contains the GestureRecognitionPipeline class.
bool getIsPipelineModeSet() const
double getTestRejectionPrecision() const
double getTotalSquaredTrainingError() const
Clusterer * getClusterer() const
bool setInfo(const string info)
Regressifier * getRegressifier() const
UINT getNumSamples() const
UINT getPredictionModuleIndexPosition() const
bool removeAllPreProcessingModules()
bool removeAllPostProcessingModules()
bool addContextModule(const Context &contextModule, UINT contextLevel, UINT insertIndex=INSERT_AT_END_INDEX)
bool loadPipelineFromFile(const string &filename)
vector< TestResult > getCrossValidationResults() const
VectorDouble getTestRecall() const
bool removeAllFeatureExtractionModules()
Regressifier * createNewInstance() const
bool setFeatureExtractionModule(const FeatureExtraction &featureExtractionModule)
bool getIsRegressifierSet() const
signed long getMilliSeconds() const
virtual bool predict(VectorDouble inputVector)
bool removeAllContextModules()
bool removePostProcessingModule(const UINT moduleIndex)
VectorDouble getClusterLikelihoods() const
VectorDouble getFeatureExtractionData() const
string getRegressifierType() const
Context * createNewInstance() const
string getClustererType() const
virtual bool deepCopyFrom(const Clusterer *Clusterer)
virtual bool train_(MatrixDouble &trainingData)
bool addPreProcessingModule(const PreProcessing &preProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool setClusterer(const Clusterer &clusterer)
bool savePipelineToFile(const string &filename) const
RegressionData getTrainingFoldData(const UINT foldIndex) const
bool getIsPipelineInClassificationMode() const
PreProcessing * createNewInstance() const
bool getIsPipelineInRegressionMode() const
static PostProcessing * createInstanceFromString(string const &postProcessingType)
VectorDouble getNullRejectionThresholds() const
bool getNullRejectionEnabled() const
bool train(const ClassificationData &trainingData)
bool predict(const VectorDouble &inputVector)
bool spiltDataIntoKFolds(const UINT K)
UINT getNumPreProcessingModules() const
UINT getPredictedClassLabel() const
Classifier * createNewInstance() const
bool getIsContextSet() const
bool addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule, UINT insertIndex=INSERT_AT_END_INDEX)
UINT getNumClasses() const
double getTrainingRMSError() const
bool removeFeatureExtractionModule(UINT moduleIndex)
UINT getUnProcessedPredictedClassLabel() const
unsigned int getNumRows() const
UINT getNumDimensions() const
Classifier * getClassifier() const
UINT getNumTestSamples() const
PostProcessing * createNewInstance() const
UINT getNumTargetDimensions() const
bool addSample(const VectorDouble &inputVector, const VectorDouble &targetVector)
bool setPreProcessingModule(const PreProcessing &preProcessingModule)
string getClassifierType() const
bool setClassifier(const Classifier &classifier)
bool getIsPostProcessingSet() const
VectorDouble getTestPrecision() const
GestureRecognitionPipeline(void)
UINT getNumOutputDimensions() const
UINT getNumInputDimensions() const
bool preProcessData(VectorDouble inputVector, bool computeFeatures=true)
VectorDouble getClassDistances() const
virtual bool deepCopyFrom(const Regressifier *regressifier)
double getTrainingSSError() const
ClassificationData getTestFoldData(const UINT foldIndex) const
VectorDouble getClusterDistances() const
VectorDouble getUnProcessedRegressionData() const
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
vector< UINT > getClassLabels() const
RegressionData getTestFoldData(const UINT foldIndex) const
vector< UINT > getClassLabels() const
UINT getPipelineModeFromString(string pipelineMode) const
TimeSeriesClassificationData getTrainingFoldData(const UINT foldIndex) const
bool addSample(UINT classLabel, const VectorDouble &sample)
UINT getNumTrainingSamples() const
VectorDouble getClassLikelihoods() const
GestureRecognitionPipeline & operator=(const GestureRecognitionPipeline &rhs)
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
std::vector< T > getRowVector(const unsigned int r) const
virtual string getModelAsString() const
FeatureExtraction * getFeatureExtractionModule(const UINT moduleIndex) const
bool notifyTestResultsObservers(const TestInstanceResult &data)
UINT getPredictedClusterLabel() const
vector< TestInstanceResult > getTestInstanceResults() const
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
PreProcessing * getPreProcessingModule(const UINT moduleIndex) const
bool getIsPreProcessingSet() const
double getTestRMSError() const
double getTestSSError() const
bool removeContextModule(const UINT contextLevel, const UINT moduleIndex)
static PreProcessing * createInstanceFromString(string const &preProcessingType)
UINT getNumClusters() const
virtual bool resize(const unsigned int r, const unsigned int c)
bool load(const string &filename)
PostProcessing * getPostProcessingModule(UINT moduleIndex) const
TimeSeriesClassificationData getTestFoldData(const UINT foldIndex) const
bool getIsClassifierSet() const
virtual bool train_(ClassificationData &trainingData)
string getModelAsString() const
bool updateContextModule(bool value, UINT contextLevel=0, UINT moduleIndex=0)