Add constant references to Statistics
This commit is contained in:
parent
c4ae3fe429
commit
55e742438f
@ -282,12 +282,15 @@ namespace platform {
|
||||
// Print the table of results
|
||||
printTableResults(models, table);
|
||||
// Compute the Friedman test
|
||||
map<string, map<string, float>> 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;
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include "Statistics.h"
|
||||
|
||||
namespace platform {
|
||||
BestResultsExcel::BestResultsExcel(string score, vector<string> models, vector<string> 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<string>& models, const vector<string>& 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");
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define BESTRESULTS_EXCEL_H
|
||||
#include "ExcelFile.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace std;
|
||||
@ -11,7 +12,7 @@ namespace platform {
|
||||
|
||||
class BestResultsExcel : ExcelFile {
|
||||
public:
|
||||
BestResultsExcel(string score, vector<string> models, vector<string> datasets, json table, bool friedman, double significance);
|
||||
BestResultsExcel(const string& score, const vector<string>& models, const vector<string>& 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<string> models;
|
||||
vector<string> datasets;
|
||||
json table;
|
||||
const string& score;
|
||||
const vector<string>& models;
|
||||
const vector<string>& 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<string, map<string, float>>& ranksModels;
|
||||
};
|
||||
}
|
||||
#endif //BESTRESULTS_EXCEL_H
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace platform {
|
||||
|
||||
Statistics::Statistics(vector<string>& models, vector<string>& datasets, json data, double significance, bool output) :
|
||||
Statistics::Statistics(const vector<string>& models, const vector<string>& 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<string, map<string, float>>& Statistics::getRanks()
|
||||
{
|
||||
return ranksModels;
|
||||
}
|
||||
} // namespace platform
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define STATISTICS_H
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace std;
|
||||
@ -32,18 +33,19 @@ namespace platform {
|
||||
};
|
||||
class Statistics {
|
||||
public:
|
||||
Statistics(vector<string>& models, vector<string>& datasets, json data, double significance = 0.05, bool output = true);
|
||||
Statistics(const vector<string>& models, const vector<string>& datasets, const json& data, double significance = 0.05, bool output = true);
|
||||
bool friedmanTest();
|
||||
void postHocHolmTest(bool friedmanResult);
|
||||
FriedmanResult& getFriedmanResult();
|
||||
HolmResult& getHolmResult();
|
||||
map<string, map<string, float>>& getRanks();
|
||||
private:
|
||||
void fit();
|
||||
void computeRanks();
|
||||
void computeWTL();
|
||||
vector<string> models;
|
||||
vector<string> datasets;
|
||||
json data;
|
||||
const vector<string>& models;
|
||||
const vector<string>& 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<string, map<string, float>> ranksModels;
|
||||
};
|
||||
}
|
||||
#endif // !STATISTICS_H
|
Loading…
Reference in New Issue
Block a user