21 #define GRT_DLL_EXPORTS 48 this->initialized = rhs.initialized;
49 this->trained = rhs.trained;
50 this->info = rhs.info;
51 this->inputVectorDimensions = rhs.inputVectorDimensions;
52 this->outputVectorDimensions = rhs.outputVectorDimensions;
53 this->predictedClassLabel = rhs.predictedClassLabel;
54 this->predictedClusterLabel = rhs.predictedClusterLabel;
55 this->pipelineMode = rhs.pipelineMode;
56 this->predictionModuleIndex = rhs.predictionModuleIndex;
57 this->numTrainingSamples = rhs.numTrainingSamples;
58 this->numTestSamples = rhs.numTestSamples;
59 this->testAccuracy = rhs.testAccuracy;
60 this->testRMSError = rhs.testRMSError;
61 this->testSquaredError = rhs.testSquaredError;
62 this->testTime = rhs.testTime;
63 this->trainingTime = rhs.trainingTime;
64 this->testFMeasure = rhs.testFMeasure;
65 this->testPrecision = rhs.testPrecision;
66 this->testRecall = rhs.testRecall;
67 this->regressionData = rhs.regressionData;
68 this->testRejectionPrecision = rhs.testRejectionPrecision;
69 this->testRejectionRecall = rhs.testRejectionRecall;
70 this->testConfusionMatrix = rhs.testConfusionMatrix;
71 this->crossValidationResults = rhs.crossValidationResults;
72 this->testResults = rhs.testResults;
74 for(
unsigned int i=0; i<rhs.preProcessingModules.
getSize(); i++){
78 for(
unsigned int i=0; i<rhs.featureExtractionModules.
getSize(); i++){
94 for(
unsigned int i=0; i<rhs.postProcessingModules.
getSize(); i++){
98 for(
unsigned int k=0; k<NUM_CONTEXT_LEVELS; k++){
99 for(
unsigned int i=0; i<rhs.contextModules[k].
getSize(); i++){
105 this->trained = rhs.trained;
154 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, the classifier has not been set!" << std::endl;
159 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, there is no training data!" << std::endl;
175 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
177 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
190 bool okToAddProcessedData =
true;
191 classLabel = trainingData[i].getClassLabel();
192 trainingSample = trainingData[i].getSample();
196 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
197 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
198 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Training Data. PreProcessingModuleIndex: ";
199 errorLog << moduleIndex;
200 errorLog << std::endl;
203 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
209 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
210 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
211 errorLog << __GRT_LOG__ <<
" Failed to Compute Features from Training Data. FeatureExtractionModuleIndex ";
212 errorLog << moduleIndex;
213 errorLog << std::endl;
216 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
217 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
219 okToAddProcessedData =
false;
225 if( okToAddProcessedData ){
227 processedTrainingData.
addSample(classLabel, trainingSample);
233 warningLog << __GRT_LOG__ <<
" Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
240 trained = classifier->
train_( processedTrainingData );
242 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
255 return train_( data, kFoldValue, useStratifiedSampling );
265 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, the classifier has not been set!" << std::endl;
270 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, there is no training data!" << std::endl;
283 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, failed to split data into K folds!" << std::endl;
288 Float crossValidationAccuracy = 0;
293 for(UINT k=0; k<kFoldValue; k++){
297 if( !
train_( foldTrainingData ) ){
304 if( !
test( foldTestData ) ){
316 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
317 crossValidationResults = cvResults;
332 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, the classifier has not been set!" << std::endl;
337 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, there is no training data!" << std::endl;
355 bool allowNullGestureClass =
true;
357 timeseriesClassificationData.setAllowNullGestureClass( allowNullGestureClass );
365 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
368 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
370 timeseriesClassificationData.setNumDimensions( trainingDataInputDimensionSize );
374 trainingDataInputDimensionSize = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
377 trainingDataInputDimensionSize = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
384 UINT classLabel = trainingData[i].getClassLabel();
385 MatrixFloat trainingSample = trainingData[i].getData();
390 bool resetPreprocessingModule =
true;
392 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
393 sample = trainingSample.
getRow( r );
395 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
397 if( resetPreprocessingModule ){
398 preProcessingModules[moduleIndex]->reset();
403 errorLog << __GRT_LOG__ <<
" Failed To PreProcess Training Data. The number of inputDimensions (";
404 errorLog << preProcessingModules[moduleIndex]->getNumInputDimensions();
405 errorLog <<
") in PreProcessingModule ";
406 errorLog << moduleIndex;
407 errorLog <<
" do not match the number of outputDimensions (";
408 errorLog << preProcessingModules[moduleIndex]->getNumOutputDimensions();
409 errorLog << std::endl;
413 if( !preProcessingModules[moduleIndex]->process( sample ) ){
414 errorLog << __GRT_LOG__ <<
" Failed To PreProcess Training Data. PreProcessingModuleIndex: ";
415 errorLog << moduleIndex;
416 errorLog << std::endl;
419 sample = preProcessingModules[moduleIndex]->getProcessedData();
423 resetPreprocessingModule =
false;
426 for(UINT c=0; c<sample.size(); c++){
427 trainingSample[r][c] = sample[c];
434 processedTrainingData.addSample(classLabel,trainingSample);
439 for(UINT i=0; i<processedTrainingData.getNumSamples(); i++){
440 UINT classLabel = processedTrainingData[i].getClassLabel();
442 bool featureDataReady =
false;
443 bool resetFeatureExtractionModules =
true;
448 for(UINT r=0; r<trainingSample.
getNumRows(); r++){
449 inputVector = trainingSample.
getRow( r );
450 featureDataReady =
true;
455 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
457 if( resetFeatureExtractionModules ){
458 featureExtractionModules[moduleIndex]->reset();
461 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
462 errorLog << __GRT_LOG__ <<
" Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: ";
463 errorLog << moduleIndex;
464 errorLog << std::endl;
470 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
471 featureDataReady = featureExtractionModules[moduleIndex]->getFeatureDataReady();
474 if( !featureDataReady ) {
break; }
478 resetFeatureExtractionModules =
false;
480 if( featureDataReady ){
483 if( !featureData.
push_back( inputVector ) ){
484 errorLog << __GRT_LOG__ <<
" Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
487 }
else classificationData.
addSample(classLabel, inputVector);
492 if( !featureData.
push_back( inputVector ) ){
493 errorLog << __GRT_LOG__ <<
" Failed To add feature Vector to feature data matrix! FeatureExtractionModuleIndex: " << std::endl;
497 else classificationData.
addSample(classLabel, inputVector);
507 numTrainingSamples = timeseriesClassificationData.getNumSamples();
508 trained = classifier->
train_( timeseriesClassificationData );
511 trained = classifier->
train_( classificationData );
515 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier" << classifier->
getLastErrorMessage() << std::endl;
528 return train_( data, kFoldValue, useStratifiedSampling );
538 errorLog << __GRT_LOG__ <<
" - Failed To Train Classifier, the classifier has not been set!" << std::endl;
543 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier, there is no training data!" << std::endl;
556 errorLog << __GRT_LOG__ <<
" Failed To Spilt Dataset into KFolds!" << std::endl;
561 Float crossValidationAccuracy = 0;
565 for(UINT k=0; k<kFoldValue; k++){
569 if( !
train_( foldTrainingData ) ){
570 errorLog << __GRT_LOG__ <<
" Failed to train pipeline for fold " << k <<
"." << std::endl;
577 if( !
test( foldTestData ) ){
578 errorLog << __GRT_LOG__ <<
" Failed to test pipeline for fold " << k <<
"." << std::endl;
589 testAccuracy = crossValidationAccuracy / Float(kFoldValue);
604 errorLog << __GRT_LOG__ <<
" Failed To train Classifier, the classifier has not been set!" << std::endl;
609 errorLog << __GRT_LOG__ <<
" Failed To train Classifier, there is no training data!" << std::endl;
620 UINT numDimensions = inputVectorDimensions;
625 numDimensions = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
627 numDimensions = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
640 bool okToAddProcessedData =
true;
641 classLabel = trainingData[i].getClassLabel();
642 trainingSample = trainingData[i].getSample();
646 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
647 if( !preProcessingModules[moduleIndex]->process( trainingSample ) ){
648 errorLog << __GRT_LOG__ <<
" Failed to PreProcess training Data. PreProcessingModuleIndex: ";
649 errorLog << moduleIndex;
650 errorLog << std::endl;
653 trainingSample = preProcessingModules[moduleIndex]->getProcessedData();
659 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
660 if( !featureExtractionModules[moduleIndex]->computeFeatures( trainingSample ) ){
661 errorLog << __GRT_LOG__ <<
" Failed to Compute Features from training Data. FeatureExtractionModuleIndex ";
662 errorLog << moduleIndex;
663 errorLog << std::endl;
666 if( featureExtractionModules[moduleIndex]->getFeatureDataReady() ){
667 trainingSample = featureExtractionModules[moduleIndex]->getFeatureVector();
669 okToAddProcessedData =
false;
675 if( okToAddProcessedData ){
677 processedTrainingData.
addSample(classLabel, trainingSample);
683 warningLog << __GRT_LOG__ <<
" Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
690 trained = classifier->
train_( processedTrainingData );
692 errorLog << __GRT_LOG__ <<
" Failed To Train Classifier: " << classifier->
getLastErrorMessage() << std::endl;
729 numInputs = preProcessingModules[ preProcessingModules.size()-1 ]->getNumOutputDimensions();
733 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
737 numInputs = featureExtractionModules[ featureExtractionModules.size()-1 ]->getNumOutputDimensions();
744 VectorFloat inputVector = trainingData[i].getInputVector();
745 VectorFloat targetVector = trainingData[i].getTargetVector();
748 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
749 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
750 errorLog << __GRT_LOG__ <<
" Failed To Compute Features For Training Data. PreProcessingModuleIndex: " << moduleIndex << std::endl;
754 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
759 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
760 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
761 errorLog << __GRT_LOG__ <<
" Failed To Compute Features For Training Data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
765 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
770 if( !processedTrainingData.
addSample(inputVector,targetVector) ){
771 errorLog << __GRT_LOG__ <<
" Failed to add processed training sample to training data" << std::endl;
781 trained = regressifier->
train_( processedTrainingData );
783 errorLog << __GRT_LOG__ <<
" Failed To Train Regressifier: " << regressifier->
getLastErrorMessage() << std::endl;
787 errorLog << __GRT_LOG__ <<
" Classifier is not set" << std::endl;
802 return train_( data, kFoldValue );
812 errorLog << __GRT_LOG__ <<
" Failed To Train Regressifier, the regressifier has not been set!" << std::endl;
817 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Failed To Train Clusterer, the clusterer has not been set!" << std::endl;
881 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Lost " << trainingData.
getNumSamples()-processedTrainingData.
getNumSamples() <<
" of " << trainingData.
getNumSamples() <<
" training samples due to the processing stage!" << std::endl;
960 trained = clusterer->
train_( processedTrainingData );
962 errorLog << __GRT_LOG__ <<
" Failed To Train Clusterer: " << clusterer->
getLastErrorMessage() << std::endl;
979 errorLog << __GRT_LOG__ <<
" Classifier is not trained" << std::endl;
985 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" The classifier has not been set" << std::endl;
998 bool classLabelValidationPassed =
true;
1000 bool labelFound =
false;
1009 classLabelValidationPassed =
false;
1010 errorLog << __GRT_LOG__ <<
" The test dataset contains a class label (" << testData.
getClassTracker()[i].classLabel <<
") that is not in the model!" << std::endl;
1014 if( !classLabelValidationPassed ){
1015 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Prediction failed for test sample at index: " << i << std::endl;
1062 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1063 errorLog << __GRT_LOG__ <<
" Failed to update test metrics at test sample index: " << i << std::endl;
1075 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, numTestSamples) ){
1076 errorLog << __GRT_LOG__ <<
" Failed to compute test metrics!" << std::endl;
1092 errorLog << __GRT_LOG__ <<
" The classifier has not been trained" << std::endl;
1098 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Failed to run prediction for test sample index: " << i << std::endl;
1147 if( !updateTestMetrics(classLabel,predictedClassLabel,precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter) ){
1148 errorLog << __GRT_LOG__ <<
" Failed to update test metrics at test sample index: " << i << std::endl;
1154 if( !computeTestMetrics(precisionCounter,recallCounter,rejectionPrecisionCounter,rejectionRecallCounter, confusionMatrixCounter, M) ){
1155 errorLog << __GRT_LOG__ <<
" Failed to compute test metrics!" << std::endl;
1171 errorLog << __GRT_LOG__ <<
" The classifier has not been trained" << std::endl;
1177 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Regressifier is not trained" << std::endl;
1281 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" The regressifier has not been set" << std::endl;
1291 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" The classifier has not been trained" << std::endl;
1351 if( inputVector.size() != inputVectorDimensions ){
1352 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" Neither a classifier, regressifer or clusterer is set" << std::endl;
1376 errorLog << __GRT_LOG__ <<
" The classifier has not been trained!" << std::endl;
1381 if( input.
getNumCols() != inputVectorDimensions ){
1382 errorLog << __GRT_LOG__ <<
" 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 << __GRT_LOG__ <<
" A classifier has not been set" << std::endl;
1395 const void *data =
static_cast< const void*
>( &inputMatrix );
1396 DataType dataType = DATA_TYPE_MATRIX;
1399 predictionModuleIndex = START_OF_PIPELINE;
1408 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.
getSize(); moduleIndex++){
1409 MatrixFloat tmpMatrix( inputMatrix.
getNumRows(), preProcessingModules[moduleIndex]->getNumOutputDimensions() );
1411 for(UINT i=0; i<inputMatrix.
getNumRows(); i++){
1412 if( !preProcessingModules[moduleIndex]->process( inputMatrix.
getRow(i) ) ){
1413 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Matrix. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1416 tmpMatrix.
setRowVector( preProcessingModules[moduleIndex]->getProcessedData(), i );
1420 inputMatrix = tmpMatrix;
1425 predictionModuleIndex = AFTER_PREPROCESSING;
1429 const void *feInput = data;
1430 const void *feOutput = NULL;
1431 const UINT numFeatureExtractionModules = featureExtractionModules.
getSize();
1432 DataType inputType = DATA_TYPE_UNKNOWN;
1433 DataType outputType = DATA_TYPE_UNKNOWN;
1434 for(UINT moduleIndex=0; moduleIndex<numFeatureExtractionModules; moduleIndex++){
1436 inputType = featureExtractionModules[ moduleIndex ]->getInputType();
1437 outputType = featureExtractionModules[ moduleIndex ]->getOutputType();
1440 switch( inputType ){
1441 case DATA_TYPE_VECTOR:
1442 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const VectorFloat* >( feInput ) ) ){
1443 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1447 case DATA_TYPE_MATRIX:
1448 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( *static_cast< const MatrixFloat* >( feInput ) ) ){
1449 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Matrix. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1454 errorLog << __GRT_LOG__ <<
" Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1460 switch( outputType ){
1461 case DATA_TYPE_VECTOR:
1462 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureVector() );
1464 case DATA_TYPE_MATRIX:
1465 feOutput =
static_cast< const void*
>( &featureExtractionModules[ moduleIndex ]->getFeatureMatrix() );
1468 errorLog << __GRT_LOG__ <<
" Failed to process data. Unknown output data type for FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1474 if( moduleIndex+1 < numFeatureExtractionModules ){
1481 dataType = outputType;
1485 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1489 case DATA_TYPE_VECTOR:
1491 errorLog << __GRT_LOG__ <<
" Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1495 case DATA_TYPE_MATRIX:
1497 errorLog << __GRT_LOG__ <<
" Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1502 errorLog << __GRT_LOG__ <<
" Failed to run prediction. Unknown data type!" << std::endl;
1513 predictionModuleIndex = AFTER_CLASSIFIER;
1567 predictionModuleIndex = END_OF_PIPELINE;
1572 return predict_regressifier( inputVector );
1575 bool GestureRecognitionPipeline::predict_classifier(
const VectorFloat &input){
1577 predictedClassLabel = 0;
1581 predictionModuleIndex = START_OF_PIPELINE;
1582 if( contextModules[ START_OF_PIPELINE ].size() > 0 ){
1583 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1584 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1585 errorLog << __GRT_LOG__ <<
" Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1588 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1591 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1597 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1598 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1599 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1602 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1607 predictionModuleIndex = AFTER_PREPROCESSING;
1608 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1609 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1610 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1611 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1614 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1615 predictionModuleIndex = AFTER_PREPROCESSING;
1618 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1624 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1625 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1626 errorLog << __GRT_LOG__ <<
" Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1629 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1634 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1635 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1636 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1637 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1638 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1641 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1642 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1645 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1650 if( !classifier->
predict_(inputVector) ){
1651 errorLog << __GRT_LOG__ <<
" Prediction Failed! " << classifier->
getLastErrorMessage() << std::endl;
1657 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1658 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1659 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1660 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1663 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1664 predictionModuleIndex = AFTER_CLASSIFIER;
1667 predictedClassLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1672 predictionModuleIndex = AFTER_CLASSIFIER;
1675 if( pipelineMode != CLASSIFICATION_MODE){
1676 errorLog << __GRT_LOG__ <<
" Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1681 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1684 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1687 data[0] = predictedClassLabel;
1690 if( data.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1691 errorLog << __GRT_LOG__ <<
" 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;
1696 if( !postProcessingModules[moduleIndex]->process( data ) ){
1697 errorLog << __GRT_LOG__ <<
" Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1702 data = postProcessingModules[moduleIndex]->getProcessedData();
1706 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
1708 data = postProcessingModules[moduleIndex]->getProcessedData();
1711 if( data.size() != 1 ){
1712 errorLog << __GRT_LOG__ <<
" 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;
1717 predictedClassLabel = (UINT)data[0];
1724 predictionModuleIndex = END_OF_PIPELINE;
1725 if( contextModules[ END_OF_PIPELINE ].size() ){
1726 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1727 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
1728 errorLog << __GRT_LOG__ <<
" Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1731 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1732 predictionModuleIndex = END_OF_PIPELINE;
1735 predictedClassLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
1742 bool GestureRecognitionPipeline::predict_regressifier(
const VectorFloat &input){
1747 predictionModuleIndex = START_OF_PIPELINE;
1748 if( contextModules[ START_OF_PIPELINE ].size() ){
1749 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1750 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1751 errorLog << __GRT_LOG__ <<
" Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1754 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1757 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1763 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1764 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1765 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1768 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1773 predictionModuleIndex = AFTER_PREPROCESSING;
1774 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1775 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1776 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1777 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1780 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1781 predictionModuleIndex = AFTER_PREPROCESSING;
1784 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1790 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1791 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1792 errorLog << __GRT_LOG__ <<
" Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1795 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1800 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1801 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1802 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1803 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1804 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1807 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1808 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1811 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1816 if( !regressifier->
predict_(inputVector) ){
1817 errorLog << __GRT_LOG__ <<
" Prediction Failed! " << regressifier->
getLastErrorMessage() << std::endl;
1823 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1824 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1825 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process( regressionData ) ){
1826 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1829 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1830 predictionModuleIndex = AFTER_CLASSIFIER;
1833 regressionData = contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData();
1838 predictionModuleIndex = AFTER_CLASSIFIER;
1841 if( pipelineMode != REGRESSION_MODE ){
1842 errorLog << __GRT_LOG__ <<
" Pipeline Mode Is Not In RegressionMode!" << std::endl;
1846 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1847 if( regressionData.size() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1848 errorLog << __GRT_LOG__ <<
" 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;
1852 if( !postProcessingModules[moduleIndex]->process( regressionData ) ){
1853 errorLog << __GRT_LOG__ <<
" Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
1856 regressionData = postProcessingModules[moduleIndex]->getProcessedData();
1862 predictionModuleIndex = END_OF_PIPELINE;
1863 if( contextModules[ END_OF_PIPELINE ].size() ){
1864 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].size(); moduleIndex++){
1865 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1866 errorLog << __GRT_LOG__ <<
" Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1869 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
1870 predictionModuleIndex = END_OF_PIPELINE;
1873 regressionData = contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData();
1880 bool GestureRecognitionPipeline::predict_clusterer(
const VectorFloat &input){
1883 predictedClusterLabel = 0;
1886 predictionModuleIndex = START_OF_PIPELINE;
1887 if( contextModules[ START_OF_PIPELINE ].size() ){
1888 for(UINT moduleIndex=0; moduleIndex<contextModules[ START_OF_PIPELINE ].size(); moduleIndex++){
1889 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->process( inputVector ) ){
1890 errorLog << __GRT_LOG__ <<
" Context Module Failed at START_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
1893 if( !contextModules[ START_OF_PIPELINE ][moduleIndex]->getOK() ){
1896 inputVector = contextModules[ START_OF_PIPELINE ][moduleIndex]->getProcessedData();
1902 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.size(); moduleIndex++){
1903 if( !preProcessingModules[moduleIndex]->process( inputVector ) ){
1904 errorLog << __GRT_LOG__ <<
" Failed to PreProcess Input Vector. PreProcessingModuleIndex: " << moduleIndex << std::endl;
1907 inputVector = preProcessingModules[moduleIndex]->getProcessedData();
1912 predictionModuleIndex = AFTER_PREPROCESSING;
1913 if( contextModules[ AFTER_PREPROCESSING ].size() ){
1914 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_PREPROCESSING ].size(); moduleIndex++){
1915 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->process( inputVector ) ){
1916 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_PREPROCESSING. ModuleIndex: " << moduleIndex << std::endl;
1919 if( !contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getOK() ){
1920 predictionModuleIndex = AFTER_PREPROCESSING;
1923 inputVector = contextModules[ AFTER_PREPROCESSING ][moduleIndex]->getProcessedData();
1929 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.size(); moduleIndex++){
1930 if( !featureExtractionModules[moduleIndex]->computeFeatures( inputVector ) ){
1931 errorLog << __GRT_LOG__ <<
" Failed to compute features from data. FeatureExtractionModuleIndex: " << moduleIndex << std::endl;
1934 inputVector = featureExtractionModules[moduleIndex]->getFeatureVector();
1939 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1940 if( contextModules[ AFTER_FEATURE_EXTRACTION ].size() ){
1941 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_FEATURE_EXTRACTION ].size(); moduleIndex++){
1942 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->process( inputVector ) ){
1943 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_FEATURE_EXTRACTION. ModuleIndex: " << moduleIndex << std::endl;
1946 if( !contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getOK() ){
1947 predictionModuleIndex = AFTER_FEATURE_EXTRACTION;
1950 inputVector = contextModules[ AFTER_FEATURE_EXTRACTION ][moduleIndex]->getProcessedData();
1955 if( !clusterer->
predict_(inputVector) ){
1956 errorLog << __GRT_LOG__ <<
" Prediction Failed! " << clusterer->
getLastErrorMessage() << std::endl;
1962 if( contextModules[ AFTER_CLASSIFIER ].size() ){
1963 for(UINT moduleIndex=0; moduleIndex<contextModules[ AFTER_CLASSIFIER ].size(); moduleIndex++){
1964 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->process(
VectorFloat(1,predictedClusterLabel) ) ){
1965 errorLog << __GRT_LOG__ <<
" Context Module Failed at AFTER_CLASSIFIER. ModuleIndex: " << moduleIndex << std::endl;
1968 if( !contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getOK() ){
1969 predictionModuleIndex = AFTER_CLASSIFIER;
1972 predictedClusterLabel = (UINT)contextModules[ AFTER_CLASSIFIER ][moduleIndex]->getProcessedData()[0];
1977 predictionModuleIndex = AFTER_CLASSIFIER;
1980 if( pipelineMode != CLASSIFICATION_MODE){
1981 errorLog << __GRT_LOG__ <<
" Pipeline Mode Is Not in CLASSIFICATION_MODE!" << std::endl;
1986 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.size(); moduleIndex++){
1989 if( postProcessingModules[moduleIndex]->getIsPostProcessingInputModePredictedClassLabel() ){
1992 data[0] = predictedClusterLabel;
1995 if( data.
getSize() != postProcessingModules[moduleIndex]->getNumInputDimensions() ){
1996 errorLog << __GRT_LOG__ <<
" 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;
2001 if( !postProcessingModules[moduleIndex]->process( data ) ){
2002 errorLog << __GRT_LOG__ <<
" Failed to post process data. PostProcessing moduleIndex: " << moduleIndex << std::endl;
2007 data = postProcessingModules[moduleIndex]->getProcessedData();
2011 if( postProcessingModules[moduleIndex]->getIsPostProcessingOutputModePredictedClassLabel() ){
2013 data = postProcessingModules[moduleIndex]->getProcessedData();
2017 errorLog << __GRT_LOG__ <<
" The size of the processed data Vector (" << int(data.
getSize()) <<
") from postProcessingModule at the moduleIndex: " << moduleIndex <<
" is not equal to 1 even though it is in OutputModePredictedClassLabel!" << std::endl;
2022 predictedClusterLabel = (UINT)data[0];
2029 predictionModuleIndex = END_OF_PIPELINE;
2030 if( contextModules[ END_OF_PIPELINE ].getSize() ){
2031 for(UINT moduleIndex=0; moduleIndex<contextModules[ END_OF_PIPELINE ].
getSize(); moduleIndex++){
2032 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->process(
VectorFloat(1,predictedClassLabel) ) ){
2033 errorLog << __GRT_LOG__ <<
" Context Module Failed at END_OF_PIPELINE. ModuleIndex: " << moduleIndex << std::endl;
2036 if( !contextModules[ END_OF_PIPELINE ][moduleIndex]->getOK() ){
2037 predictionModuleIndex = END_OF_PIPELINE;
2040 predictedClusterLabel = (UINT)contextModules[ END_OF_PIPELINE ][moduleIndex]->getProcessedData()[0];
2051 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.
getSize(); moduleIndex++){
2052 if( !preProcessingModules[ moduleIndex ]->
reset() ){
2053 errorLog << __GRT_LOG__ <<
" Failed To Reset PreProcessingModule " << moduleIndex << std::endl;
2061 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.
getSize(); moduleIndex++){
2062 if( !featureExtractionModules[ moduleIndex ]->
reset() ){
2063 errorLog << __GRT_LOG__ <<
" Failed To Reset FeatureExtractionModule " << moduleIndex << std::endl;
2071 if( !classifier->
reset() ){
2072 errorLog << __GRT_LOG__ <<
" Failed To Reset Classifier! " << classifier->
getLastErrorMessage() << std::endl;
2079 if( !regressifier->
reset() ){
2080 errorLog << __GRT_LOG__ <<
" Failed To Reset Regressifier! " << regressifier->
getLastErrorMessage() << std::endl;
2087 if( !clusterer->
reset() ){
2088 errorLog << __GRT_LOG__ <<
" Failed To Reset clusterer! " << clusterer->
getLastErrorMessage() << std::endl;
2095 for(UINT moduleIndex=0; moduleIndex<postProcessingModules.
getSize(); moduleIndex++){
2096 if( !postProcessingModules[ moduleIndex ]->
reset() ){
2097 errorLog << __GRT_LOG__ <<
" Failed To Reset PostProcessingModule " << moduleIndex << std::endl;
2106 bool GestureRecognitionPipeline::clearAll(){
return clear(); }
2112 deleteAllPreProcessingModules();
2113 deleteAllFeatureExtractionModules();
2115 deleteRegressifier();
2117 deleteAllPostProcessingModules();
2118 deleteAllContextModules();
2128 preProcessingModules[i]->clear();
2133 featureExtractionModules[i]->clear();
2137 switch( pipelineMode ){
2138 case PIPELINE_MODE_NOT_SET:
2140 case CLASSIFICATION_MODE:
2142 classifier->
clear();
2145 case REGRESSION_MODE:
2147 regressifier->
clear();
2161 postProcessingModules[i]->clear();
2167 bool GestureRecognitionPipeline::savePipelineToFile(
const std::string &filename)
const {
2168 return save( filename );
2174 errorLog << __GRT_LOG__ <<
" Failed to write pipeline to file as the pipeline has not been initialized yet!" << std::endl;
2180 file.open(filename.c_str(), std::iostream::out );
2182 if( !file.is_open() ){
2183 errorLog << __GRT_LOG__ <<
" Failed to open file with filename: " << filename << std::endl;
2188 file <<
"GRT_PIPELINE_FILE_V3.0\n";
2193 file <<
"Trained: " <<
getTrained() << std::endl;
2194 file <<
"Info: " << info << std::endl;
2197 file <<
"PreProcessingModuleDatatypes:";
2199 file <<
"\t" << preProcessingModules[i]->getId();
2203 file <<
"FeatureExtractionModuleDatatypes:";
2205 file <<
"\t" << featureExtractionModules[i]->getId();
2209 switch( pipelineMode ){
2210 case PIPELINE_MODE_NOT_SET:
2212 case CLASSIFICATION_MODE:
2214 else file <<
"ClassificationModuleDatatype:\tCLASSIFIER_NOT_SET" << std::endl;
2216 case REGRESSION_MODE:
2218 else file <<
"RegressionModuleDatatype:\tREGRESSIFIER_NOT_SET" << std::endl;
2222 else file <<
"ClusterModuleDatatype:\tCLUSTERER_NOT_SET" << std::endl;
2228 file <<
"PostProcessingModuleDatatypes:";
2230 file <<
"\t" << postProcessingModules[i]->getId();
2237 if( !preProcessingModules[i]->
save( file ) ){
2238 errorLog <<
"Failed to write preprocessing module " << i <<
" settings to file!" << std::endl;
2247 if( !featureExtractionModules[i]->
save( file ) ){
2248 errorLog <<
"Failed to write feature extraction module " << i <<
" settings to file!" << std::endl;
2254 switch( pipelineMode ){
2255 case PIPELINE_MODE_NOT_SET:
2257 case CLASSIFICATION_MODE:
2259 if( !classifier->
save( file ) ){
2260 errorLog <<
"Failed to write classifier model to file!" << std::endl;
2266 case REGRESSION_MODE:
2268 if( !regressifier->
save( file ) ){
2269 errorLog <<
"Failed to write regressifier model to file!" << std::endl;
2277 if( !clusterer->
save( file ) ){
2278 errorLog <<
"Failed to write clusterer model to file!" << std::endl;
2291 if( !postProcessingModules[i]->
save( file ) ){
2292 errorLog <<
"Failed to write post processing module " << i <<
" settings to file!" << std::endl;
2304 bool GestureRecognitionPipeline::loadPipelineFromFile(
const std::string &filename){
2305 return load( filename );
2315 file.open(filename.c_str(), std::iostream::in );
2317 if( !file.is_open() ){
2318 errorLog << __GRT_LOG__ <<
" Failed to open file with filename: " << filename << std::endl;
2326 if( word !=
"GRT_PIPELINE_FILE_V3.0" ){
2327 errorLog << __GRT_LOG__ <<
" Failed to read file header" << std::endl;
2334 if( word !=
"PipelineMode:" ){
2335 errorLog << __GRT_LOG__ <<
" Failed to read PipelineMode" << std::endl;
2344 if( word !=
"NumPreprocessingModules:" ){
2345 errorLog << __GRT_LOG__ <<
" Failed to read NumPreprocessingModules header" << std::endl;
2349 unsigned int numPreprocessingModules;
2350 file >> numPreprocessingModules;
2354 if( word !=
"NumFeatureExtractionModules:" ){
2355 errorLog << __GRT_LOG__ <<
" Failed to read NumFeatureExtractionModules header" << std::endl;
2359 unsigned int numFeatureExtractionModules;
2360 file >> numFeatureExtractionModules;
2364 if( word !=
"NumPostprocessingModules:" ){
2365 errorLog << __GRT_LOG__ <<
" Failed to read NumPostprocessingModules header" << std::endl;
2369 unsigned int numPostprocessingModules;
2370 file >> numPostprocessingModules;
2374 if( word !=
"Trained:" ){
2375 errorLog << __GRT_LOG__ <<
" Failed to read Trained header" << std::endl;
2383 if( word !=
"Info:" ){
2384 errorLog << __GRT_LOG__ <<
" Failed to read Info header" << std::endl;
2391 while( word !=
"PreProcessingModuleDatatypes:" ){
2397 if( numPreprocessingModules > 0 ) preProcessingModules.
resize(numPreprocessingModules,NULL);
2398 if( numFeatureExtractionModules > 0 ) featureExtractionModules.
resize(numFeatureExtractionModules,NULL);
2399 if( numPostprocessingModules > 0 ) postProcessingModules.
resize(numPostprocessingModules,NULL);
2402 if( word !=
"PreProcessingModuleDatatypes:" ){
2403 errorLog << __GRT_LOG__ <<
" Failed to read PreProcessingModuleDatatypes" << std::endl;
2407 for(UINT i=0; i<numPreprocessingModules; i++){
2410 if( preProcessingModules[i] == NULL ){
2411 errorLog << __GRT_LOG__ <<
" Failed to create preprocessing instance from string: " << word << std::endl;
2419 if( word !=
"FeatureExtractionModuleDatatypes:" ){
2420 errorLog << __GRT_LOG__ <<
" Failed to read FeatureExtractionModuleDatatypes" << std::endl;
2424 for(UINT i=0; i<numFeatureExtractionModules; i++){
2427 if( featureExtractionModules[i] == NULL ){
2428 errorLog << __GRT_LOG__ <<
" Failed to create feature extraction instance from string: " << word << std::endl;
2434 switch( pipelineMode ){
2435 case PIPELINE_MODE_NOT_SET:
2437 case CLASSIFICATION_MODE:
2439 if( word !=
"ClassificationModuleDatatype:" ){
2440 errorLog << __GRT_LOG__ <<
" Failed to read ClassificationModuleDatatype" << std::endl;
2449 if( classifier == NULL ){
2450 errorLog << __GRT_LOG__ <<
" Failed to create classifier instance from string: " << word << std::endl;
2455 case REGRESSION_MODE:
2457 if( word !=
"RegressionModuleDatatype:" ){
2458 errorLog << __GRT_LOG__ <<
" Failed to read RegressionModuleDatatype" << std::endl;
2467 if( regressifier == NULL ){
2468 errorLog << __GRT_LOG__ <<
" Failed to create regressifier instance from string: " << word << std::endl;
2475 if( word !=
"ClusterModuleDatatype:" ){
2476 errorLog << __GRT_LOG__ <<
" Failed to read ClusterModuleDatatype" << std::endl;
2485 if( clusterer == NULL ){
2486 errorLog << __GRT_LOG__ <<
" Failed to create clusterer instance from string: " << word << std::endl;
2497 if( word !=
"PostProcessingModuleDatatypes:" ){
2498 errorLog << __GRT_LOG__ <<
" Failed to read PostProcessingModuleDatatypes" << std::endl;
2502 for(UINT i=0; i<numPostprocessingModules; i++){
2508 for(UINT i=0; i<numPreprocessingModules; i++){
2511 if( !preProcessingModules[i]->
load( file ) ){
2512 errorLog << __GRT_LOG__ <<
" Failed to load preprocessing module " << i <<
" settings from file!" << std::endl;
2519 for(UINT i=0; i<numFeatureExtractionModules; i++){
2522 if( !featureExtractionModules[i]->
load( file ) ){
2523 errorLog << __GRT_LOG__ <<
" Failed to load feature extraction module " << i <<
" settings from file!" << std::endl;
2530 switch( pipelineMode ){
2531 case PIPELINE_MODE_NOT_SET:
2533 case CLASSIFICATION_MODE:
2534 if( !classifier->
load( file ) ){
2535 errorLog << __GRT_LOG__ <<
" Failed to load classifier model from file!" << std::endl;
2540 case REGRESSION_MODE:
2541 if( !regressifier->
load( file ) ){
2542 errorLog << __GRT_LOG__ <<
" Failed to load regressifier model from file!" << std::endl;
2548 if( !clusterer->
load( file ) ){
2549 errorLog << __GRT_LOG__ <<
" Failed to load cluster model from file!" << std::endl;
2559 for(UINT i=0; i<numPostprocessingModules; i++){
2562 if( !postProcessingModules[i]->
load( file ) ){
2563 errorLog << __GRT_LOG__ <<
" Failed to load post processing module " << i <<
" settings from file!" << std::endl;
2573 inputVectorDimensions = 0;
2575 if( numPreprocessingModules > 0 ){
2576 inputVectorDimensions = preProcessingModules[0]->getNumInputDimensions();
2578 if( numFeatureExtractionModules > 0 ){
2579 inputVectorDimensions = featureExtractionModules[0]->getNumInputDimensions();
2581 switch( pipelineMode ){
2582 case PIPELINE_MODE_NOT_SET:
2584 case CLASSIFICATION_MODE:
2587 case REGRESSION_MODE:
2608 for(UINT moduleIndex=0; moduleIndex<preProcessingModules.
getSize(); moduleIndex++){
2610 if( inputVector.
getSize() != preProcessingModules[ moduleIndex ]->getNumInputDimensions() ){
2611 errorLog << __GRT_LOG__ <<
" The size of the input Vector (" << preProcessingModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the PreProcessing Module at moduleIndex: " << moduleIndex << std::endl;
2615 if( !preProcessingModules[ moduleIndex ]->process( inputVector ) ){
2616 errorLog << __GRT_LOG__ <<
" Failed To PreProcess Input Vector. PreProcessing moduleIndex: " << moduleIndex << std::endl;
2619 inputVector = preProcessingModules[ moduleIndex ]->getProcessedData();
2625 for(UINT moduleIndex=0; moduleIndex<featureExtractionModules.
getSize(); moduleIndex++){
2626 if( inputVector.
getSize() != featureExtractionModules[ moduleIndex ]->getNumInputDimensions() ){
2627 errorLog << __GRT_LOG__ <<
" The size of the input Vector (" << featureExtractionModules[ moduleIndex ]->getNumInputDimensions() <<
") does not match that of the FeatureExtraction Module at moduleIndex: " << moduleIndex << std::endl;
2631 if( !featureExtractionModules[ moduleIndex ]->computeFeatures( inputVector ) ){
2632 errorLog << __GRT_LOG__ <<
" Failed To Compute Features from Input Vector. FeatureExtraction moduleIndex: " << moduleIndex << std::endl;
2635 inputVector = featureExtractionModules[ moduleIndex ]->getFeatureVector();
2648 return preProcessingModules.
getSize() > 0;
2652 return featureExtractionModules.
getSize() > 0;
2656 return (classifier!=NULL);
2660 return (regressifier!=NULL);
2664 return (clusterer!=NULL);
2668 return postProcessingModules.size() > 0;
2672 for(UINT i=0; i<NUM_CONTEXT_LEVELS; i++){
2673 if( contextModules[i].getSize() > 0 )
return true;
2679 return (pipelineMode!=PIPELINE_MODE_NOT_SET);
2683 return (pipelineMode==CLASSIFICATION_MODE);
2687 return pipelineMode==REGRESSION_MODE;
2693 return preProcessingModules[0]->getNumInputDimensions();
2697 return featureExtractionModules[0]->getNumInputDimensions();
2722 UINT numClasses = 0;
2733 return preProcessingModules.
getSize();
2737 return featureExtractionModules.
getSize();
2741 return postProcessingModules.
getSize();
2745 return predictionModuleIndex;
2751 return predictedClassLabel;
2754 return predictedClusterLabel;
2770 return numTrainingSamples;
2774 return numTestSamples;
2806 return testAccuracy;
2810 return testRMSError;
2814 return testSquaredError;
2822 for(UINT i=0; i<testFMeasure.
getSize(); i++){
2824 return testFMeasure[i];
2835 for(UINT i=0; i<testPrecision.
getSize(); i++){
2837 return testPrecision[i];
2848 for(UINT i=0; i<testRecall.
getSize(); i++){
2850 return testRecall[i];
2857 return testRejectionPrecision;
2861 return testRejectionRecall;
2869 return trainingTime;
2881 return testConfusionMatrix;
2896 testResults.numTrainingSamples = numTrainingSamples;
2897 testResults.numTestSamples = numTestSamples;
2898 testResults.accuracy = testAccuracy;
2899 testResults.rmsError = testRMSError;
2900 testResults.totalSquaredError = testSquaredError;
2901 testResults.trainingTime = trainingTime;
2902 testResults.testTime = testTime;
2903 testResults.rejectionPrecision = testRejectionPrecision;
2904 testResults.rejectionRecall = testRejectionRecall;
2905 testResults.precision = testPrecision;
2906 testResults.recall = testRecall;
2907 testResults.fMeasure = testFMeasure;
2908 testResults.confusionMatrix = testConfusionMatrix;
2913 return testPrecision;
2921 return testFMeasure;
2942 return regressionData;
2954 return preProcessingModules[ preProcessingModules.
getSize()-1 ]->getProcessedData();
2961 if( moduleIndex < preProcessingModules.
getSize() ){
2962 return preProcessingModules[ moduleIndex ]->getProcessedData();
2970 return featureExtractionModules[ featureExtractionModules.
getSize()-1 ]->getFeatureVector();
2977 if( moduleIndex < featureExtractionModules.
getSize() ){
2978 return featureExtractionModules[ moduleIndex ]->getFeatureVector();
2981 warningLog << __GRT_LOG__ <<
" Failed to get class labels!" << std::endl;
2992 warningLog << __GRT_LOG__ <<
" Failed to get class labels!" << std::endl;
3001 return crossValidationResults;
3005 if( moduleIndex < preProcessingModules.
getSize() ){
3006 return preProcessingModules[ moduleIndex ];
3008 warningLog << __GRT_LOG__ <<
" Failed to get pre processing module!" << std::endl;
3013 if( moduleIndex < featureExtractionModules.
getSize() ){
3014 return featureExtractionModules[ moduleIndex ];
3016 warningLog << __GRT_LOG__ <<
" Failed to get feature extraction module!" << std::endl;
3025 return regressifier;
3033 if( moduleIndex < postProcessingModules.
getSize() ){
3034 return postProcessingModules[ moduleIndex ];
3036 warningLog << __GRT_LOG__ <<
"Failed to get post processing module!" << std::endl;
3041 if( contextLevel < contextModules.
getSize() ){
3042 if( moduleIndex < contextModules[ contextLevel ].getSize() ){
3043 return contextModules[ contextLevel ][ moduleIndex ];
3046 warningLog << __GRT_LOG__ <<
" Failed to get context module!" << std::endl;
3058 errorLog << __GRT_LOG__ <<
"Invalid insertIndex value!" << std::endl;
3066 if( !newInstance->
deepCopyFrom( &preProcessingModule ) ){
3069 errorLog << __GRT_LOG__ <<
" PreProcessing Module Not Set!" << std::endl;
3077 else iter = preProcessingModules.begin() + insertIndex;
3079 preProcessingModules.insert(iter, newInstance);
3096 errorLog << __GRT_LOG__ <<
" Invalid insertIndex value!" << std::endl;
3104 if( !newInstance->
deepCopyFrom( &featureExtractionModule ) ){
3107 errorLog << __GRT_LOG__ <<
" FeatureExtraction Module Not Set!" << std::endl;
3115 else iter = featureExtractionModules.begin() + insertIndex;
3117 featureExtractionModules.insert(iter, newInstance);
3134 deleteRegressifier();
3138 this->classifier = classifier.
create( classifier.
getId() );
3140 if( this->classifier == NULL ){
3141 errorLog << __GRT_LOG__ <<
" Classifier Module Not Set!" << std::endl;
3148 pipelineMode = PIPELINE_MODE_NOT_SET;
3149 errorLog << __GRT_LOG__ <<
" Classifier Module Not Set!" << std::endl;
3154 pipelineMode = CLASSIFICATION_MODE;
3164 }
else trained =
false;
3173 deleteRegressifier();
3177 pipelineMode = REGRESSION_MODE;
3180 this->regressifier = regressifier.
create( regressifier.
getId() );
3183 if( !this->regressifier->
deepCopyFrom( ®ressifier ) ){
3184 deleteRegressifier();
3185 pipelineMode = PIPELINE_MODE_NOT_SET;
3186 errorLog << __GRT_LOG__ <<
" Regressifier Module Not Set!" << std::endl;
3197 }
else trained =
false;
3206 deleteRegressifier();
3210 pipelineMode = CLUSTER_MODE;
3213 this->clusterer = clusterer.
create( clusterer.
getId() );
3218 pipelineMode = PIPELINE_MODE_NOT_SET;
3219 errorLog << __GRT_LOG__ <<
" Clusterer Module Not Set!" << std::endl;
3230 }
else trained =
false;
3239 errorLog << __GRT_LOG__ <<
" Invalid insertIndex value!" << std::endl;
3247 if( !newInstance->
deepCopyFrom( &postProcessingModule ) ){
3250 errorLog << __GRT_LOG__ <<
" PostProcessing Module Not Set!" << std::endl;
3258 else iter = postProcessingModules.begin() + insertIndex;
3260 postProcessingModules.insert(iter, newInstance);
3275 if( contextLevel >= contextModules.
getSize() ){
3276 errorLog << __GRT_LOG__ <<
" Invalid contextLevel value!" << std::endl;
3281 if( insertIndex !=
INSERT_AT_END_INDEX && insertIndex >= contextModules[contextLevel].getSize() ){
3282 errorLog << __GRT_LOG__ <<
" Invalid insertIndex value!" << std::endl;
3290 if( !newInstance->deepCopyFrom( &contextModule ) ){
3293 errorLog << __GRT_LOG__ <<
" Context Module Not Set!" << std::endl;
3301 else iter = contextModules[ contextLevel ].begin() + insertIndex;
3303 contextModules[ contextLevel ].insert(iter, newInstance);
3311 if( contextLevel >= contextModules.
getSize() ){
3312 errorLog << __GRT_LOG__ <<
" Context Level is out of bounds!" << std::endl;
3317 if( moduleIndex >= contextModules[contextLevel].getSize() ){
3318 errorLog << __GRT_LOG__ <<
" Invalid contextLevel value!" << std::endl;
3322 return contextModules[contextLevel][moduleIndex]->updateContext( value );
3326 deleteAllPreProcessingModules();
3331 if( moduleIndex >= preProcessingModules.
getSize() ){
3332 errorLog << __GRT_LOG__ <<
" Invalid moduleIndex " << moduleIndex <<
". The size of the preProcessingModules Vector is " << int(preProcessingModules.size()) << std::endl;
3337 delete preProcessingModules[ moduleIndex ];
3338 preProcessingModules[ moduleIndex ] = NULL;
3339 preProcessingModules.erase( preProcessingModules.begin() + moduleIndex );
3348 deleteAllFeatureExtractionModules();
3353 if( moduleIndex >= featureExtractionModules.
getSize() ){
3354 errorLog << __GRT_LOG__ <<
" Invalid moduleIndex " << moduleIndex <<
". The size of the featureExtractionModules Vector is " << int(featureExtractionModules.size()) << std::endl;
3359 delete featureExtractionModules[ moduleIndex ];
3360 featureExtractionModules[ moduleIndex ] = NULL;
3361 featureExtractionModules.erase( featureExtractionModules.begin() + moduleIndex );
3370 deleteAllPostProcessingModules();
3375 if( moduleIndex >= postProcessingModules.size() ){
3376 errorLog << __GRT_LOG__ <<
" Invalid moduleIndex " << moduleIndex <<
". The size of the postProcessingModules Vector is " << int(postProcessingModules.size()) << std::endl;
3381 delete postProcessingModules[ moduleIndex ];
3382 postProcessingModules[ moduleIndex ] = NULL;
3383 postProcessingModules.erase( postProcessingModules.begin() + moduleIndex );
3392 if( contextLevel >= NUM_CONTEXT_LEVELS ){
3393 errorLog << __GRT_LOG__ <<
" Invalid moduleIndex " << moduleIndex <<
" is out of bounds!" << std::endl;
3397 if( moduleIndex >= contextModules[contextLevel].size() ){
3398 errorLog << __GRT_LOG__ <<
" Invalid moduleIndex " << moduleIndex <<
". The size of the contextModules Vector at context level " <<
" is " << int(contextModules[contextLevel].size()) << std::endl;
3403 delete contextModules[contextLevel][moduleIndex];
3404 contextModules[contextLevel][moduleIndex] = NULL;
3405 contextModules[contextLevel].erase( contextModules[contextLevel].begin() + moduleIndex );
3410 deleteAllContextModules();
3419 testSquaredError = 0;
3421 testFMeasure.clear();
3422 testPrecision.clear();
3424 testRejectionPrecision = 0;
3425 testRejectionRecall = 0;
3426 testConfusionMatrix.
clear();
3427 testResults.clear();
3428 crossValidationResults.clear();
3442 void GestureRecognitionPipeline::deleteAllPreProcessingModules(){
3443 if( preProcessingModules.
getSize() != 0 ){
3444 for(UINT i=0; i<preProcessingModules.
getSize(); i++){
3445 delete preProcessingModules[i];
3446 preProcessingModules[i] = NULL;
3448 preProcessingModules.clear();
3453 void GestureRecognitionPipeline::deleteAllFeatureExtractionModules(){
3454 if( featureExtractionModules.
getSize() != 0 ){
3455 for(UINT i=0; i<featureExtractionModules.
getSize(); i++){
3456 delete featureExtractionModules[i];
3457 featureExtractionModules[i] = NULL;
3459 featureExtractionModules.clear();
3464 void GestureRecognitionPipeline::deleteClassifier(){
3465 if( classifier != NULL ){
3470 initialized =
false;
3473 void GestureRecognitionPipeline::deleteRegressifier(){
3474 if( regressifier != NULL ){
3475 delete regressifier;
3476 regressifier = NULL;
3479 initialized =
false;
3482 void GestureRecognitionPipeline::deleteClusterer(){
3483 if( clusterer != NULL ){
3488 initialized =
false;
3491 void GestureRecognitionPipeline::deleteAllPostProcessingModules(){
3492 if( postProcessingModules.size() != 0 ){
3493 for(UINT i=0; i<postProcessingModules.
getSize(); i++){
3494 delete postProcessingModules[i];
3495 postProcessingModules[i] = NULL;
3497 postProcessingModules.clear();
3502 void GestureRecognitionPipeline::deleteAllContextModules(){
3503 for(UINT i=0; i<contextModules.
getSize(); i++){
3504 for(UINT j=0; j<contextModules[i].
getSize(); j++){
3505 delete contextModules[i][j];
3506 contextModules[i][j] = NULL;
3508 contextModules[i].clear();
3512 bool GestureRecognitionPipeline::init(){
3513 initialized =
false;
3516 pipelineMode = PIPELINE_MODE_NOT_SET;
3517 inputVectorDimensions = 0;
3518 outputVectorDimensions = 0;
3519 predictedClassLabel = 0;
3520 predictedClusterLabel = 0;
3521 predictionModuleIndex = 0;
3522 numTrainingSamples = 0;
3526 testSquaredError = 0;
3527 testRejectionPrecision = 0;
3528 testRejectionRecall = 0;
3532 regressifier = NULL;
3534 contextModules.
resize( NUM_CONTEXT_LEVELS );
3538 bool GestureRecognitionPipeline::updateTestMetrics(
const UINT classLabel,
const UINT predictedClassLabel,
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter){
3543 UINT predictedClassLabelIndex =0;
3544 bool predictedClassLabelIndexFound =
false;
3546 for(UINT k=0; k<K; k++){
3548 predictedClassLabelIndex = k;
3549 predictedClassLabelIndexFound =
true;
3554 if( !predictedClassLabelIndexFound && (nullRejectionEnabled ==
false || predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL) ){
3555 errorLog << __GRT_LOG__ <<
" Failed to find class label index for label: " << predictedClassLabel << std::endl;
3560 UINT actualClassLabelIndex = 0;
3561 for(UINT k=0; k<K; k++){
3563 actualClassLabelIndex = k;
3569 if( classLabel == predictedClassLabel ){
3573 if( nullRejectionEnabled ==
false ){
3576 if( classLabel == predictedClassLabel ){
3578 testPrecision[ predictedClassLabelIndex ]++;
3581 precisionCounter[ predictedClassLabelIndex ]++;
3584 if( classLabel == predictedClassLabel ){
3586 testRecall[ predictedClassLabelIndex ]++;
3589 recallCounter[ actualClassLabelIndex ]++;
3592 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3593 confusionMatrixCounter[ actualClassLabelIndex ]++;
3597 if( predictedClassLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3598 if( classLabel == predictedClassLabel ){
3600 testPrecision[ predictedClassLabelIndex ]++;
3603 precisionCounter[ predictedClassLabelIndex ]++;
3607 if( classLabel != GRT_DEFAULT_NULL_CLASS_LABEL ){
3608 if( classLabel == predictedClassLabel ){
3610 testRecall[ predictedClassLabelIndex ]++;
3613 recallCounter[ actualClassLabelIndex ]++;
3617 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3618 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionPrecision++;
3619 rejectionPrecisionCounter++;
3623 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ){
3624 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) testRejectionRecall++;
3625 rejectionRecallCounter++;
3629 if( classLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) actualClassLabelIndex = 0;
3630 else actualClassLabelIndex++;
3631 if( predictedClassLabel == GRT_DEFAULT_NULL_CLASS_LABEL ) predictedClassLabelIndex = 0;
3632 else predictedClassLabelIndex++;
3633 testConfusionMatrix[ actualClassLabelIndex ][ predictedClassLabelIndex ]++;
3634 confusionMatrixCounter[ actualClassLabelIndex ]++;
3640 bool GestureRecognitionPipeline::computeTestMetrics(
VectorFloat &precisionCounter,
VectorFloat &recallCounter,Float &rejectionPrecisionCounter,Float &rejectionRecallCounter,
VectorFloat &confusionMatrixCounter,
const UINT numTestSamples){
3643 testAccuracy = testAccuracy/Float(numTestSamples) * 100.0;
3646 if( precisionCounter[k] > 0 ) testPrecision[k] /= precisionCounter[k];
3647 else testPrecision[k] = 0;
3648 if( recallCounter[k] > 0 ) testRecall[k] /= recallCounter[k];
3649 else testRecall[k] = 0;
3651 if( precisionCounter[k] + recallCounter[k] > 0 )
3652 testFMeasure[k] = 2 * ((testPrecision[k]*testRecall[k])/(testPrecision[k]+testRecall[k]));
3653 else testFMeasure[k] = 0;
3655 if( rejectionPrecisionCounter > 0 ) testRejectionPrecision /= rejectionPrecisionCounter;
3656 if( rejectionRecallCounter > 0 ) testRejectionRecall /= rejectionRecallCounter;
3658 for(UINT r=0; r<confusionMatrixCounter.
getSize(); r++){
3659 if( confusionMatrixCounter[r] > 0 ){
3660 for(UINT c=0; c<testConfusionMatrix.
getNumCols(); c++){
3661 testConfusionMatrix[r][c] /= confusionMatrixCounter[r];
3670 std::string model =
"";
3672 switch( pipelineMode ){
3673 case PIPELINE_MODE_NOT_SET:
3675 case CLASSIFICATION_MODE:
3677 model +=
"Classifier: " + classifier->
getId() +
"\n";
3681 case REGRESSION_MODE:
3683 model +=
"Regressifier: " + regressifier->
getId() +
"\n";
3695 switch( pipelineMode ){
3696 case PIPELINE_MODE_NOT_SET:
3697 return "PIPELINE_MODE_NOT_SET";
3699 case CLASSIFICATION_MODE:
3700 return "CLASSIFICATION_MODE";
3702 case REGRESSION_MODE:
3703 return "REGRESSION_MODE";
3706 return "ERROR_UNKNWON_PIPELINE_MODE";
3710 return "ERROR_UNKNWON_PIPELINE_MODE";
3713 std::string GestureRecognitionPipeline::getInfo()
const{
3718 if( pipelineModeAsString ==
"PIPELINE_MODE_NOT_SET" ){
3719 return PIPELINE_MODE_NOT_SET;
3721 if( pipelineModeAsString ==
"CLASSIFICATION_MODE" ){
3722 return CLASSIFICATION_MODE;
3724 if( pipelineModeAsString ==
"REGRESSION_MODE" ){
3725 return REGRESSION_MODE;
3727 return PIPELINE_MODE_NOT_SET;
bool removePostProcessingModule(const UINT moduleIndex)
virtual bool load(const std::string &filename) override
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
std::string getId() const
Float getTrainingSSError() const
UINT getOutputVectorDimensionsSize() const
UINT getNumPreProcessingModules() const
VectorFloat getNullRejectionThresholds() const
Float getTrainingSetAccuracy() 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 setAllowNullGestureClass(const bool allowNullGestureClass)
virtual bool reset() override
Float getTestRMSError() const
TestResult getTestResults() const
virtual bool deepCopyFrom(const PreProcessing *rhs)
bool getIsPipelineModeSet() const
virtual bool predict_(VectorFloat &inputVector)
bool getIsPipelineInRegressionMode() const
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)
bool addSample(const UINT classLabel, const VectorFloat &sample)
virtual bool clear() override
Vector< ClassTracker > getClassTracker() const
virtual bool save(const std::string &filename) const override
virtual UINT getNumClasses() const
PostProcessing * create() const
VectorFloat getClusterLikelihoods() const
Float getMaximumLikelihood() const
virtual bool train(const ClassificationData &trainingData, const UINT kFoldValue, const bool useStratifiedSampling=false)
bool getTimeseriesCompatible() const
Float getTestTime() const
virtual bool clear() override
bool resetPlaybackIndex(const UINT playbackIndex)
VectorFloat getPreProcessedData() const
Float getTestRejectionRecall() const
bool setRowVector(const Vector< T > &row, const unsigned int rowIndex)
virtual bool clear() override
UINT getNumDimensions() const
virtual bool resize(const unsigned int size)
bool setNumDimensions(UINT numDimensions)
RegressionData getTrainingFoldData(const UINT foldIndex) const
virtual bool deepCopyFrom(const Clusterer *clusterer)
Float getTestAccuracy() const
bool removeAllFeatureExtractionModules()
UINT getNumSamples() const
virtual bool train_(MatrixFloat &trainingData) override
UINT getNumOutputDimensions() const
bool addContextModule(const Context &contextModule, UINT contextLevel, UINT insertIndex=INSERT_AT_END_INDEX)
Regressifier * create() const
bool preProcessData(VectorFloat inputVector, bool computeFeatures=true)
Float getCrossValidationAccuracy() const
virtual bool clearModel()
UINT getInputVectorDimensionsSize() const
bool setRegressifier(const Regressifier ®ressifier)
UINT getPredictionModuleIndexPosition() const
UINT getNumInputDimensions() const
Classifier * getClassifier() const
virtual bool save(const std::string &filename) const
bool removeFeatureExtractionModule(UINT moduleIndex)
virtual bool reset() override
bool removeAllPreProcessingModules()
static std::string intToString(const int &i)
std::string getLastErrorMessage() const
bool setClassifier(const Classifier &classifier)
signed long getMilliSeconds()
virtual bool predict_(VectorFloat &inputVector) override
Vector< TestInstanceResult > getTestInstanceResults() const
UINT getNumTrainingSamples() const
This is the main base class that all GRT PostProcessing algorithms should inherit from...
static Clusterer * create(std::string const &id)
std::string getPipelineModeAsString() const
Float getRMSTrainingError() const
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
UINT getNumSamples() const
UINT getNumTargetDimensions() const
virtual bool train_(ClassificationData &trainingData) override
ClassificationSample getNextSample()
UINT getUnProcessedPredictedClassLabel() const
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
UINT getNumClassesInModel() const
virtual std::string getModelAsString() const override
Float getTotalSquaredTrainingError() const
Vector< UINT > getClusterLabels() const
static PostProcessing * create(const std::string &postProcessingType)
bool addPreProcessingModule(const PreProcessing &preProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool getNullRejectionEnabled() const
bool setClusterer(const Clusterer &clusterer)
static Context * create(std::string const &id)
UINT getPredictedClassLabel() const
static PreProcessing * create(const std::string &id)
GestureRecognitionPipeline & operator=(const GestureRecognitionPipeline &rhs)
static Regressifier * create(const std::string &id)
Float getTrainingRMSError() const
Clusterer * create() const
bool copyMLBaseVariables(const MLBase *mlBase)
UINT getPipelineModeFromString(std::string pipelineMode) const
PreProcessing * create() const
bool getIsFeatureExtractionSet() const
UINT getNumTestSamples() const
bool getIsContextSet() const
bool getIsClassifierSet() const
unsigned int getNumRows() const
UINT getNumDimensions() const
UINT getNumClasses() const
virtual std::string getModelAsString() const
unsigned int getNumCols() const
UINT getPredictedClusterLabel() const
Context * getContextModule(const UINT contextLevel, const UINT moduleIndex) const
bool removeAllPostProcessingModules()
Float getMaximumLikelihood() const
bool setFeatureExtractionModule(const FeatureExtraction &featureExtractionModule)
bool addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule, UINT insertIndex=INSERT_AT_END_INDEX)
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)
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
Float getTrainingSetAccuracy() 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
bool reserve(const UINT M)
VectorFloat getRegressionData() const
VectorFloat getRegressionData() const
PostProcessing * getPostProcessingModule(UINT moduleIndex) const
virtual bool reset() override
#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
This class stores the class label and raw data for a single labelled classification sample...
VectorFloat getUnProcessedRegressionData() const
UINT getNumInputDimensions() const
virtual bool map_(VectorFloat &inputVector)
UINT getNumFeatureExtractionModules() const
Regressifier * getRegressifier() const
VectorFloat getClusterDistances() const
VectorFloat getTestRecall() const
ClassificationData getTrainingFoldData(const UINT foldIndex) const
UINT getNumSamples() const
RegressionData getTestFoldData(const UINT foldIndex) const
virtual bool test(const ClassificationData &testData)
virtual bool load(const std::string &filename)
bool push_back(const Vector< T > &sample)
Float getTestSSError() const
GestureRecognitionPipeline(void)
Vector< TrainingResult > getTrainingResults() const
virtual bool map(VectorFloat inputVector)
Classifier * create() const
TimeSeriesClassificationData getTrainingFoldData(const UINT foldIndex) const
Float getMaximumLikelihood() const
bool getIsRegressifierSet() const
This is the main base class that all GRT machine learning algorithms should inherit from...
This is the main base class that all GRT Classification algorithms should inherit from...
bool setPreProcessingModule(const PreProcessing &preProcessingModule)
VectorFloat getTestPrecision() const
bool addSample(const VectorFloat &inputVector, const VectorFloat &targetVector)
virtual bool getIsInitialized() const
Vector< TrainingResult > getTrainingResults() const
Float getTrainingTime() const
bool spiltDataIntoKFolds(const UINT K)
VectorFloat getFeatureExtractionData() const
UINT getNumSamples() const
static Classifier * create(const std::string &id)
TimeSeriesClassificationData getTestFoldData(const UINT foldIndex) const