From 4d4c6ba31a98d042daf937eb3c6653e88b874147 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@etu.univ-amu.fr>
Date: Fri, 11 Jan 2019 09:51:23 +0100
Subject: [PATCH] Added a program parameter for error analysis

---
 decoder/src/Decoder.cpp                   | 11 +++++++++++
 decoder/src/macaon_decode.cpp             |  3 +++
 error_correction/src/Error.cpp            |  4 ++--
 maca_common/include/ProgramParameters.hpp |  1 +
 maca_common/src/ProgramParameters.cpp     |  1 +
 5 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/decoder/src/Decoder.cpp b/decoder/src/Decoder.cpp
index bfd694e..b4ae4fe 100644
--- a/decoder/src/Decoder.cpp
+++ b/decoder/src/Decoder.cpp
@@ -67,6 +67,17 @@ void Decoder::decode()
     if (classifier->needsTrain() && ProgramParameters::errorAnalysis && (classifier->name == ProgramParameters::classifierName || ProgramParameters::classifierName.empty()))
     {
       auto zeroCostActions = classifier->getZeroCostActions(config);
+      if (zeroCostActions.empty())
+      {
+        fprintf(stderr, "ERROR (%s) : could not find zero cost action for classifier \'%s\'. Aborting.\n", ERRINFO, classifier->name.c_str());
+        config.printForDebug(stderr);
+        for (auto & a : weightedActions)
+        {
+          fprintf(stderr, "%s : ", a.second.second.c_str());
+          Oracle::explainCostOfAction(stderr, config, a.second.second);
+        }
+        exit(1);
+      }
       std::string oAction = zeroCostActions[0];
       for (auto & s : zeroCostActions)
         if (action->name == s)
diff --git a/decoder/src/macaon_decode.cpp b/decoder/src/macaon_decode.cpp
index 87aa954..f401292 100644
--- a/decoder/src/macaon_decode.cpp
+++ b/decoder/src/macaon_decode.cpp
@@ -57,6 +57,8 @@ po::options_description getOptionsDescription()
     ("errorAnalysis", "Print an analysis of errors")
     ("meanEntropy", "Print the mean entropy for error types")
     ("onlyPrefixes", "Only uses the prefixes of error categories")
+    ("nbErrorsToShow", po::value<int>()->default_value(10),
+      "Display only the X most common errors")
     ("classifier", po::value<std::string>()->default_value(""),
       "Name of the monitored classifier, if not specified monitor everyone");
 
@@ -120,6 +122,7 @@ int main(int argc, char * argv[])
   ProgramParameters::mcdName = vm["mcd"].as<std::string>();
   ProgramParameters::debug = vm.count("debug") == 0 ? false : true;
   ProgramParameters::errorAnalysis = vm.count("errorAnalysis") == 0 ? false : true;
+  ProgramParameters::nbErrorsToShow = vm["nbErrorsToShow"].as<int>();
   ProgramParameters::meanEntropy = vm.count("meanEntropy") == 0 ? false : true;
   ProgramParameters::onlyPrefixes = vm.count("onlyPrefixes") == 0 ? false : true;
   ProgramParameters::dicts = vm["dicts"].as<std::string>();
diff --git a/error_correction/src/Error.cpp b/error_correction/src/Error.cpp
index 141e0e1..ca50de4 100644
--- a/error_correction/src/Error.cpp
+++ b/error_correction/src/Error.cpp
@@ -89,8 +89,8 @@ void Errors::printStats()
 {
   unsigned int minDistanceToCheck = 1;
   unsigned int maxDistanceToCheck = 5;
-  int window = 10;
-  int nbErrorsToKeep = 10;
+  int window = 20;
+  int nbErrorsToKeep = ProgramParameters::nbErrorsToShow;
   std::map<std::string, int> nbErrorOccurencesByType;
   std::map<std::string, int> nbFirstErrorOccurencesByType;
   std::map<std::string, float> nbFirstErrorIntroduced;
diff --git a/maca_common/include/ProgramParameters.hpp b/maca_common/include/ProgramParameters.hpp
index ce26f3a..fe1efb0 100644
--- a/maca_common/include/ProgramParameters.hpp
+++ b/maca_common/include/ProgramParameters.hpp
@@ -59,6 +59,7 @@ struct ProgramParameters
   static bool meanEntropy;
   static bool onlyPrefixes;
   static std::map<std::string,std::string> featureModelByClassifier;
+  static int nbErrorsToShow;
 
   private :
 
diff --git a/maca_common/src/ProgramParameters.cpp b/maca_common/src/ProgramParameters.cpp
index c5fe5ea..64d01ac 100644
--- a/maca_common/src/ProgramParameters.cpp
+++ b/maca_common/src/ProgramParameters.cpp
@@ -53,3 +53,4 @@ std::string ProgramParameters::classifierName;
 int ProgramParameters::batchSize;
 std::string ProgramParameters::loss;
 std::map<std::string,std::string> ProgramParameters::featureModelByClassifier;
+int ProgramParameters::nbErrorsToShow;
-- 
GitLab