diff --git a/error_correction/include/Error.hpp b/error_correction/include/Error.hpp index ba4bb0e9530f22f67c16c64675a297a8086013e9..4a49d6bc9eb5026b6bc50c38c01c093cda381671 100644 --- a/error_correction/include/Error.hpp +++ b/error_correction/include/Error.hpp @@ -18,12 +18,16 @@ class Error std::string gold; Classifier::WeightedActions weightedActions; std::string type; + int indexOfPrediction; + int indexOfGold; + int distanceWithGold; public : Error(std::string &, std::string &, Classifier::WeightedActions &); bool isError() const; const std::string & getType() const; + const bool goldWasAtDistance(); }; class ErrorSequence diff --git a/error_correction/src/Error.cpp b/error_correction/src/Error.cpp index 05fa782363321b0e2fa4c6f7601b6384f20f5acf..bf9454079e86c1afde2e9175ee1a5b4d34d5a558 100644 --- a/error_correction/src/Error.cpp +++ b/error_correction/src/Error.cpp @@ -4,6 +4,31 @@ Error::Error(std::string & prediction, std::string & gold, Classifier::WeightedA prediction(prediction), gold(gold), weightedActions(weightedActions) { type = prediction + "->" + gold; + indexOfPrediction = -1; + indexOfGold = -1; + distanceWithGold = 0; + + for (unsigned int i = 0; i < weightedActions.size(); i++) + { + if (weightedActions[i].second.second == prediction) + indexOfPrediction = i; + if (weightedActions[i].second.second == gold) + indexOfGold = i; + if (weightedActions[i].first && indexOfPrediction != -1 && indexOfGold == -1) + distanceWithGold++; + } + + if (indexOfPrediction == -1 || indexOfGold == -1) + { + fprintf(stderr, "ERROR (%s) : weightedActions do not contain prediction or gold. Aborting.\n", ERRINFO); + exit(1); + } + + if (distanceWithGold != 0 && !isError()) + { + fprintf(stderr, "ERROR (%s) : incoherent Error initialization. Aborting.\n", ERRINFO); + exit(1); + } } const std::string & Error::getType() const