diff --git a/src/best/BestResults.cpp b/src/best/BestResults.cpp index 208fef6..09a2cf3 100644 --- a/src/best/BestResults.cpp +++ b/src/best/BestResults.cpp @@ -215,7 +215,7 @@ namespace platform { return table; } - void BestResults::printTableResults(std::vector models, json table, bool tex) + void BestResults::printTableResults(std::vector models, json table, bool tex, bool index) { std::stringstream oss; oss << Colors::GREEN() << "Best results for " << score << " as of " << table.at("dateTable").get() << std::endl; @@ -225,7 +225,7 @@ namespace platform { auto bestResultsTex = BestResultsTex(); auto bestResultsMd = BestResultsMd(); if (tex) { - bestResultsTex.results_header(models, table.at("dateTable").get()); + bestResultsTex.results_header(models, table.at("dateTable").get(), index); bestResultsMd.results_header(models, table.at("dateTable").get()); } for (const auto& model : models) { @@ -242,7 +242,7 @@ namespace platform { int nDatasets = table.begin().value().size(); auto datasets = getDatasets(table.begin().value()); if (tex) { - bestResultsTex.results_body(datasets, table); + bestResultsTex.results_body(datasets, table, index); bestResultsMd.results_body(datasets, table); } for (auto const& dataset_ : datasets) { @@ -326,14 +326,14 @@ namespace platform { messageOutputFile("Excel", excel_report.getFileName()); } } - void BestResults::reportAll(bool excel, bool tex) + void BestResults::reportAll(bool excel, bool tex, bool index) { auto models = getModels(); // Build the table of results json table = buildTableResults(models); std::vector datasets = getDatasets(table.begin().value()); // Print the table of results - printTableResults(models, table, tex); + printTableResults(models, table, tex, index); // Compute the Friedman test std::map> ranksModels; if (friedman) { diff --git a/src/best/BestResults.h b/src/best/BestResults.h index 6ecee03..fde6a74 100644 --- a/src/best/BestResults.h +++ b/src/best/BestResults.h @@ -13,7 +13,7 @@ namespace platform { } std::string build(); void reportSingle(bool excel); - void reportAll(bool excel, bool tex); + void reportAll(bool excel, bool tex, bool index); void buildAll(); private: std::vector getModels(); @@ -21,7 +21,7 @@ namespace platform { std::vector loadResultFiles(); void messageOutputFile(const std::string& title, const std::string& fileName); json buildTableResults(std::vector models); - void printTableResults(std::vector models, json table, bool tex); + void printTableResults(std::vector models, json table, bool tex, bool index); json loadFile(const std::string& fileName); void listFile(); std::string path; diff --git a/src/best/BestResultsTex.cpp b/src/best/BestResultsTex.cpp index fe21f18..bf74c88 100644 --- a/src/best/BestResultsTex.cpp +++ b/src/best/BestResultsTex.cpp @@ -12,7 +12,7 @@ namespace platform { exit(1); } } - void BestResultsTex::results_header(const std::vector& models, const std::string& date) + void BestResultsTex::results_header(const std::vector& models, const std::string& date, bool index) { this->models = models; auto file_name = Paths::tex() + Paths::tex_output(); @@ -29,7 +29,8 @@ namespace platform { handler << "\\renewcommand{\\tabcolsep }{0.07cm} " << std::endl; handler << "\\caption{Accuracy results(mean $\\pm$ std) for all the algorithms and datasets} " << std::endl; handler << "\\label{tab:results_accuracy}" << std::endl; - handler << "\\begin{tabular} {{r" << std::string(models.size(), 'c').c_str() << "}}" << std::endl; + std::string header_dataset_name = index ? "r" : "l"; + handler << "\\begin{tabular} {{" << header_dataset_name << std::string(models.size(), 'c').c_str() << "}}" << std::endl; handler << "\\hline " << std::endl; handler << "" << std::endl; for (const auto& model : models) { @@ -38,13 +39,12 @@ namespace platform { handler << "\\\\" << std::endl; handler << "\\hline" << std::endl; } - void BestResultsTex::results_body(const std::vector& datasets, json& table) + void BestResultsTex::results_body(const std::vector& datasets, json& table, bool index) { int i = 0; for (auto const& dataset : datasets) { // Find out max value for this dataset double max_value = 0; - // Find out the max value for this dataset for (const auto& model : models) { double value; try { @@ -57,7 +57,10 @@ namespace platform { max_value = value; } } - handler << ++i << " "; + if (index) + handler << ++i << " "; + else + handler << dataset << " "; for (const auto& model : models) { double value = table[model].at(dataset).at(0).get(); double std_value = table[model].at(dataset).at(3).get(); diff --git a/src/best/BestResultsTex.h b/src/best/BestResultsTex.h index 860e3e0..ae88c6d 100644 --- a/src/best/BestResultsTex.h +++ b/src/best/BestResultsTex.h @@ -9,13 +9,14 @@ namespace platform { using json = nlohmann::ordered_json; class BestResultsTex { public: - BestResultsTex() = default; + BestResultsTex(bool dataset_name = true) : dataset_name(dataset_name) {}; ~BestResultsTex() = default; - void results_header(const std::vector& models, const std::string& date); - void results_body(const std::vector& datasets, json& table); + void results_header(const std::vector& models, const std::string& date, bool index); + void results_body(const std::vector& datasets, json& table, bool index); void results_footer(const std::map>& totals, const std::string& best_model); void holm_test(struct HolmResult& holmResult, const std::string& date); private: + bool dataset_name; void openTexFile(const std::string& name); std::ofstream handler; std::vector models; diff --git a/src/commands/b_best.cpp b/src/commands/b_best.cpp index f884baf..39ec19a 100644 --- a/src/commands/b_best.cpp +++ b/src/commands/b_best.cpp @@ -16,7 +16,8 @@ void manageArguments(argparse::ArgumentParser& program) program.add_argument("-s", "--score").default_value("accuracy").help("Filter results of the score name supplied"); program.add_argument("--friedman").help("Friedman test").default_value(false).implicit_value(true); program.add_argument("--excel").help("Output to excel").default_value(false).implicit_value(true); - program.add_argument("--tex").help("Output result table to TeX file").default_value(false).implicit_value(true); + program.add_argument("--tex").help("Output results to TeX & Markdown files").default_value(false).implicit_value(true); + program.add_argument("--index").help("In tex output show the index of the dataset instead of the name to save space").default_value(false).implicit_value(true); program.add_argument("--level").help("significance level").default_value(0.05).scan<'g', double>().action([](const std::string& value) { try { auto k = std::stod(value); @@ -38,7 +39,7 @@ int main(int argc, char** argv) argparse::ArgumentParser program("b_best", { platform_project_version.begin(), platform_project_version.end() }); manageArguments(program); std::string model, dataset, score; - bool build, report, friedman, excel, tex; + bool build, report, friedman, excel, tex, index; double level; try { program.parse_args(argc, argv); @@ -48,6 +49,7 @@ int main(int argc, char** argv) friedman = program.get("friedman"); excel = program.get("excel"); tex = program.get("tex"); + index = program.get("index"); level = program.get("level"); if (model == "" || score == "") { throw std::runtime_error("Model and score name must be supplied"); @@ -67,7 +69,7 @@ int main(int argc, char** argv) auto results = platform::BestResults(platform::Paths::results(), score, model, dataset, friedman, level); if (model == "any") { results.buildAll(); - results.reportAll(excel, tex); + results.reportAll(excel, tex, index); } else { std::string fileName = results.build(); std::cout << Colors::GREEN() << fileName << " created!" << Colors::RESET() << std::endl;