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
|
// Print the table of results
|
||||||
printTableResults(models, table);
|
printTableResults(models, table);
|
||||||
// Compute the Friedman test
|
// Compute the Friedman test
|
||||||
|
map<string, map<string, float>> ranksModels;
|
||||||
if (friedman) {
|
if (friedman) {
|
||||||
Statistics stats(models, datasets, table, significance);
|
Statistics stats(models, datasets, table, significance);
|
||||||
auto result = stats.friedmanTest();
|
auto result = stats.friedmanTest();
|
||||||
stats.postHocHolmTest(result);
|
stats.postHocHolmTest(result);
|
||||||
|
ranksModels = stats.getRanks();
|
||||||
}
|
}
|
||||||
if (excel) {
|
if (excel) {
|
||||||
|
// BestResultsExcel excel(score, models, datasets, ranksModels, table, friedman, significance);
|
||||||
BestResultsExcel excel(score, models, datasets, table, friedman, significance);
|
BestResultsExcel excel(score, models, datasets, table, friedman, significance);
|
||||||
excel.build();
|
excel.build();
|
||||||
cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl;
|
cout << Colors::YELLOW() << "** Excel file generated: " << excel.getFileName() << Colors::RESET() << endl;
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#include "Statistics.h"
|
#include "Statistics.h"
|
||||||
|
|
||||||
namespace platform {
|
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());
|
workbook = workbook_new((Paths::excel() + fileName).c_str());
|
||||||
worksheet = workbook_add_worksheet(workbook, "Best Results");
|
worksheet = workbook_add_worksheet(workbook, "Best Results");
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define BESTRESULTS_EXCEL_H
|
#define BESTRESULTS_EXCEL_H
|
||||||
#include "ExcelFile.h"
|
#include "ExcelFile.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -11,7 +12,7 @@ namespace platform {
|
|||||||
|
|
||||||
class BestResultsExcel : ExcelFile {
|
class BestResultsExcel : ExcelFile {
|
||||||
public:
|
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();
|
~BestResultsExcel();
|
||||||
void build();
|
void build();
|
||||||
string getFileName();
|
string getFileName();
|
||||||
@ -21,14 +22,15 @@ namespace platform {
|
|||||||
void footer();
|
void footer();
|
||||||
void formatColumns();
|
void formatColumns();
|
||||||
const string fileName = "BestResults.xlsx";
|
const string fileName = "BestResults.xlsx";
|
||||||
string score;
|
const string& score;
|
||||||
vector<string> models;
|
const vector<string>& models;
|
||||||
vector<string> datasets;
|
const vector<string>& datasets;
|
||||||
json table;
|
const json& table;
|
||||||
bool friedman;
|
bool friedman;
|
||||||
double significance;
|
double significance;
|
||||||
int modelNameSize = 12; // Min size of the column
|
int modelNameSize = 12; // Min size of the column
|
||||||
int datasetNameSize = 25; // Min size of the column
|
int datasetNameSize = 25; // Min size of the column
|
||||||
|
// map<string, map<string, float>>& ranksModels;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //BESTRESULTS_EXCEL_H
|
#endif //BESTRESULTS_EXCEL_H
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace platform {
|
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)
|
models(models), datasets(datasets), data(data), significance(significance), output(output)
|
||||||
{
|
{
|
||||||
nModels = models.size();
|
nModels = models.size();
|
||||||
@ -21,6 +21,7 @@ namespace platform {
|
|||||||
cerr << "nDatasets: " << nDatasets << endl;
|
cerr << "nDatasets: " << nDatasets << endl;
|
||||||
throw runtime_error("Can't make the Friedman test with less than 3 models and/or less than 3 datasets.");
|
throw runtime_error("Can't make the Friedman test with less than 3 models and/or less than 3 datasets.");
|
||||||
}
|
}
|
||||||
|
ranksModels.clear();
|
||||||
computeRanks();
|
computeRanks();
|
||||||
// Set the control model as the one with the lowest average rank
|
// 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; }));
|
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
|
// Assign the ranks
|
||||||
ranksLine = assignRanks(ranksOrder);
|
ranksLine = assignRanks(ranksOrder);
|
||||||
|
// Store the ranks of the dataset
|
||||||
|
ranksModels[dataset] = ranksLine;
|
||||||
if (ranks.size() == 0) {
|
if (ranks.size() == 0) {
|
||||||
ranks = ranksLine;
|
ranks = ranksLine;
|
||||||
} else {
|
} else {
|
||||||
@ -239,4 +242,8 @@ namespace platform {
|
|||||||
{
|
{
|
||||||
return holmResult;
|
return holmResult;
|
||||||
}
|
}
|
||||||
|
map<string, map<string, float>>& Statistics::getRanks()
|
||||||
|
{
|
||||||
|
return ranksModels;
|
||||||
|
}
|
||||||
} // namespace platform
|
} // namespace platform
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define STATISTICS_H
|
#define STATISTICS_H
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -32,18 +33,19 @@ namespace platform {
|
|||||||
};
|
};
|
||||||
class Statistics {
|
class Statistics {
|
||||||
public:
|
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();
|
bool friedmanTest();
|
||||||
void postHocHolmTest(bool friedmanResult);
|
void postHocHolmTest(bool friedmanResult);
|
||||||
FriedmanResult& getFriedmanResult();
|
FriedmanResult& getFriedmanResult();
|
||||||
HolmResult& getHolmResult();
|
HolmResult& getHolmResult();
|
||||||
|
map<string, map<string, float>>& getRanks();
|
||||||
private:
|
private:
|
||||||
void fit();
|
void fit();
|
||||||
void computeRanks();
|
void computeRanks();
|
||||||
void computeWTL();
|
void computeWTL();
|
||||||
vector<string> models;
|
const vector<string>& models;
|
||||||
vector<string> datasets;
|
const vector<string>& datasets;
|
||||||
json data;
|
const json& data;
|
||||||
double significance;
|
double significance;
|
||||||
bool output;
|
bool output;
|
||||||
bool fitted = false;
|
bool fitted = false;
|
||||||
@ -56,6 +58,7 @@ namespace platform {
|
|||||||
int maxDatasetName = 0;
|
int maxDatasetName = 0;
|
||||||
FriedmanResult friedmanResult;
|
FriedmanResult friedmanResult;
|
||||||
HolmResult holmResult;
|
HolmResult holmResult;
|
||||||
|
map<string, map<string, float>> ranksModels;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // !STATISTICS_H
|
#endif // !STATISTICS_H
|
Loading…
Reference in New Issue
Block a user