Continue TeX output
This commit is contained in:
85
src/best/BestResultsTex.cpp
Normal file
85
src/best/BestResultsTex.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include <iostream>
|
||||
#include "BestResultsTex.h"
|
||||
#include "common/Utils.h" // compute_std
|
||||
|
||||
namespace platform {
|
||||
using json = nlohmann::ordered_json;
|
||||
BestResultsTex::BestResultsTex(const std::vector<std::string>& models, const std::string& date) : models(models), date(date)
|
||||
{
|
||||
}
|
||||
void BestResultsTex::results_header()
|
||||
{
|
||||
auto file_name = Paths::tex() + Paths::tex_output();
|
||||
output_tex = fopen(file_name.c_str(), "w");
|
||||
if (output_tex == NULL) {
|
||||
std::cerr << "Error opening file " << file_name << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
fprintf(output_tex, "%% This file has been generated by the platform program\n");
|
||||
fprintf(output_tex, "%% Date: %s\n", date.c_str());
|
||||
fprintf(output_tex, "%%\n");
|
||||
fprintf(output_tex, "%% Table of results\n");
|
||||
fprintf(output_tex, "%%\n");
|
||||
fprintf(output_tex, "\\begin{table}[htbp] \n");
|
||||
fprintf(output_tex, "\\centering \n");
|
||||
fprintf(output_tex, "\\tiny \n");
|
||||
fprintf(output_tex, "\\renewcommand{\\arraystretch }{1.2} \n");
|
||||
fprintf(output_tex, "\\renewcommand{\\tabcolsep }{0.07cm} \n");
|
||||
fprintf(output_tex, "\\caption{Accuracy results(mean ± std) for all the algorithms and datasets} \n");
|
||||
fprintf(output_tex, "\\label{tab:results_accuracy}\n");
|
||||
fprintf(output_tex, "\\begin{tabular} {{r%s}}\n", std::string(models.size(), 'c').c_str());
|
||||
fprintf(output_tex, "\\hline \n");
|
||||
fprintf(output_tex, "Id");
|
||||
for (const auto& model : models) {
|
||||
fprintf(output_tex, "& %s ", model.c_str());
|
||||
}
|
||||
fprintf(output_tex, "\\\\ \n");
|
||||
fprintf(output_tex, "\\hline \n");
|
||||
}
|
||||
void BestResultsTex::results_body(const std::vector<std::string>& datasets, json& table)
|
||||
{
|
||||
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 {
|
||||
value = table[model].at(dataset).at(0).get<double>();
|
||||
}
|
||||
catch (nlohmann::json_abi_v3_11_3::detail::out_of_range err) {
|
||||
value = -1.0;
|
||||
}
|
||||
if (value > max_value) {
|
||||
max_value = value;
|
||||
}
|
||||
}
|
||||
fprintf(output_tex, "%d ", i);
|
||||
for (const auto& model : models) {
|
||||
double value = table[model].at(dataset).at(0).get<double>();
|
||||
double std_value = table[model].at(dataset).at(3).get<double>();
|
||||
const char* bold = value == max_value ? "\\bfseries" : "";
|
||||
fprintf(output_tex, "& %s %0.4f±%0.3f", bold, value, std_value);
|
||||
}
|
||||
fprintf(output_tex, "\\\\\n");
|
||||
}
|
||||
}
|
||||
void BestResultsTex::results_footer(const std::map<std::string, std::vector<double>>& totals, const std::string& best_model)
|
||||
{
|
||||
fprintf(output_tex, "\\hline \n");
|
||||
fprintf(output_tex, "Average ");
|
||||
int nDatasets = totals.begin()->second.size();
|
||||
for (const auto& model : models) {
|
||||
double value = std::reduce(totals.at(model).begin(), totals.at(model).end()) / nDatasets;
|
||||
double std_value = compute_std(totals.at(model), value);
|
||||
const char* bold = model == best_model ? "\\bfseries" : "";
|
||||
fprintf(output_tex, "& %s %0.4f±%0.3f", bold, value, std_value);
|
||||
}
|
||||
fprintf(output_tex, "\\ \n");
|
||||
fprintf(output_tex, "\\hline \n");
|
||||
fprintf(output_tex, "\\end{tabular}\n");
|
||||
fprintf(output_tex, "\\end{table}\n");
|
||||
fclose(output_tex);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user