Add report output to main
This commit is contained in:
parent
7f45495837
commit
506ef34c6f
@ -35,7 +35,6 @@ namespace bayesnet {
|
||||
}
|
||||
// 2. Compute class conditional mutual information I(Xi;XjIC), f or each
|
||||
auto conditionalEdgeWeights = metrics.conditionalEdge();
|
||||
cout << "Conditional edge weights: " << conditionalEdgeWeights << endl;
|
||||
// 3. Let the used variable list, S, be empty.
|
||||
vector<int> S;
|
||||
// 4. Let the DAG network being constructed, BN, begin with a single
|
||||
|
@ -4,5 +4,5 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/Files)
|
||||
include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp)
|
||||
include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include)
|
||||
include_directories(${BayesNet_SOURCE_DIR}/lib/json/include)
|
||||
add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc)
|
||||
add_executable(main main.cc Folding.cc platformUtils.cc Experiment.cc Datasets.cc Models.cc Report.cc)
|
||||
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
@ -1,6 +1,7 @@
|
||||
#include "Experiment.h"
|
||||
#include "Datasets.h"
|
||||
#include "Models.h"
|
||||
#include "Report.h"
|
||||
|
||||
namespace platform {
|
||||
using json = nlohmann::json;
|
||||
@ -86,6 +87,13 @@ namespace platform {
|
||||
file.close();
|
||||
}
|
||||
|
||||
void Experiment::report()
|
||||
{
|
||||
json data = build_json();
|
||||
Report report(data);
|
||||
report.show();
|
||||
}
|
||||
|
||||
void Experiment::show()
|
||||
{
|
||||
json data = build_json();
|
||||
|
@ -108,6 +108,7 @@ namespace platform {
|
||||
void cross_validation(const string& path, const string& fileName);
|
||||
void go(vector<string> filesToProcess, const string& path);
|
||||
void show();
|
||||
void report();
|
||||
};
|
||||
}
|
||||
#endif
|
66
src/Platform/Report.cc
Normal file
66
src/Platform/Report.cc
Normal file
@ -0,0 +1,66 @@
|
||||
#include "Report.h"
|
||||
|
||||
namespace platform {
|
||||
string headerLine(const string& text)
|
||||
{
|
||||
int n = MAXL - text.length() - 3;
|
||||
return "* " + text + string(n, ' ') + "*\n";
|
||||
}
|
||||
string Report::fromVector(const string& key)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
for (auto& item : data[key]) {
|
||||
result += to_string(item) + ", ";
|
||||
}
|
||||
return "[" + result.substr(0, result.length() - 2) + "]";
|
||||
}
|
||||
string fVector(const json& data)
|
||||
{
|
||||
string result = "";
|
||||
for (const auto& item : data) {
|
||||
result += to_string(item) + ", ";
|
||||
}
|
||||
return "[" + result.substr(0, result.length() - 2) + "]";
|
||||
}
|
||||
void Report::show()
|
||||
{
|
||||
header();
|
||||
body();
|
||||
}
|
||||
void Report::header()
|
||||
{
|
||||
cout << string(MAXL, '*') << 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"));
|
||||
cout << headerLine("Execution took " + to_string(data["duration"].get<float>()) + " seconds, " + to_string(data["duration"].get<float>() / 3600) + " hours, on " + data["platform"].get<string>());
|
||||
cout << headerLine("Score is " + data["score_name"].get<string>());
|
||||
cout << string(MAXL, '*') << endl;
|
||||
cout << endl;
|
||||
}
|
||||
void Report::body()
|
||||
{
|
||||
cout << "Dataset Sampl. Feat. Cls Nodes Edges States Score Time Hyperparameters" << endl;
|
||||
cout << "============================== ====== ===== === ======= ======= ======= =============== ================= ===============" << endl;
|
||||
for (const auto& r : data["results"]) {
|
||||
cout << 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(7) << right << r["nodes"].get<float>() << " ";
|
||||
cout << setw(7) << right << r["leaves"].get<float>() << " ";
|
||||
cout << setw(7) << right << r["depth"].get<float>() << " ";
|
||||
cout << setw(8) << right << setprecision(6) << fixed << r["score_test"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["score_test_std"].get<double>() << " ";
|
||||
cout << setw(10) << right << setprecision(6) << fixed << r["test_time"].get<double>() << "±" << setw(6) << setprecision(4) << fixed << r["test_time_std"].get<double>() << " ";
|
||||
cout << " " << r["hyperparameters"].get<string>();
|
||||
cout << endl;
|
||||
cout << string(MAXL, '*') << endl;
|
||||
cout << headerLine("Train scores: " + fVector(r["scores_train"]));
|
||||
cout << headerLine("Test scores: " + fVector(r["scores_test"]));
|
||||
cout << headerLine("Train times: " + fVector(r["times_train"]));
|
||||
cout << headerLine("Test times: " + fVector(r["times_test"]));
|
||||
cout << string(MAXL, '*') << endl;
|
||||
}
|
||||
}
|
||||
}
|
23
src/Platform/Report.h
Normal file
23
src/Platform/Report.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef REPORT_H
|
||||
#define REPORT_H
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
const int MAXL = 121;
|
||||
namespace platform {
|
||||
using namespace std;
|
||||
class Report {
|
||||
public:
|
||||
explicit Report(json data_) { data = data_; };
|
||||
virtual ~Report() = default;
|
||||
void show();
|
||||
private:
|
||||
void header();
|
||||
void body();
|
||||
string fromVector(const string& key);
|
||||
json data;
|
||||
};
|
||||
};
|
||||
#endif
|
@ -116,7 +116,7 @@ int main(int argc, char** argv)
|
||||
if (saveResults)
|
||||
experiment.save(PATH_RESULTS);
|
||||
else
|
||||
experiment.show();
|
||||
experiment.report();
|
||||
cout << "Done!" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user