diff --git a/src/Platform/BestResults.cc b/src/Platform/BestResults.cc index d2b27ef..5dd34f4 100644 --- a/src/Platform/BestResults.cc +++ b/src/Platform/BestResults.cc @@ -282,12 +282,15 @@ namespace platform { // Print the table of results printTableResults(models, table); // Compute the Friedman test + map> ranksModels; if (friedman) { Statistics stats(models, datasets, table, significance); auto result = stats.friedmanTest(); stats.postHocHolmTest(result); + ranksModels = stats.getRanks(); } if (excel) { + // BestResultsExcel excel(score, models, datasets, ranksModels, table, friedman, significance); BestResultsExcel excel(score, models, datasets, table, friedman, significance); excel.build(); cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl; diff --git a/src/Platform/BestResultsExcel.cc b/src/Platform/BestResultsExcel.cc index d536f93..937d0e7 100644 --- a/src/Platform/BestResultsExcel.cc +++ b/src/Platform/BestResultsExcel.cc @@ -4,7 +4,8 @@ #include "Statistics.h" namespace platform { - BestResultsExcel::BestResultsExcel(string score, vector models, vector datasets, json table, bool friedman, double significance) : score(score), models(models), datasets(datasets), table(table), friedman(friedman), significance(significance) + BestResultsExcel::BestResultsExcel(const string& score, const vector& models, const vector& datasets, const json& table, bool friedman, double significance) : + score(score), models(models), datasets(datasets), table(table), friedman(friedman), significance(significance) { workbook = workbook_new((Paths::excel() + fileName).c_str()); worksheet = workbook_add_worksheet(workbook, "Best Results"); diff --git a/src/Platform/BestResultsExcel.h b/src/Platform/BestResultsExcel.h index 93eb017..fef9add 100644 --- a/src/Platform/BestResultsExcel.h +++ b/src/Platform/BestResultsExcel.h @@ -2,6 +2,7 @@ #define BESTRESULTS_EXCEL_H #include "ExcelFile.h" #include +#include #include using namespace std; @@ -11,7 +12,7 @@ namespace platform { class BestResultsExcel : ExcelFile { public: - BestResultsExcel(string score, vector models, vector datasets, json table, bool friedman, double significance); + BestResultsExcel(const string& score, const vector& models, const vector& datasets, const json& table, bool friedman, double significance); ~BestResultsExcel(); void build(); string getFileName(); @@ -21,14 +22,15 @@ namespace platform { void footer(); void formatColumns(); const string fileName = "BestResults.xlsx"; - string score; - vector models; - vector datasets; - json table; + const string& score; + const vector& models; + const vector& datasets; + const json& table; bool friedman; double significance; int modelNameSize = 12; // Min size of the column int datasetNameSize = 25; // Min size of the column + // map>& ranksModels; }; } #endif //BESTRESULTS_EXCEL_H \ No newline at end of file diff --git a/src/Platform/Statistics.cc b/src/Platform/Statistics.cc index 10cf91c..bf5451c 100644 --- a/src/Platform/Statistics.cc +++ b/src/Platform/Statistics.cc @@ -7,7 +7,7 @@ namespace platform { - Statistics::Statistics(vector& models, vector& datasets, json data, double significance, bool output) : + Statistics::Statistics(const vector& models, const vector& datasets, const json& data, double significance, bool output) : models(models), datasets(datasets), data(data), significance(significance), output(output) { nModels = models.size(); @@ -21,6 +21,7 @@ namespace platform { cerr << "nDatasets: " << nDatasets << endl; throw runtime_error("Can't make the Friedman test with less than 3 models and/or less than 3 datasets."); } + ranksModels.clear(); computeRanks(); // Set the control model as the one with the lowest average rank controlIdx = distance(ranks.begin(), min_element(ranks.begin(), ranks.end(), [](const auto& l, const auto& r) { return l.second < r.second; })); @@ -68,6 +69,8 @@ namespace platform { } // Assign the ranks ranksLine = assignRanks(ranksOrder); + // Store the ranks of the dataset + ranksModels[dataset] = ranksLine; if (ranks.size() == 0) { ranks = ranksLine; } else { @@ -239,4 +242,8 @@ namespace platform { { return holmResult; } + map>& Statistics::getRanks() + { + return ranksModels; + } } // namespace platform diff --git a/src/Platform/Statistics.h b/src/Platform/Statistics.h index a3f9b3c..a84aed7 100644 --- a/src/Platform/Statistics.h +++ b/src/Platform/Statistics.h @@ -2,6 +2,7 @@ #define STATISTICS_H #include #include +#include #include using namespace std; @@ -32,18 +33,19 @@ namespace platform { }; class Statistics { public: - Statistics(vector& models, vector& datasets, json data, double significance = 0.05, bool output = true); + Statistics(const vector& models, const vector& datasets, const json& data, double significance = 0.05, bool output = true); bool friedmanTest(); void postHocHolmTest(bool friedmanResult); FriedmanResult& getFriedmanResult(); HolmResult& getHolmResult(); + map>& getRanks(); private: void fit(); void computeRanks(); void computeWTL(); - vector models; - vector datasets; - json data; + const vector& models; + const vector& datasets; + const json& data; double significance; bool output; bool fitted = false; @@ -56,6 +58,7 @@ namespace platform { int maxDatasetName = 0; FriedmanResult friedmanResult; HolmResult holmResult; + map> ranksModels; }; } #endif // !STATISTICS_H \ No newline at end of file