#include #include #include "Report.h" #include "BestResult.h" namespace platform { string headerLine(const string& text) { int n = MAXL - text.length() - 3; n = n < 0 ? 0 : n; return "* " + text + string(n, ' ') + "*\n"; } string Report::fromVector(const string& key) { stringstream oss; string sep = ""; oss << "[" << fixed << setprecision(16); for (auto& item : data[key]) { oss << sep << item.get(); sep = ", "; } oss << "]"; return oss.str(); } string fVector(const string& title, const json& data) { stringstream oss; string sep = ""; oss << title << "[" << fixed << setprecision(16); for (const auto& item : data) { oss << sep << item.get(); sep = ", "; } oss << "]"; return oss.str(); } void Report::show() { header(); body(); footer(); } struct separated : numpunct { char do_decimal_point() const { return ','; } char do_thousands_sep() const { return '.'; } string do_grouping() const { return "\03"; } }; void Report::header() { locale mylocale(cout.getloc(), new separated); locale::global(mylocale); cout.imbue(mylocale); stringstream oss; cout << Colors::MAGENTA() << string(MAXL, '*') << endl; cout << headerLine("Report " + data["model"].get() + " ver. " + data["version"].get() + " with " + to_string(data["folds"].get()) + " Folds cross validation and " + to_string(data["seeds"].size()) + " random seeds. " + data["date"].get() + " " + data["time"].get()); cout << headerLine(data["title"].get()); cout << headerLine("Random seeds: " + fromVector("seeds") + " Stratified: " + (data["stratified"].get() ? "True" : "False")); oss << "Execution took " << setprecision(2) << fixed << data["duration"].get() << " seconds, " << data["duration"].get() / 3600 << " hours, on " << data["platform"].get(); cout << headerLine(oss.str()); cout << headerLine("Score is " + data["score_name"].get()); cout << string(MAXL, '*') << endl; cout << endl; } void Report::body() { cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl; cout << "============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl; json lastResult; totalScore = 0; bool odd = true; for (const auto& r : data["results"]) { auto color = odd ? Colors::CYAN() : Colors::BLUE(); cout << color << setw(30) << left << r["dataset"].get() << " "; cout << setw(6) << right << r["samples"].get() << " "; cout << setw(5) << right << r["features"].get() << " "; cout << setw(3) << right << r["classes"].get() << " "; cout << setw(9) << setprecision(2) << fixed << r["nodes"].get() << " "; cout << setw(9) << setprecision(2) << fixed << r["leaves"].get() << " "; cout << setw(9) << setprecision(2) << fixed << r["depth"].get() << " "; cout << setw(8) << right << setprecision(6) << fixed << r["score"].get() << "±" << setw(6) << setprecision(4) << fixed << r["score_std"].get() << " "; cout << setw(11) << right << setprecision(6) << fixed << r["time"].get() << "±" << setw(6) << setprecision(4) << fixed << r["time_std"].get() << " "; try { cout << r["hyperparameters"].get(); } catch (const exception& err) { cout << r["hyperparameters"]; } cout << endl; lastResult = r; totalScore += r["score"].get(); odd = !odd; } if (data["results"].size() == 1) { cout << string(MAXL, '*') << endl; cout << headerLine(fVector("Train scores: ", lastResult["scores_train"])); cout << headerLine(fVector("Test scores: ", lastResult["scores_test"])); cout << headerLine(fVector("Train times: ", lastResult["times_train"])); cout << headerLine(fVector("Test times: ", lastResult["times_test"])); cout << string(MAXL, '*') << endl; } } void Report::footer() { cout << Colors::MAGENTA() << string(MAXL, '*') << endl; auto score = data["score_name"].get(); if (score == BestResult::scoreName()) { stringstream oss; oss << score << " compared to " << BestResult::title() << " .: " << totalScore / BestResult::score(); cout << headerLine(oss.str()); } cout << string(MAXL, '*') << endl << Colors::RESET(); } }