Compare commits
4 Commits
2b7353b9e0
...
d2da0ddb88
Author | SHA1 | Date | |
---|---|---|---|
d2da0ddb88
|
|||
8066701c3c
|
|||
0f66ac73d0
|
|||
4370bf51d7
|
@@ -55,6 +55,7 @@ endif (ENABLE_CLANG_TIDY)
|
|||||||
add_git_submodule("lib/mdlp")
|
add_git_submodule("lib/mdlp")
|
||||||
add_git_submodule("lib/argparse")
|
add_git_submodule("lib/argparse")
|
||||||
add_git_submodule("lib/json")
|
add_git_submodule("lib/json")
|
||||||
|
add_git_submodule("lib/openXLSX")
|
||||||
|
|
||||||
# Subdirectories
|
# Subdirectories
|
||||||
# --------------
|
# --------------
|
||||||
|
1
lib/openXLSX
Submodule
1
lib/openXLSX
Submodule
Submodule lib/openXLSX added at b80da42d14
@@ -4,9 +4,9 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/Files)
|
|||||||
include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp)
|
include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp)
|
||||||
include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include)
|
include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include)
|
||||||
include_directories(${BayesNet_SOURCE_DIR}/lib/json/include)
|
include_directories(${BayesNet_SOURCE_DIR}/lib/json/include)
|
||||||
add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc Report.cc)
|
add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc ReportConsole.cc ReportBase.cc)
|
||||||
add_executable(manage manage.cc Results.cc Report.cc)
|
add_executable(manage manage.cc Results.cc ReportConsole.cc ReportExcel.cc ReportBase.cc)
|
||||||
add_executable(list list.cc platformUtils Datasets.cc)
|
add_executable(list list.cc platformUtils Datasets.cc)
|
||||||
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
||||||
target_link_libraries(manage "${TORCH_LIBRARIES}")
|
target_link_libraries(manage "${TORCH_LIBRARIES}" OpenXLSX::OpenXLSX)
|
||||||
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
@@ -1,7 +1,7 @@
|
|||||||
#include "Experiment.h"
|
#include "Experiment.h"
|
||||||
#include "Datasets.h"
|
#include "Datasets.h"
|
||||||
#include "Models.h"
|
#include "Models.h"
|
||||||
#include "Report.h"
|
#include "ReportConsole.h"
|
||||||
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@@ -91,7 +91,7 @@ namespace platform {
|
|||||||
void Experiment::report()
|
void Experiment::report()
|
||||||
{
|
{
|
||||||
json data = build_json();
|
json data = build_json();
|
||||||
Report report(data);
|
ReportConsole report(data);
|
||||||
report.show();
|
report.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,26 +0,0 @@
|
|||||||
#ifndef REPORT_H
|
|
||||||
#define REPORT_H
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "Colors.h"
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
const int MAXL = 128;
|
|
||||||
namespace platform {
|
|
||||||
using namespace std;
|
|
||||||
class Report {
|
|
||||||
public:
|
|
||||||
explicit Report(json data_) { data = data_; };
|
|
||||||
virtual ~Report() = default;
|
|
||||||
void show();
|
|
||||||
private:
|
|
||||||
void header();
|
|
||||||
void body();
|
|
||||||
void footer();
|
|
||||||
string fromVector(const string& key);
|
|
||||||
json data;
|
|
||||||
double totalScore; // Total score of all results in a report
|
|
||||||
};
|
|
||||||
};
|
|
||||||
#endif
|
|
38
src/Platform/ReportBase.cc
Normal file
38
src/Platform/ReportBase.cc
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include <sstream>
|
||||||
|
#include <locale>
|
||||||
|
#include "ReportBase.h"
|
||||||
|
#include "BestResult.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace platform {
|
||||||
|
string ReportBase::fromVector(const string& key)
|
||||||
|
{
|
||||||
|
stringstream oss;
|
||||||
|
string sep = "";
|
||||||
|
oss << "[";
|
||||||
|
for (auto& item : data[key]) {
|
||||||
|
oss << sep << item.get<double>();
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
oss << "]";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
string ReportBase::fVector(const string& title, const json& data, const int width, const int precision)
|
||||||
|
{
|
||||||
|
stringstream oss;
|
||||||
|
string sep = "";
|
||||||
|
oss << title << "[";
|
||||||
|
for (const auto& item : data) {
|
||||||
|
oss << sep << fixed << setw(width) << setprecision(precision) << item.get<double>();
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
oss << "]";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
void ReportBase::show()
|
||||||
|
{
|
||||||
|
header();
|
||||||
|
body();
|
||||||
|
footer();
|
||||||
|
}
|
||||||
|
}
|
25
src/Platform/ReportBase.h
Normal file
25
src/Platform/ReportBase.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef REPORTBASE_H
|
||||||
|
#define REPORTBASE_H
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
namespace platform {
|
||||||
|
using namespace std;
|
||||||
|
class ReportBase {
|
||||||
|
public:
|
||||||
|
explicit ReportBase(json data_) { data = data_; };
|
||||||
|
virtual ~ReportBase() = default;
|
||||||
|
void show();
|
||||||
|
protected:
|
||||||
|
json data;
|
||||||
|
double totalScore; // Total score of all results in a report
|
||||||
|
string fromVector(const string& key);
|
||||||
|
string fVector(const string& title, const json& data, const int width, const int precision);
|
||||||
|
virtual void header() = 0;
|
||||||
|
virtual void body() = 0;
|
||||||
|
virtual void footer() = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
#endif
|
@@ -1,52 +1,23 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include "Report.h"
|
#include "ReportConsole.h"
|
||||||
#include "BestResult.h"
|
#include "BestResult.h"
|
||||||
|
|
||||||
|
|
||||||
namespace platform {
|
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 << "[";
|
|
||||||
for (auto& item : data[key]) {
|
|
||||||
oss << sep << item.get<double>();
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
oss << "]";
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
string fVector(const string& title, const json& data, const int width, const int precision)
|
|
||||||
{
|
|
||||||
stringstream oss;
|
|
||||||
string sep = "";
|
|
||||||
oss << title << "[";
|
|
||||||
for (const auto& item : data) {
|
|
||||||
oss << sep << fixed << setw(width) << setprecision(precision) << item.get<double>();
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
oss << "]";
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
void Report::show()
|
|
||||||
{
|
|
||||||
header();
|
|
||||||
body();
|
|
||||||
footer();
|
|
||||||
}
|
|
||||||
struct separated : numpunct<char> {
|
struct separated : numpunct<char> {
|
||||||
char do_decimal_point() const { return ','; }
|
char do_decimal_point() const { return ','; }
|
||||||
char do_thousands_sep() const { return '.'; }
|
char do_thousands_sep() const { return '.'; }
|
||||||
string do_grouping() const { return "\03"; }
|
string do_grouping() const { return "\03"; }
|
||||||
};
|
};
|
||||||
void Report::header()
|
string ReportConsole::headerLine(const string& text)
|
||||||
|
{
|
||||||
|
int n = MAXL - text.length() - 3;
|
||||||
|
n = n < 0 ? 0 : n;
|
||||||
|
return "* " + text + string(n, ' ') + "*\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportConsole::header()
|
||||||
{
|
{
|
||||||
locale mylocale(cout.getloc(), new separated);
|
locale mylocale(cout.getloc(), new separated);
|
||||||
locale::global(mylocale);
|
locale::global(mylocale);
|
||||||
@@ -62,7 +33,7 @@ namespace platform {
|
|||||||
cout << string(MAXL, '*') << endl;
|
cout << string(MAXL, '*') << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
void Report::body()
|
void ReportConsole::body()
|
||||||
{
|
{
|
||||||
cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl;
|
cout << Colors::GREEN() << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl;
|
||||||
cout << "============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl;
|
cout << "============================== ====== ===== === ========= ========= ========= =============== ================== ===============" << endl;
|
||||||
@@ -100,7 +71,7 @@ namespace platform {
|
|||||||
cout << string(MAXL, '*') << endl;
|
cout << string(MAXL, '*') << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Report::footer()
|
void ReportConsole::footer()
|
||||||
{
|
{
|
||||||
cout << Colors::MAGENTA() << string(MAXL, '*') << endl;
|
cout << Colors::MAGENTA() << string(MAXL, '*') << endl;
|
||||||
auto score = data["score_name"].get<string>();
|
auto score = data["score_name"].get<string>();
|
||||||
@@ -110,6 +81,5 @@ namespace platform {
|
|||||||
cout << headerLine(oss.str());
|
cout << headerLine(oss.str());
|
||||||
}
|
}
|
||||||
cout << string(MAXL, '*') << endl << Colors::RESET();
|
cout << string(MAXL, '*') << endl << Colors::RESET();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
22
src/Platform/ReportConsole.h
Normal file
22
src/Platform/ReportConsole.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef REPORTCONSOLE_H
|
||||||
|
#define REPORTCONSOLE_H
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include "ReportBase.h"
|
||||||
|
#include "Colors.h"
|
||||||
|
|
||||||
|
namespace platform {
|
||||||
|
using namespace std;
|
||||||
|
const int MAXL = 128;
|
||||||
|
class ReportConsole : public ReportBase{
|
||||||
|
public:
|
||||||
|
explicit ReportConsole(json data_) : ReportBase(data_) {};
|
||||||
|
virtual ~ReportConsole() = default;
|
||||||
|
private:
|
||||||
|
string headerLine(const string& text);
|
||||||
|
void header() override;
|
||||||
|
void body() override;
|
||||||
|
void footer() override;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
#endif
|
85
src/Platform/ReportExcel.cc
Normal file
85
src/Platform/ReportExcel.cc
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include <sstream>
|
||||||
|
#include <locale>
|
||||||
|
#include "ReportExcel.h"
|
||||||
|
#include "BestResult.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace platform {
|
||||||
|
struct separated : numpunct<char> {
|
||||||
|
char do_decimal_point() const { return ','; }
|
||||||
|
char do_thousands_sep() const { return '.'; }
|
||||||
|
string do_grouping() const { return "\03"; }
|
||||||
|
};
|
||||||
|
string headerLine(const string& text)
|
||||||
|
{
|
||||||
|
int n = MAXLL - text.length() - 3;
|
||||||
|
n = n < 0 ? 0 : n;
|
||||||
|
return "* " + text + string(n, ' ') + "*\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportExcel::header()
|
||||||
|
{
|
||||||
|
locale mylocale(cout.getloc(), new separated);
|
||||||
|
locale::global(mylocale);
|
||||||
|
cout.imbue(mylocale);
|
||||||
|
stringstream oss;
|
||||||
|
cout << Colors::MAGENTA() << string(MAXLL, '*') << endl;
|
||||||
|
cout << headerLine("Report " + data["model"].get<string>() + " ver. " + data["version"].get<string>() + " with " + to_string(data["folds"].get<int>()) + " Folds cross validation and " + to_string(data["seeds"].size()) + " random seeds. " + data["date"].get<string>() + " " + data["time"].get<string>());
|
||||||
|
cout << headerLine(data["title"].get<string>());
|
||||||
|
cout << headerLine("Random seeds: " + fromVector("seeds") + " Stratified: " + (data["stratified"].get<bool>() ? "True" : "False"));
|
||||||
|
oss << "Execution took " << setprecision(2) << fixed << data["duration"].get<float>() << " seconds, " << data["duration"].get<float>() / 3600 << " hours, on " << data["platform"].get<string>();
|
||||||
|
cout << headerLine(oss.str());
|
||||||
|
cout << headerLine("Score is " + data["score_name"].get<string>());
|
||||||
|
cout << string(MAXLL, '*') << endl;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
void ReportExcel::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<string>() << " ";
|
||||||
|
cout << setw(6) << right << r["samples"].get<int>() << " ";
|
||||||
|
cout << setw(5) << right << r["features"].get<int>() << " ";
|
||||||
|
cout << setw(3) << right << r["classes"].get<int>() << " ";
|
||||||
|
cout << setw(9) << setprecision(2) << fixed << r["nodes"].get<float>() << " ";
|
||||||
|
cout << setw(9) << setprecision(2) << fixed << r["leaves"].get<float>() << " ";
|
||||||
|
cout << setw(9) << setprecision(2) << fixed << r["depth"].get<float>() << " ";
|
||||||
|
cout << setw(8) << right << setprecision(6) << fixed << r["score"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["score_std"].get<double>() << " ";
|
||||||
|
cout << setw(11) << right << setprecision(6) << fixed << r["time"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["time_std"].get<double>() << " ";
|
||||||
|
try {
|
||||||
|
cout << r["hyperparameters"].get<string>();
|
||||||
|
}
|
||||||
|
catch (const exception& err) {
|
||||||
|
cout << r["hyperparameters"];
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
lastResult = r;
|
||||||
|
totalScore += r["score"].get<double>();
|
||||||
|
odd = !odd;
|
||||||
|
}
|
||||||
|
if (data["results"].size() == 1) {
|
||||||
|
cout << string(MAXLL, '*') << endl;
|
||||||
|
cout << headerLine(fVector("Train scores: ", lastResult["scores_train"], 14, 12));
|
||||||
|
cout << headerLine(fVector("Test scores: ", lastResult["scores_test"], 14, 12));
|
||||||
|
cout << headerLine(fVector("Train times: ", lastResult["times_train"], 10, 3));
|
||||||
|
cout << headerLine(fVector("Test times: ", lastResult["times_test"], 10, 3));
|
||||||
|
cout << string(MAXLL, '*') << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ReportExcel::footer()
|
||||||
|
{
|
||||||
|
cout << Colors::MAGENTA() << string(MAXLL, '*') << endl;
|
||||||
|
auto score = data["score_name"].get<string>();
|
||||||
|
if (score == BestResult::scoreName()) {
|
||||||
|
stringstream oss;
|
||||||
|
oss << score << " compared to " << BestResult::title() << " .: " << totalScore / BestResult::score();
|
||||||
|
cout << headerLine(oss.str());
|
||||||
|
}
|
||||||
|
cout << string(MAXLL, '*') << endl << Colors::RESET();
|
||||||
|
}
|
||||||
|
}
|
18
src/Platform/ReportExcel.h
Normal file
18
src/Platform/ReportExcel.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef REPORTEXCEL_H
|
||||||
|
#define REPORTEXCEL_H
|
||||||
|
#include "ReportBase.h"
|
||||||
|
#include "Colors.h"
|
||||||
|
namespace platform {
|
||||||
|
using namespace std;
|
||||||
|
const int MAXLL = 128;
|
||||||
|
class ReportExcel : public ReportBase{
|
||||||
|
public:
|
||||||
|
explicit ReportExcel(json data_) : ReportBase(data_) {};
|
||||||
|
virtual ~ReportExcel() = default;
|
||||||
|
private:
|
||||||
|
void header() override;
|
||||||
|
void body() override;
|
||||||
|
void footer() override;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
#endif // !REPORTEXCEL_H
|
@@ -1,7 +1,8 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "platformUtils.h"
|
#include "platformUtils.h"
|
||||||
#include "Results.h"
|
#include "Results.h"
|
||||||
#include "Report.h"
|
#include "ReportConsole.h"
|
||||||
|
#include "ReportExcel.h"
|
||||||
#include "BestResult.h"
|
#include "BestResult.h"
|
||||||
#include "Colors.h"
|
#include "Colors.h"
|
||||||
namespace platform {
|
namespace platform {
|
||||||
@@ -94,21 +95,26 @@ namespace platform {
|
|||||||
cout << "Invalid index" << endl;
|
cout << "Invalid index" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
void Results::report(const int index) const
|
void Results::report(const int index, const bool excelReport) const
|
||||||
{
|
{
|
||||||
cout << Colors::YELLOW() << "Reporting " << files.at(index).getFilename() << endl;
|
cout << Colors::YELLOW() << "Reporting " << files.at(index).getFilename() << endl;
|
||||||
auto data = files.at(index).load();
|
auto data = files.at(index).load();
|
||||||
Report report(data);
|
if (excelReport) {
|
||||||
report.show();
|
ReportExcel report(data);
|
||||||
|
report.show();
|
||||||
|
} else {
|
||||||
|
ReportConsole report(data);
|
||||||
|
report.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void Results::menu()
|
void Results::menu()
|
||||||
{
|
{
|
||||||
char option;
|
char option;
|
||||||
int index;
|
int index;
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
string filename, line, options = "qldhsr";
|
string filename, line, options = "qldhsre";
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
cout << Colors::RESET() << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r'): ";
|
cout << Colors::RESET() << "Choose option (quit='q', list='l', delete='d', hide='h', sort='s', report='r', excel='e'): ";
|
||||||
getline(cin, line);
|
getline(cin, line);
|
||||||
if (line.size() == 0)
|
if (line.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -119,12 +125,14 @@ namespace platform {
|
|||||||
}
|
}
|
||||||
option = line[0];
|
option = line[0];
|
||||||
} else {
|
} else {
|
||||||
index = stoi(line);
|
if (all_of(line.begin(), line.end(), ::isdigit)) {
|
||||||
if (index >= 0 && index < files.size()) {
|
index = stoi(line);
|
||||||
report(index);
|
if (index >= 0 && index < files.size()) {
|
||||||
} else {
|
report(index, false);
|
||||||
cout << "Invalid option" << endl;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cout << "Invalid option" << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@@ -164,7 +172,13 @@ namespace platform {
|
|||||||
index = getIndex("report");
|
index = getIndex("report");
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
break;
|
break;
|
||||||
report(index);
|
report(index, false);
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
index = getIndex("excel");
|
||||||
|
if (index == -1)
|
||||||
|
break;
|
||||||
|
report(index, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Invalid option" << endl;
|
cout << "Invalid option" << endl;
|
||||||
|
@@ -42,7 +42,7 @@ namespace platform {
|
|||||||
vector<Result> files;
|
vector<Result> files;
|
||||||
void load(); // Loads the list of results
|
void load(); // Loads the list of results
|
||||||
void show() const;
|
void show() const;
|
||||||
void report(const int index) const;
|
void report(const int index, const bool excelReport) const;
|
||||||
int getIndex(const string& intent) const;
|
int getIndex(const string& intent) const;
|
||||||
void menu();
|
void menu();
|
||||||
void sortList();
|
void sortList();
|
||||||
|
Reference in New Issue
Block a user