From 3ea028511989a93b38c6d6fd759a97b3f552aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Mon, 25 Sep 2023 18:38:12 +0200 Subject: [PATCH] Fix ranks to match friedman test ranks --- src/Platform/BestResults.cc | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Platform/BestResults.cc b/src/Platform/BestResults.cc index d529cbf..6d8505e 100644 --- a/src/Platform/BestResults.cc +++ b/src/Platform/BestResults.cc @@ -200,6 +200,34 @@ namespace platform { table["dateTable"] = ftime_to_string(maxDate); return table; } + map assignRanks(vector>& ranksOrder) + { + // sort the ranksOrder vector by value + sort(ranksOrder.begin(), ranksOrder.end(), [](const pair& a, const pair& b) { + return a.second > b.second; + }); + //Assign ranks to values and if they are the same they share the same averaged rank + map ranks; + for (int i = 0; i < ranksOrder.size(); i++) { + ranks[ranksOrder[i].first] = i + 1.0; + } + int i = 0; + while (i < static_cast(ranksOrder.size())) { + int j = i + 1; + int sumRanks = ranks[ranksOrder[i].first]; + while (j < static_cast(ranksOrder.size()) && ranksOrder[i].second == ranksOrder[j].second) { + sumRanks += ranks[ranksOrder[j++].first]; + } + if (j > i + 1) { + float averageRank = (float)sumRanks / (j - i); + for (int k = i; k < j; k++) { + ranks[ranksOrder[k].first] = averageRank; + } + } + i = j; + } + return ranks; + } void BestResults::printTableResults(set models, json table) { cout << Colors::GREEN() << "Best results for " << score << " as of " << table.at("dateTable").get() << endl; @@ -217,7 +245,6 @@ namespace platform { auto i = 0; bool odd = true; map totals; - map ranks; for (const auto& model : models) { totals[model] = 0.0; } @@ -236,14 +263,8 @@ namespace platform { } ranksOrder.push_back({ model, value }); } - // sort the ranksOrder vector by value - sort(ranksOrder.begin(), ranksOrder.end(), [](const pair& a, const pair& b) { - return a.second > b.second; - }); // Assign the ranks - for (int i = 0; i < ranksOrder.size(); i++) { - ranks[ranksOrder[i].first] = i + 1; - } + auto ranks = assignRanks(ranksOrder); // Print the row with red colors on max values for (const auto& model : models) { string efectiveColor = color;