29 debugLog.setProceedingText(
"[DEBUG GRP]");
30 errorLog.setProceedingText(
"[ERROR GRP]");
31 warningLog.setProceedingText(
"[WARNING GRP]");
32 testingLog.setProceedingText(
"[TEST GRP]");
39 debugLog.setProceedingText(
"[DEBUG GRP]");
40 errorLog.setProceedingText(
"[ERROR GRP]");
41 warningLog.setProceedingText(
"[WARNING GRP]");
42 testingLog.setProceedingText(
"[TEST GRP]");
55 this->initialized = rhs.initialized;
56 this->trained = rhs.trained;
57 this->info = rhs.info;
58 this->inputVectorDimensions = rhs.inputVectorDimensions;
59 this->outputVectorDimensions = rhs.outputVectorDimensions;
60 this->predictedClassLabel = rhs.predictedClassLabel;
61 this->predictedClusterLabel = rhs.predictedClusterLabel;
62 this->pipelineMode = rhs.pipelineMode;
63 this->predictionModuleIndex = rhs.predictionModuleIndex;
64 this->numTrainingSamples = rhs.numTrainingSamples;
65 this->numTestSamples = rhs.numTestSamples;
66 this->testAccuracy = rhs.testAccuracy;
67 this->testRMSError = rhs.testRMSError;
68 this->testSquaredError = rhs.testSquaredError;
69 this->testTime = rhs.testTime;
70 this->trainingTime = rhs.trainingTime;
71 this->testFMeasure = rhs.testFMeasure;
72 this->testPrecision = rhs.testPrecision;
73 this->testRecall = rhs.testRecall;
74 this->regressionData = rhs.regressionData;
75 this->testRejectionPrecision = rhs.testRejectionPrecision;
76 this->testRejectionRecall = rhs.testRejectionRecall;
77 this->testConfusionMatrix = rhs.testConfusionMatrix;
78 this->crossValidationResults = rhs.crossValidationResults;
79 this->testResults = rhs.testResults;
82 this->debugLog = rhs.debugLog;
83 this->errorLog = rhs.errorLog;
84 this->trainingLog = rhs.trainingLog;
85 this->testingLog = rhs.testingLog;
86 this->warningLog = rhs.warningLog;
88 for(
unsigned int i=0; i<rhs.preProcessingModules.size(); i++){
92 for(
unsigned int i=0; i<rhs.featureExtractionModules.size(); i++){
108 for(
unsigned int i=0; i<rhs.postProcessingModules.size(); i++){
112 for(
unsigned int k=0; k<NUM_CONTEXT_LEVELS; k++){
113 for(
unsigned int i=0; i<rhs.contextModules[k].size(); i++){
119 this->trained = rhs.trained;
168 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
173 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << std::endl;
189 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
191 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
204 bool okToAddProcessedData =
true;
205 classLabel = trainingData[i].getClassLabel();
206 trainingSample = trainingData[i].getSample();
210 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
211 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
212 errorLog <<
"train(ClassificationData trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
213 errorLog << moduleIndex;
214 errorLog << std::endl;
217 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
223 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
224 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
225 errorLog <<
"train(ClassificationData trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
226 errorLog << moduleIndex;
227 errorLog << std::endl;
230 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
231 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
233 okToAddProcessedData =
false;
239 if( okToAddProcessedData ){
241 processedTrainingData.
addSample(classLabel, trainingSample);
247 warningLog <<
"train(ClassificationData trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
254 trained = classifier->
train_( processedTrainingData );
256 errorLog <<
"train(ClassificationData trainingData) - Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
273 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
278 errorLog <<
"train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << std::endl;
300 Float crossValidationAccuracy = 0;
305 for(UINT k=0; k<kFoldValue; k++){
309 if( !
train( foldTrainingData ) ){
316 if( !
test( foldTestData ) ){
328 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
329 crossValidationResults = cvResults;
344 errorLog <<
"train(const TimeSeriesClassificationData &trainingData) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
349 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier, there is no training data!" << std::endl;
367 bool allowNullGestureClass =
true;
369 timeseriesClassificationData.setAllowNullGestureClass( allowNullGestureClass );
377 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
380 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
382 timeseriesClassificationData.setNumDimensions( trainingDataInputDimensionSize );
386 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
389 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
396 UINT classLabel = trainingData[i].getClassLabel();
397 MatrixFloat trainingSample = trainingData[i].getData();
402 bool resetPreprocessingModule =
true;
403 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
406 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
408 if( resetPreprocessingModule ){
409 preProcessingModules[moduleIndex]->reset();
413 if( preProcessingModules[moduleIndex]->getNumInputDimensions() != preProcessingModules[moduleIndex]->getNumOutputDimensions() ){
414 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. The number of inputDimensions (";
415 errorLog << preProcessingModules[moduleIndex]->getNumInputDimensions();
416 errorLog <<
") in PreProcessingModule ";
417 errorLog << moduleIndex;
418 errorLog <<
" do not match the number of outputDimensions (";
419 errorLog << preProcessingModules[moduleIndex]->getNumOutputDimensions();
420 errorLog << std::endl;
424 if( !preProcessingModules[moduleIndex]->process( sample ) ){
425 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To PreProcess Training Data. PreProcessingModuleIndex: ";
426 errorLog << moduleIndex;
427 errorLog << std::endl;
430 sample = preProcessingModules[moduleIndex]->getProcessedData();
434 resetPreprocessingModule =
false;
437 for(UINT c=0; c<sample.size(); c++){
438 trainingSample[r][c] = sample[c];
445 processedTrainingData.addSample(classLabel,trainingSample);
450 for(UINT i=0; i<processedTrainingData.getNumSamples(); i++){
451 UINT classLabel = processedTrainingData[i].getClassLabel();
453 bool featureDataReady =
false;
454 bool resetFeatureExtractionModules =
true;
459 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
460 inputVector = trainingSample.
getRow( r );
461 featureDataReady =
true;
466 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
468 if( resetFeatureExtractionModules ){
469 featureExtractionModules[moduleIndex]->reset();
472 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
473 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: ";
474 errorLog << moduleIndex;
475 errorLog << std::endl;
481 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
482 featureDataReady = featureExtractionModules[moduleIndex]->getFeatureDataReady();
486 resetFeatureExtractionModules =
false;
488 if( featureDataReady ){
491 if( !featureData.
push_back( inputVector ) ){
492 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
495 }
else classificationData.
addSample(classLabel, inputVector);
500 if( !featureData.
push_back( inputVector ) ){
501 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
505 else classificationData.
addSample(classLabel, inputVector);
515 numTrainingSamples = timeseriesClassificationData.getNumSamples();
516 trained = classifier->
train( timeseriesClassificationData );
519 trained = classifier->
train( classificationData );
523 errorLog <<
"train(TimeSeriesClassificationData trainingData) - Failed To Train Classifier" << classifier->
getLastErrorMessage() << std::endl;
540 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, the classifier has not been set!" << std::endl;
545 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Train Classifier, there is no training data!" << std::endl;
561 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed To Spilt Dataset into KFolds!" << std::endl;
566 Float crossValidationAccuracy = 0;
570 for(UINT k=0; k<kFoldValue; k++){
574 if( !
train( foldTrainingData ) ){
575 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to train pipeline for fold " << k <<
"." << std::endl;
582 if( !
test( foldTestData ) ){
583 errorLog <<
"train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling) - Failed to test pipeline for fold " << k <<
"." << std::endl;
594 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
609 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To train Classifier, the classifier has not been set!" << std::endl;
614 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To train Classifier, there is no training data!" << std::endl;
625 UINT numDimensions = inputVectorDimensions;
630 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
632 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
645 bool okToAddProcessedData =
true;
646 classLabel = trainingData[i].getClassLabel();
647 trainingSample = trainingData[i].getSample();
651 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
652 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
653 errorLog <<
"train(ClassificationDataStream trainingData) - Failed to PreProcess training Data. PreProcessingModuleIndex: ";
654 errorLog << moduleIndex;
655 errorLog << std::endl;
658 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
664 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
665 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
666 errorLog <<
"train(ClassificationDataStream trainingData) - Failed to Compute Features from training Data. FeatureExtractionModuleIndex ";
667 errorLog << moduleIndex;
668 errorLog << std::endl;
671 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
672 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
674 okToAddProcessedData =
false;
680 if( okToAddProcessedData ){
682 processedTrainingData.
addSample(classLabel, trainingSample);
688 warningLog <<
"train(ClassificationDataStream trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
695 trained = classifier->
train_( processedTrainingData );
697 errorLog <<
"train(ClassificationDataStream trainingData) - Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
734 numInputs = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
738 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
742 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
749 VectorFloat inputVector = trainingData[i].getInputVector();
750 VectorFloat targetVector = trainingData[i].getTargetVector();
753 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
754 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
755 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. PreProcessingModuleIndex: " << moduleIndex << std::endl;
759 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
764 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
765 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
766 errorLog <<
"train(const RegressionData &trainingData) - Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
770 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
775 if( !processedTrainingData.
addSample(inputVector,targetVector) ){
776 errorLog <<
"train(const RegressionData &trainingData) - Failed to add processed training sample to training data" << std::endl;
786 trained = regressifier->
train( processedTrainingData );
788 errorLog <<
"train(const RegressionData &trainingData) - Failed To Train Regressifier: " << regressifier->
getLastErrorMessage() << std::endl;
792 errorLog <<
"train(const RegressionData &trainingData) - Classifier is not set" << std::endl;
809 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, the regressifier has not been set!" << std::endl;
814 errorLog <<
"train(const RegressionData &trainingData,const UINT kFoldValue) - Failed To Train Regressifier, there is no training data!" << std::endl;
836 Float crossValidationAccuracy = 0;
839 for(UINT k=0; k<kFoldValue; k++){
843 if( !
train( foldTrainingData ) ){
850 if( !
test( foldTestData ) ){
861 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
876 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, the clusterer has not been set!" << std::endl;
881 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer, there is no training data!" << std::endl;
897 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
899 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
910 bool okToAddProcessedData =
true;
915 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
916 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
917 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
918 errorLog << moduleIndex;
919 errorLog << std::endl;
922 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
928 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
929 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
930 errorLog <<
"train(const UnlabelledData &trainingData) - Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
931 errorLog << moduleIndex;
932 errorLog << std::endl;
935 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
936 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
938 okToAddProcessedData =
false;
944 if( okToAddProcessedData ){
946 processedTrainingData.
addSample(trainingSample);
953 warningLog <<
"train(const ClassificationData &trainingData) - Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
960 trained = clusterer->
train_( processedTrainingData );
962 errorLog <<
"train(const UnlabelledData &trainingData) - Failed To Train Clusterer: " << clusterer->
getLastErrorMessage() << std::endl;
979 errorLog <<
"test(const ClassificationData &testData) - Classifier is not trained" << std::endl;
985 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;
990 errorLog <<
"test(const ClassificationData &testData) - The classifier has not been set" << std::endl;
998 bool classLabelValidationPassed =
true;
1000 bool labelFound =
false;
1009 classLabelValidationPassed =
false;
1010 errorLog <<
"test(const ClassificationData &testData) - The test dataset contains a class label (" << testData.
getClassTracker()[i].classLabel <<
") that is not in the model!" << std::endl;
1014 if( !classLabelValidationPassed ){
1015 errorLog <<
"test(const ClassificationData &testData) - Model Class Labels: ";
1019 errorLog << std::endl;
1023 Float rejectionPrecisionCounter = 0;
1024 Float rejectionRecallCounter = 0;
1028 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1031 testConfusionMatrix.
resize(confusionMatrixSize, confusionMatrixSize);
1035 testPrecision.clear();
1037 testFMeasure.clear();
1049 for(UINT i=0; i<numTestSamples; i++){
1050 UINT classLabel = testData[i].getClassLabel();
1055 errorLog <<
"test(const ClassificationData &testData) - Prediction failed for test sample at index: " << i << std::endl;
1062 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1063 errorLog <<
"test(const ClassificationData &testData) - Failed to update test metrics at test sample index: " << i << std::endl;
1075 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, numTestSamples) ){
1076 errorLog <<
"test(const ClassificationData &testData) - Failed to compute test metrics!" << std::endl;
1092 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been trained" << std::endl;
1098 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;
1103 errorLog <<
"test(const TimeSeriesClassificationData &testData) - The classifier has not been set" << std::endl;
1110 Float rejectionPrecisionCounter = 0;
1111 Float rejectionRecallCounter = 0;
1116 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1119 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1123 testPrecision.
resize(K, 0);
1125 testFMeasure.
resize(K, 0);
1134 for(UINT i=0; i<M; i++){
1135 UINT classLabel = testData[i].getClassLabel();
1140 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to run prediction for test sample index: " << i << std::endl;
1147 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1148 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to update test metrics at test sample index: " << i << std::endl;
1154 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, M) ){
1155 errorLog <<
"test(const TimeSeriesClassificationData &testData) - Failed to compute test metrics!" << std::endl;
1171 errorLog <<
"test(const ClassificationDataStream &testData) - The classifier has not been trained" << std::endl;
1177 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;
1182 errorLog <<
"test(const ClassificationDataStream &testData) - The classifier has not been set" << std::endl;
1194 VectorFloat confusionMatrixCounter(confusionMatrixSize,0);
1197 testConfusionMatrix.
resize(confusionMatrixSize,confusionMatrixSize);
1220 UINT classLabel = sample.getClassLabel();
1225 errorLog <<
"test(const ClassificationDataStream &testData) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1239 if( classLabel == predictedClassLabel ) testAccuracy++;
1247 testingLog <<
"test iteration: " << i;
1248 testingLog <<
"\tClassLabel: " << classLabel;
1249 testingLog <<
"\tPredictedClassLabel: " << predictedClassLabel;
1261 testAccuracy = testAccuracy / Float( testData.
getNumSamples() ) * 100.0;
1263 testingLog <<
"Test complete. Total testing time: " << testTime << std::endl;
1275 errorLog <<
"test(const RegressionData &testData) - Regressifier is not trained" << std::endl;
1281 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;
1286 errorLog <<
"test(const RegressionData &testData) - The regressifier has not been set" << std::endl;
1291 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;
1299 testResults.
resize( numTestSamples );
1306 testSquaredError = 0;
1308 for(UINT i=0; i<numTestSamples; i++){
1309 VectorFloat inputVector = testData[i].getInputVector();
1310 VectorFloat targetVector = testData[i].getTargetVector();
1313 if( !
map( inputVector ) ){
1314 errorLog <<
"test(const RegressionData &testData) - Failed to map input Vector!" << std::endl;
1321 for(UINT j=0; j<targetVector.size(); j++){
1322 sum += grt_sqr( regressionData[j]-targetVector[j] );
1325 testSquaredError += sum;
1328 testResults[i].setRegressionResult(i,regressionData,targetVector);
1335 testRMSError = sqrt( testSquaredError / Float( testData.
getNumSamples() ) );
1346 errorLog <<
"predict(const VectorFloat &inputVector) - The classifier has not been trained" << std::endl;
1351 if( inputVector.size() != inputVectorDimensions ){
1352 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;
1357 return predict_classifier( inputVector );
1361 return predict_regressifier( inputVector );
1365 return predict_clusterer( inputVector );
1368 errorLog <<
"predict(const VectorFloat &inputVector) - Neither a classifier, regressifer or clusterer is set" << std::endl;
1376 errorLog <<
"predict(const MatrixFloat &inputMatrix) - The classifier has not been trained!" << std::endl;
1381 if( input.
getNumCols() != inputVectorDimensions ){
1382 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;
1387 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - A classifier has not been set" << std::endl;
1395 const void *data =
static_cast< const void*
>( &inputMatrix );
1396 DataType dataType = DATA_TYPE_MATRIX;
1403 predictionModuleIndex = START_OF_PIPELINE;
1427 predictionModuleIndex = AFTER_PREPROCESSING;
1431 const void *feInput = data;
1432 const void *feOutput = NULL;
1433 const UINT numFeatureExtractionModules = featureExtractionModules.
getSize();
1434 DataType inputType = DATA_TYPE_UNKNOWN;
1435 DataType outputType = DATA_TYPE_UNKNOWN;
1436 for(UINT moduleIndex=0; moduleIndex<numFeatureExtractionModules; moduleIndex++){
1438 inputType = featureExtractionModules[ moduleIndex ]->getInputType();
1439 outputType = featureExtractionModules[ moduleIndex ]->getOutputType();
1442 switch( inputType ){
1443 case DATA_TYPE_VECTOR:
1444 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const VectorFloat* >( feInput ) ) ){
1445 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1449 case DATA_TYPE_MATRIX:
1450 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const MatrixFloat* >( feInput ) ) ){
1451 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1456 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1462 switch( outputType ){
1463 case DATA_TYPE_VECTOR:
1464 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureVector() );
1466 case DATA_TYPE_MATRIX:
1467 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureMatrix() );
1470 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1476 if( moduleIndex+1 < numFeatureExtractionModules ){
1483 dataType = outputType;
1487 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1491 case DATA_TYPE_VECTOR:
1493 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1497 case DATA_TYPE_MATRIX:
1499 errorLog <<
"predict_timeseries(const MatrixFloat &inputMatrix) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1504 errorLog <<
"predict(const MatrixFloat &inputMatrix) - Failed to run prediction. Unknown data type!" << std::endl;
1515 predictionModuleIndex = AFTER_CLASSIFIER;
1569 predictionModuleIndex = END_OF_PIPELINE;
1574 return predict_regressifier( inputVector );
1577 bool GestureRecognitionPipeline::predict_classifier(
const VectorFloat &input){
1579 predictedClassLabel = 0;
1583 predictionModuleIndex = START_OF_PIPELINE;
1584 if( contextModules[ START_OF_PIPELINE ].size() > 0 ){
1585 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1586 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1587 errorLog <<
"predict_classifier(const VectorFloat &inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1590 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1593 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1599 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1600 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1601 errorLog <<
"predict_classifier(const VectorFloat &inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1604 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1609 predictionModuleIndex = AFTER_PREPROCESSING;
1610 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1611 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1612 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1613 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1616 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1617 predictionModuleIndex = AFTER_PREPROCESSING;
1620 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1626 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1627 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1628 errorLog <<
"predict_classifier(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1631 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1636 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1637 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1638 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1639 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1640 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1643 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1644 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1647 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1652 if( !classifier->
predict(inputVector) ){
1653 errorLog <<
"predict_classifier(VectorFloat inputVector) - Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1659 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1660 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1661 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1662 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1665 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1666 predictionModuleIndex = AFTER_CLASSIFIER;
1669 predictedClassLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1674 predictionModuleIndex = AFTER_CLASSIFIER;
1677 if( pipelineMode != CLASSIFICATION_MODE){
1678 errorLog <<
"predict_classifier(VectorFloat inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1683 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1686 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1689 data[0] = predictedClassLabel;
1692 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1693 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;
1698 if( !postProcessingModules[moduleIndex]->process( data ) ){
1699 errorLog <<
"predict_classifier(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1704 data = postProcessingModules[moduleIndex]->getProcessedData();
1708 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1710 data = postProcessingModules[moduleIndex]->getProcessedData();
1713 if( data.size() != 1 ){
1714 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;
1719 predictedClassLabel = (UINT)data[0];
1726 predictionModuleIndex = END_OF_PIPELINE;
1727 if( contextModules[ END_OF_PIPELINE ].size() ){
1728 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1729 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1730 errorLog <<
"predict_classifier(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1733 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1734 predictionModuleIndex = END_OF_PIPELINE;
1737 predictedClassLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
1744 bool GestureRecognitionPipeline::predict_regressifier(
const VectorFloat &input){
1749 predictionModuleIndex = START_OF_PIPELINE;
1750 if( contextModules[ START_OF_PIPELINE ].size() ){
1751 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1752 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1753 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1756 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1759 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1765 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1766 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1767 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1770 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1775 predictionModuleIndex = AFTER_PREPROCESSING;
1776 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1777 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1778 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1779 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1782 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1783 predictionModuleIndex = AFTER_PREPROCESSING;
1786 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1792 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1793 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1794 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1797 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1802 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1803 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1804 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1805 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1806 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1809 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1810 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1813 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1818 if( !regressifier->
predict(inputVector) ){
1819 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Prediction Failed! " << regressifier->
getLastErrorMessage() << std::endl;
1825 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1826 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1827 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( regressionData ) ){
1828 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1831 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1832 predictionModuleIndex = AFTER_CLASSIFIER;
1835 regressionData = contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData();
1840 predictionModuleIndex = AFTER_CLASSIFIER;
1843 if( pipelineMode != REGRESSION_MODE ){
1844 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Pipeline Mode Is Not In RegressionMode!" << std::endl;
1848 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1849 if( regressionData.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1850 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;
1854 if( !postProcessingModules[moduleIndex]->process( regressionData ) ){
1855 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1858 regressionData = postProcessingModules[moduleIndex]->getProcessedData();
1864 predictionModuleIndex = END_OF_PIPELINE;
1865 if( contextModules[ END_OF_PIPELINE ].size() ){
1866 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1867 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1868 errorLog <<
"predict_regressifier(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1871 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1872 predictionModuleIndex = END_OF_PIPELINE;
1875 regressionData = contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData();
1882 bool GestureRecognitionPipeline::predict_clusterer(
const VectorFloat &input){
1885 predictedClusterLabel = 0;
1888 predictionModuleIndex = START_OF_PIPELINE;
1889 if( contextModules[ START_OF_PIPELINE ].size() ){
1890 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1891 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1892 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1895 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1898 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1904 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1905 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1906 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1909 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1914 predictionModuleIndex = AFTER_PREPROCESSING;
1915 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1916 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1917 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1918 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1921 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1922 predictionModuleIndex = AFTER_PREPROCESSING;
1925 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1931 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1932 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1933 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1936 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1941 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1942 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1943 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1944 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1945 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1948 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1949 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1952 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1957 if( !clusterer->
predict(inputVector) ){
1958 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Prediction Failed! " << clusterer->
getLastErrorMessage() << std::endl;
1964 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1965 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1966 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClusterLabel) ) ){
1967 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1970 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1971 predictionModuleIndex = AFTER_CLASSIFIER;
1974 predictedClusterLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1979 predictionModuleIndex = AFTER_CLASSIFIER;
1982 if( pipelineMode != CLASSIFICATION_MODE){
1983 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1988 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1991 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1994 data[0] = predictedClusterLabel;
1997 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1998 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;
2003 if( !postProcessingModules[moduleIndex]->process( data ) ){
2004 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
2009 data = postProcessingModules[moduleIndex]->getProcessedData();
2013 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
2015 data = postProcessingModules[moduleIndex]->getProcessedData();
2018 if( data.size() != 1 ){
2019 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;
2024 predictedClusterLabel = (UINT)data[0];
2031 predictionModuleIndex = END_OF_PIPELINE;
2032 if( contextModules[ END_OF_PIPELINE ].size() ){
2033 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
2034 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
2035 errorLog <<
"predict_clusterer(VectorFloat inputVector) - Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
2038 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
2039 predictionModuleIndex = END_OF_PIPELINE;
2042 predictedClusterLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
2053 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
2054 if( !preProcessingModules[ moduleIndex ]->
reset() ){
2055 errorLog <<
"Failed To Reset PreProcessingModule " << moduleIndex << std::endl;
2063 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
2064 if( !featureExtractionModules[ moduleIndex ]->
reset() ){
2065 errorLog <<
"Failed To Reset FeatureExtractionModule " << moduleIndex << std::endl;
2073 if( !classifier->
reset() ){
2074 errorLog <<
"Failed To Reset Classifier! " << classifier->
getLastErrorMessage() << std::endl;
2081 if( !regressifier->
reset() ){
2082 errorLog <<
"Failed To Reset Regressifier! " << regressifier->
getLastErrorMessage() << std::endl;
2089 if( !clusterer->
reset() ){
2090 errorLog <<
"Failed To Reset clusterer! " << clusterer->
getLastErrorMessage() << std::endl;
2097 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
2098 if( !postProcessingModules[ moduleIndex ]->
reset() ){
2099 errorLog <<
"Failed To Reset PostProcessingModule " << moduleIndex << std::endl;
2108 bool GestureRecognitionPipeline::clearAll(){
return clear(); }
2114 deleteAllPreProcessingModules();
2115 deleteAllFeatureExtractionModules();
2117 deleteRegressifier();
2119 deleteAllPostProcessingModules();
2120 deleteAllContextModules();
2130 preProcessingModules[i]->clear();
2135 featureExtractionModules[i]->clear();
2139 switch( pipelineMode ){
2140 case PIPELINE_MODE_NOT_SET:
2142 case CLASSIFICATION_MODE:
2144 classifier->
clear();
2147 case REGRESSION_MODE:
2149 regressifier->
clear();
2163 postProcessingModules[i]->clear();
2176 errorLog <<
"Failed to write pipeline to file as the pipeline has not been initialized yet!" << std::endl;
2182 file.open(filename.c_str(), std::iostream::out );
2184 if( !file.is_open() ){
2185 errorLog <<
"Failed to open file with filename: " << filename << std::endl;
2190 file <<
"GRT_PIPELINE_FILE_V3.0\n";
2195 file <<
"Trained: " <<
getTrained() << std::endl;
2196 file <<
"Info: " << info << std::endl;
2199 file <<
"PreProcessingModuleDatatypes:";
2201 file <<
"\t" << preProcessingModules[i]->getPreProcessingType();
2205 file <<
"FeatureExtractionModuleDatatypes:";
2207 file <<
"\t" << featureExtractionModules[i]->getFeatureExtractionType();
2211 switch( pipelineMode ){
2212 case PIPELINE_MODE_NOT_SET:
2214 case CLASSIFICATION_MODE:
2216 else file <<
"ClassificationModuleDatatype:\tCLASSIFIER_NOT_SET" << std::endl;
2218 case REGRESSION_MODE:
2220 else file <<
"RegressionModuleDatatype:\tREGRESSIFIER_NOT_SET" << std::endl;
2224 else file <<
"ClusterModuleDatatype:\tCLUSTERER_NOT_SET" << std::endl;
2230 file <<
"PostProcessingModuleDatatypes:";
2232 file <<
"\t" << postProcessingModules[i]->getPostProcessingType();
2239 if( !preProcessingModules[i]->saveModelToFile( file ) ){
2240 errorLog <<
"Failed to write preprocessing module " << i <<
" settings to file!" << std::endl;
2249 if( !featureExtractionModules[i]->saveModelToFile( file ) ){
2250 errorLog <<
"Failed to write feature extraction module " << i <<
" settings to file!" << std::endl;
2256 switch( pipelineMode ){
2257 case PIPELINE_MODE_NOT_SET:
2259 case CLASSIFICATION_MODE:
2262 errorLog <<
"Failed to write classifier model to file!" << std::endl;
2268 case REGRESSION_MODE:
2271 errorLog <<
"Failed to write regressifier model to file!" << std::endl;
2280 errorLog <<
"Failed to write clusterer model to file!" << std::endl;
2293 if( !postProcessingModules[i]->saveModelToFile( file ) ){
2294 errorLog <<
"Failed to write post processing module " << i <<
" settings to file!" << std::endl;
2317 file.open(filename.c_str(), std::iostream::in );
2319 if( !file.is_open() ){
2320 errorLog <<
"loadPipelineFromFile(string filename) - Failed to open file with filename: " << filename << std::endl;
2328 if( word !=
"GRT_PIPELINE_FILE_V3.0" ){
2329 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read file header" << std::endl;
2336 if( word !=
"PipelineMode:" ){
2337 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PipelineMode" << std::endl;
2346 if( word !=
"NumPreprocessingModules:" ){
2347 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPreprocessingModules header" << std::endl;
2351 unsigned int numPreprocessingModules;
2352 file >> numPreprocessingModules;
2356 if( word !=
"NumFeatureExtractionModules:" ){
2357 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumFeatureExtractionModules header" << std::endl;
2361 unsigned int numFeatureExtractionModules;
2362 file >> numFeatureExtractionModules;
2366 if( word !=
"NumPostprocessingModules:" ){
2367 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read NumPostprocessingModules header" << std::endl;
2371 unsigned int numPostprocessingModules;
2372 file >> numPostprocessingModules;
2376 if( word !=
"Trained:" ){
2377 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Trained header" << std::endl;
2385 if( word !=
"Info:" ){
2386 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read Info header" << std::endl;
2393 while( word !=
"PreProcessingModuleDatatypes:" ){
2399 if( numPreprocessingModules > 0 ) preProcessingModules.
resize(numPreprocessingModules,NULL);
2400 if( numFeatureExtractionModules > 0 ) featureExtractionModules.
resize(numFeatureExtractionModules,NULL);
2401 if( numPostprocessingModules > 0 ) postProcessingModules.
resize(numPostprocessingModules,NULL);
2404 if( word !=
"PreProcessingModuleDatatypes:" ){
2405 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PreProcessingModuleDatatypes" << std::endl;
2409 for(UINT i=0; i<numPreprocessingModules; i++){
2412 if( preProcessingModules[i] == NULL ){
2413 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create preprocessing instance from string: " << word << std::endl;
2421 if( word !=
"FeatureExtractionModuleDatatypes:" ){
2422 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read FeatureExtractionModuleDatatypes" << std::endl;
2426 for(UINT i=0; i<numFeatureExtractionModules; i++){
2428 featureExtractionModules[i] = FeatureExtraction::createInstanceFromString( word );
2429 if( featureExtractionModules[i] == NULL ){
2430 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create feature extraction instance from string: " << word << std::endl;
2436 switch( pipelineMode ){
2437 case PIPELINE_MODE_NOT_SET:
2439 case CLASSIFICATION_MODE:
2441 if( word !=
"ClassificationModuleDatatype:" ){
2442 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClassificationModuleDatatype" << std::endl;
2451 if( classifier == NULL ){
2452 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create classifier instance from string: " << word << std::endl;
2457 case REGRESSION_MODE:
2459 if( word !=
"RegressionModuleDatatype:" ){
2460 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read RegressionModuleDatatype" << std::endl;
2469 if( regressifier == NULL ){
2470 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create regressifier instance from string: " << word << std::endl;
2477 if( word !=
"ClusterModuleDatatype:" ){
2478 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read ClusterModuleDatatype" << std::endl;
2487 if( clusterer == NULL ){
2488 errorLog <<
"loadPipelineFromFile(string filename) - Failed to create clusterer instance from string: " << word << std::endl;
2499 if( word !=
"PostProcessingModuleDatatypes:" ){
2500 errorLog <<
"loadPipelineFromFile(string filename) - Failed to read PostProcessingModuleDatatypes" << std::endl;
2504 for(UINT i=0; i<numPostprocessingModules; i++){
2510 for(UINT i=0; i<numPreprocessingModules; i++){
2513 if( !preProcessingModules[i]->loadModelFromFile( file ) ){
2514 errorLog <<
"Failed to load preprocessing module " << i <<
" settings from file!" << std::endl;
2521 for(UINT i=0; i<numFeatureExtractionModules; i++){
2524 if( !featureExtractionModules[i]->loadModelFromFile( file ) ){
2525 errorLog <<
"Failed to load feature extraction module " << i <<
" settings from file!" << std::endl;
2532 switch( pipelineMode ){
2533 case PIPELINE_MODE_NOT_SET:
2535 case CLASSIFICATION_MODE:
2537 errorLog <<
"Failed to load classifier model from file!" << std::endl;
2542 case REGRESSION_MODE:
2544 errorLog <<
"Failed to load regressifier model from file!" << std::endl;
2551 errorLog <<
"Failed to load cluster model from file!" << std::endl;
2561 for(UINT i=0; i<numPostprocessingModules; i++){
2564 if( !postProcessingModules[i]->loadModelFromFile( file ) ){
2565 errorLog <<
"Failed to load post processing module " << i <<
" settings from file!" << std::endl;
2575 inputVectorDimensions = 0;
2577 if( numPreprocessingModules > 0 ){
2578 inputVectorDimensions = preProcessingModules[0]->getNumInputDimensions();
2580 if( numFeatureExtractionModules > 0 ){
2581 inputVectorDimensions = featureExtractionModules[0]->getNumInputDimensions();
2583 switch( pipelineMode ){
2584 case PIPELINE_MODE_NOT_SET:
2586 case CLASSIFICATION_MODE:
2589 case REGRESSION_MODE:
2610 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
2612 if( inputVector.size() != preProcessingModules[ moduleIndex ]->getNumInputDimensions() ){
2613 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;
2617 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
2618 errorLog <<
"preProcessData(VectorFloat inputVector) - Failed To PreProcess Input Vector. PreProcessing moduleIndex: " << moduleIndex << std::endl;
2621 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
2627 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
2628 if( inputVector.size() != featureExtractionModules[ moduleIndex ]->getNumInputDimensions() ){
2629 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;
2633 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
2634 errorLog <<
"FeatureExtraction(VectorFloat inputVector) - Failed To Compute Features from Input Vector. FeatureExtraction moduleIndex: " << moduleIndex << std::endl;
2637 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
2654 return preProcessingModules.size() > 0;
2658 return featureExtractionModules.size() > 0;
2662 return (classifier!=NULL);
2666 return (regressifier!=NULL);
2670 return (clusterer!=NULL);
2674 return postProcessingModules.size() > 0;
2678 for(UINT i=0; i<NUM_CONTEXT_LEVELS; i++){
2679 if( contextModules[i].size() > 0 )
return true;
2685 return (pipelineMode!=PIPELINE_MODE_NOT_SET);
2689 return (pipelineMode==CLASSIFICATION_MODE);
2693 return pipelineMode==REGRESSION_MODE;
2699 return preProcessingModules[0]->getNumInputDimensions();
2703 return featureExtractionModules[0]->getNumInputDimensions();
2728 UINT numClasses = 0;
2739 return preProcessingModules.
getSize();
2743 return featureExtractionModules.
getSize();
2747 return postProcessingModules.
getSize();
2751 return predictionModuleIndex;
2757 return predictedClassLabel;
2760 return predictedClusterLabel;
2776 return numTrainingSamples;
2780 return numTestSamples;
2805 return testAccuracy;
2809 return testRMSError;
2813 return testSquaredError;
2821 for(UINT i=0; i<testFMeasure.size(); i++){
2823 return testFMeasure[i];
2834 for(UINT i=0; i<testPrecision.size(); i++){
2836 return testPrecision[i];
2847 for(UINT i=0; i<testRecall.
getSize(); i++){
2849 return testRecall[i];
2856 return testRejectionPrecision;
2860 return testRejectionRecall;
2868 return trainingTime;
2880 return testConfusionMatrix;
2884 TestResult testResults;
2885 testResults.numTrainingSamples = numTrainingSamples;
2886 testResults.numTestSamples = numTestSamples;
2887 testResults.accuracy = testAccuracy;
2888 testResults.rmsError = testRMSError;
2889 testResults.totalSquaredError = testSquaredError;
2890 testResults.trainingTime = trainingTime;
2891 testResults.testTime = testTime;
2892 testResults.rejectionPrecision = testRejectionPrecision;
2893 testResults.rejectionRecall = testRejectionRecall;
2894 testResults.precision = testPrecision;
2895 testResults.recall = testRecall;
2896 testResults.fMeasure = testFMeasure;
2897 testResults.confusionMatrix = testConfusionMatrix;
2902 return testPrecision;
2910 return testFMeasure;
2931 return regressionData;
2943 return preProcessingModules[ preProcessingModules.size()-1 ]->getProcessedData();
2950 if( moduleIndex < preProcessingModules.size() ){
2951 return preProcessingModules[ moduleIndex ]->getProcessedData();
2959 return featureExtractionModules[ featureExtractionModules.size()-1 ]->getFeatureVector();
2966 if( moduleIndex < featureExtractionModules.size() ){
2967 return featureExtractionModules[ moduleIndex ]->getFeatureVector();
2970 warningLog <<
"getFeatureExtractionData(UINT moduleIndex) - Failed to get class labels!" << std::endl;
2981 warningLog <<
"getClassLabels() - Failed to get class labels!" << std::endl;
2990 return crossValidationResults;
2994 if( moduleIndex < preProcessingModules.size() ){
2995 return preProcessingModules[ moduleIndex ];
2997 warningLog <<
"getPreProcessingModule(const UINT moduleIndex) - Failed to get pre processing module!" << std::endl;
3002 if( moduleIndex < featureExtractionModules.size() ){
3003 return featureExtractionModules[ moduleIndex ];
3005 warningLog <<
"getFeatureExtractionModule(const UINT moduleIndex) - Failed to get feature extraction module!" << std::endl;
3014 return regressifier;
3022 if( moduleIndex < postProcessingModules.size() ){
3023 return postProcessingModules[ moduleIndex ];
3025 warningLog <<
"getPostProcessingModule(UINT moduleIndex) - Failed to get post processing module!" << std::endl;
3030 if( contextLevel < contextModules.size() ){
3031 if( moduleIndex < contextModules[ contextLevel ].size() ){
3032 return contextModules[ contextLevel ][ moduleIndex ];
3035 warningLog <<
"getContextModule(UINT contextLevel,UINT moduleIndex) - Failed to get context module!" << std::endl;
3047 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - Invalid insertIndex value!" << std::endl;
3055 if( !newInstance->
deepCopyFrom( &preProcessingModule ) ){
3058 errorLog <<
"addPreProcessingModule(const PreProcessing &preProcessingModule) - PreProcessing Module Not Set!" << std::endl;
3066 else iter = preProcessingModules.begin() + insertIndex;
3068 preProcessingModules.insert(iter, newInstance);
3084 if( insertIndex !=
INSERT_AT_END_INDEX && insertIndex >= featureExtractionModules.size() ){
3085 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule) - Invalid insertIndex value!" << std::endl;
3093 if( !newInstance->
deepCopyFrom( &featureExtractionModule ) ){
3096 errorLog <<
"addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule - FeatureExtraction Module Not Set!" << std::endl;
3104 else iter = featureExtractionModules.begin() + insertIndex;
3106 featureExtractionModules.insert(iter, newInstance);
3123 deleteRegressifier();
3129 if( this->classifier == NULL ){
3130 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << std::endl;
3137 pipelineMode = PIPELINE_MODE_NOT_SET;
3138 errorLog <<
"setClassifier(const Classifier classifier) - Classifier Module Not Set!" << std::endl;
3143 pipelineMode = CLASSIFICATION_MODE;
3153 }
else trained =
false;
3162 deleteRegressifier();
3166 pipelineMode = REGRESSION_MODE;
3172 if( !this->regressifier->
deepCopyFrom( ®ressifier ) ){
3173 deleteRegressifier();
3174 pipelineMode = PIPELINE_MODE_NOT_SET;
3175 errorLog <<
"setRegressifier(const Regressifier ®ressifier) - Regressifier Module Not Set!" << std::endl;
3186 }
else trained =
false;
3195 deleteRegressifier();
3199 pipelineMode = CLUSTER_MODE;
3207 pipelineMode = PIPELINE_MODE_NOT_SET;
3208 errorLog <<
"setClusterer(const Clusterer &clusterer) - Clusterer Module Not Set!" << std::endl;
3219 }
else trained =
false;
3228 errorLog <<
"addPostProcessingModule((const PostProcessing &postProcessingModule) - Invalid insertIndex value!" << std::endl;
3236 if( !newInstance->
deepCopyFrom( &postProcessingModule ) ){
3239 errorLog <<
"addPostProcessingModule(const PostProcessing &postProcessingModule) - PostProcessing Module Not Set!" << std::endl;
3247 else iter = postProcessingModules.begin() + insertIndex;
3249 postProcessingModules.insert(iter, newInstance);
3264 if( contextLevel >= contextModules.size() ){
3265 errorLog <<
"addContextModule(...) - Invalid contextLevel value!" << std::endl;
3270 if( insertIndex !=
INSERT_AT_END_INDEX && insertIndex >= contextModules[contextLevel].size() ){
3271 errorLog <<
"addContextModule(...) - Invalid insertIndex value!" << std::endl;
3279 if( !newInstance->deepCopyFrom( &contextModule ) ){
3282 errorLog <<
"addContextModule(...) - Context Module Not Set!" << std::endl;
3290 else iter = contextModules[ contextLevel ].begin() + insertIndex;
3292 contextModules[ contextLevel ].insert(iter, newInstance);
3300 if( contextLevel >= contextModules.size() ){
3301 errorLog <<
"updateContextModule(...) - Context Level is out of bounds!" << std::endl;
3306 if( moduleIndex >= contextModules[contextLevel].size() ){
3307 errorLog <<
"updateContextModule(...) - Invalid contextLevel value!" << std::endl;
3311 return contextModules[contextLevel][moduleIndex]->updateContext( value );
3315 deleteAllPreProcessingModules();
3320 if( moduleIndex >= preProcessingModules.size() ){
3321 errorLog <<
"removePreProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the preProcessingModules Vector is " << int(preProcessingModules.size()) << std::endl;
3326 delete preProcessingModules[ moduleIndex ];
3327 preProcessingModules[ moduleIndex ] = NULL;
3328 preProcessingModules.erase( preProcessingModules.begin() + moduleIndex );
3337 deleteAllFeatureExtractionModules();
3342 if( moduleIndex >= featureExtractionModules.size() ){
3343 errorLog <<
"removeFeatureExtractionModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the featureExtractionModules Vector is " << int(featureExtractionModules.size()) << std::endl;
3348 delete featureExtractionModules[ moduleIndex ];
3349 featureExtractionModules[ moduleIndex ] = NULL;
3350 featureExtractionModules.erase( featureExtractionModules.begin() + moduleIndex );
3359 deleteAllPostProcessingModules();
3364 if( moduleIndex >= postProcessingModules.size() ){
3365 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the postProcessingModules Vector is " << int(postProcessingModules.size()) << std::endl;
3370 delete postProcessingModules[ moduleIndex ];
3371 postProcessingModules[ moduleIndex ] = NULL;
3372 postProcessingModules.erase( postProcessingModules.begin() + moduleIndex );
3381 if( contextLevel >= NUM_CONTEXT_LEVELS ){
3382 errorLog <<
"removeContextModule(UINT contextLevel,UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
" is out of bounds!" << std::endl;
3386 if( moduleIndex >= contextModules[contextLevel].size() ){
3387 errorLog <<
"removePostProcessingModule(UINT moduleIndex) - Invalid moduleIndex " << moduleIndex <<
". The size of the contextModules Vector at context level " <<
" is " << int(contextModules[contextLevel].size()) << std::endl;
3392 delete contextModules[contextLevel][moduleIndex];
3393 contextModules[contextLevel][moduleIndex] = NULL;
3394 contextModules[contextLevel].erase( contextModules[contextLevel].begin() + moduleIndex );
3399 deleteAllContextModules();
3408 testSquaredError = 0;
3410 testFMeasure.clear();
3411 testPrecision.clear();
3413 testRejectionPrecision = 0;
3414 testRejectionRecall = 0;
3415 testConfusionMatrix.
clear();
3416 testResults.clear();
3417 crossValidationResults.clear();
3431 void GestureRecognitionPipeline::deleteAllPreProcessingModules(){
3432 if( preProcessingModules.size() != 0 ){
3433 for(UINT i=0; i<preProcessingModules.size(); i++){
3434 delete preProcessingModules[i];
3435 preProcessingModules[i] = NULL;
3437 preProcessingModules.clear();
3442 void GestureRecognitionPipeline::deleteAllFeatureExtractionModules(){
3443 if( featureExtractionModules.size() != 0 ){
3444 for(UINT i=0; i<featureExtractionModules.size(); i++){
3445 delete featureExtractionModules[i];
3446 featureExtractionModules[i] = NULL;
3448 featureExtractionModules.clear();
3453 void GestureRecognitionPipeline::deleteClassifier(){
3454 if( classifier != NULL ){
3459 initialized =
false;
3462 void GestureRecognitionPipeline::deleteRegressifier(){
3463 if( regressifier != NULL ){
3464 delete regressifier;
3465 regressifier = NULL;
3468 initialized =
false;
3471 void GestureRecognitionPipeline::deleteClusterer(){
3472 if( clusterer != NULL ){
3477 initialized =
false;
3480 void GestureRecognitionPipeline::deleteAllPostProcessingModules(){
3481 if( postProcessingModules.size() != 0 ){
3482 for(UINT i=0; i<postProcessingModules.size(); i++){
3483 delete postProcessingModules[i];
3484 postProcessingModules[i] = NULL;
3486 postProcessingModules.clear();
3491 void GestureRecognitionPipeline::deleteAllContextModules(){
3492 for(UINT i=0; i<contextModules.size(); i++){
3493 for(UINT j=0; j<contextModules[i].size(); j++){
3494 delete contextModules[i][j];
3495 contextModules[i][j] = NULL;
3497 contextModules[i].clear();
3501 bool GestureRecognitionPipeline::init(){
3502 initialized =
false;
3505 pipelineMode = PIPELINE_MODE_NOT_SET;
3506 inputVectorDimensions = 0;
3507 outputVectorDimensions = 0;
3508 predictedClassLabel = 0;
3509 predictedClusterLabel = 0;
3510 predictionModuleIndex = 0;
3511 numTrainingSamples = 0;
3515 testSquaredError = 0;
3516 testRejectionPrecision = 0;
3517 testRejectionRecall = 0;
3521 regressifier = NULL;
3523 contextModules.
resize( NUM_CONTEXT_LEVELS );
3527 bool GestureRecognitionPipeline::updateTestMetrics(
const UINT classLabel,
const UINT predictedClassLabel,
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter){
3532 UINT predictedClassLabelIndex =0;
3533 bool predictedClassLabelIndexFound =
false;
3536 predictedClassLabelIndex = k;
3537 predictedClassLabelIndexFound =
true;
3542 if( !predictedClassLabelIndexFound && (nullRejectionEnabled ==
false || predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL) ){
3543 errorLog <<
"Failed to find class label index for label: " << predictedClassLabel << std::endl;
3548 UINT actualClassLabelIndex = 0;
3551 actualClassLabelIndex = k;
3557 if( classLabel == predictedClassLabel ){
3561 if( nullRejectionEnabled ==
false ){
3564 if( classLabel == predictedClassLabel ){
3566 testPrecision[ predictedClassLabelIndex ]++;
3569 precisionCounter[ predictedClassLabelIndex ]++;
3572 if( classLabel == predictedClassLabel ){
3574 testRecall[ predictedClassLabelIndex ]++;
3577 recallCounter[ actualClassLabelIndex ]++;
3580 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3581 confusionMatrixCounter[ actualClassLabelIndex ]++;
3585 if( predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3586 if( classLabel == predictedClassLabel ){
3588 testPrecision[ predictedClassLabelIndex ]++;
3591 precisionCounter[ predictedClassLabelIndex ]++;
3595 if( classLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3596 if( classLabel == predictedClassLabel ){
3598 testRecall[ predictedClassLabelIndex ]++;
3601 recallCounter[ actualClassLabelIndex ]++;
3605 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3606 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionPrecision++;
3607 rejectionPrecisionCounter++;
3611 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3612 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionRecall++;
3613 rejectionRecallCounter++;
3617 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) actualClassLabelIndex = 0;
3618 else actualClassLabelIndex++;
3619 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) predictedClassLabelIndex = 0;
3620 else predictedClassLabelIndex++;
3621 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3622 confusionMatrixCounter[ actualClassLabelIndex ]++;
3628 bool GestureRecognitionPipeline::computeTestMetrics(
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter,
const UINT numTestSamples){
3631 testAccuracy = testAccuracy/Float(numTestSamples) * 100.0;
3634 if( precisionCounter[k] > 0 ) testPrecision[k] /= precisionCounter[k];
3635 else testPrecision[k] = 0;
3636 if( recallCounter[k] > 0 ) testRecall[k] /= recallCounter[k];
3637 else testRecall[k] = 0;
3639 if( precisionCounter[k] + recallCounter[k] > 0 )
3640 testFMeasure[k] = 2 * ((testPrecision[k]*testRecall[k])/(testPrecision[k]+testRecall[k]));
3641 else testFMeasure[k] = 0;
3643 if( rejectionPrecisionCounter > 0 ) testRejectionPrecision /= rejectionPrecisionCounter;
3644 if( rejectionRecallCounter > 0 ) testRejectionRecall /= rejectionRecallCounter;
3647 for(UINT r=0; r<confusionMatrixCounter.size(); r++){
3648 if( confusionMatrixCounter[r] > 0 ){
3649 for(UINT c=0; c<testConfusionMatrix.
getNumCols(); c++){
3650 testConfusionMatrix[r][c] /= confusionMatrixCounter[r];
3659 std::string model =
"";
3661 switch( pipelineMode ){
3662 case PIPELINE_MODE_NOT_SET:
3664 case CLASSIFICATION_MODE:
3670 case REGRESSION_MODE:
3684 switch( pipelineMode ){
3685 case PIPELINE_MODE_NOT_SET:
3686 return "PIPELINE_MODE_NOT_SET";
3688 case CLASSIFICATION_MODE:
3689 return "CLASSIFICATION_MODE";
3691 case REGRESSION_MODE:
3692 return "REGRESSION_MODE";
3695 return "ERROR_UNKNWON_PIPELINE_MODE";
3699 return "ERROR_UNKNWON_PIPELINE_MODE";
3702 std::string GestureRecognitionPipeline::getInfo()
const{
3707 if( pipelineModeAsString ==
"PIPELINE_MODE_NOT_SET" ){
3708 return PIPELINE_MODE_NOT_SET;
3710 if( pipelineModeAsString ==
"CLASSIFICATION_MODE" ){
3711 return CLASSIFICATION_MODE;
3713 if( pipelineModeAsString ==
"REGRESSION_MODE" ){
3714 return REGRESSION_MODE;
3716 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()
unsigned int getSize() const
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 deepCopyFrom(const Regressifier *regressifier)
Clusterer * getClusterer() const
UINT getNumDimensions() const
bool getIsPreProcessingSet() const
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)
virtual bool saveModelToFile(std::string filename) const
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
virtual bool loadModelFromFile(std::string filename)
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