Begin BestResults build
This commit is contained in:
68
src/Platform/BestResults.cc
Normal file
68
src/Platform/BestResults.cc
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "platformUtils.h"
|
||||
#include "BestResults.h"
|
||||
#include "Results.h"
|
||||
#include "Colors.h"
|
||||
|
||||
namespace platform {
|
||||
|
||||
void BestResults::build()
|
||||
{
|
||||
auto files = loadFiles();
|
||||
if (files.size() == 0) {
|
||||
throw runtime_error("No result files were found!");
|
||||
}
|
||||
json bests;
|
||||
for (const auto& file : files) {
|
||||
auto result = Result(path, file);
|
||||
auto data = result.load();
|
||||
for (auto const& item : data.at("results")) {
|
||||
bool update = false;
|
||||
if (bests.contains(item.at("dataset").get<string>())) {
|
||||
if (item.at("score").get<double>() > bests["dataset"].at(0).get<double>()) {
|
||||
update = true;
|
||||
}
|
||||
} else {
|
||||
update = true;
|
||||
}
|
||||
if (update) {
|
||||
bests[item.at("dataset").get<string>()] = { item.at("score").get<double>(), item.at("hyperparameters"), file };
|
||||
}
|
||||
}
|
||||
}
|
||||
string bestFileName = path + "/" + bestResultFile();
|
||||
if (file_exists(bestFileName)) {
|
||||
cout << Colors::MAGENTA() << "File " << bestFileName << " already exists and it shall be overwritten." << Colors::RESET();
|
||||
}
|
||||
ofstream file(bestFileName);
|
||||
file << bests;
|
||||
file.close();
|
||||
}
|
||||
|
||||
string BestResults::bestResultFile()
|
||||
{
|
||||
return "best_results_" + score + "_" + model + ".json";
|
||||
}
|
||||
|
||||
vector<string> BestResults::loadFiles()
|
||||
{
|
||||
vector<string> files;
|
||||
using std::filesystem::directory_iterator;
|
||||
for (const auto& file : directory_iterator(path)) {
|
||||
auto fileName = file.path().filename().string();
|
||||
if (fileName.find(".json") != string::npos && fileName.find("results_") == 0
|
||||
&& fileName.find("_" + score + "_") != string::npos
|
||||
&& fileName.find("_" + model + "_") != string::npos) {
|
||||
files.push_back(fileName);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
void BestResults::report()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
20
src/Platform/BestResults.h
Normal file
20
src/Platform/BestResults.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef BESTRESULTS_H
|
||||
#define BESTRESULTS_H
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
namespace platform {
|
||||
class BestResults {
|
||||
public:
|
||||
explicit BestResults(const string& path, const string& score, const string& model) : path(path), score(score), model(model) {}
|
||||
void build();
|
||||
void report();
|
||||
private:
|
||||
vector<string> loadFiles();
|
||||
string bestResultFile();
|
||||
string path;
|
||||
string score;
|
||||
string model;
|
||||
};
|
||||
}
|
||||
#endif //BESTRESULTS_H
|
@@ -8,11 +8,13 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/libxlsxwriter/include)
|
||||
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 ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc platformUtils.cc)
|
||||
add_executable(list list.cc platformUtils Datasets.cc)
|
||||
add_executable(best list.cc platformUtils Datasets.cc)
|
||||
add_executable(best best.cc BestResults.cc Results.cc ReportBase.cc ReportExcel.cc platformUtils.cc)
|
||||
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
||||
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
|
||||
target_link_libraries(manage "${TORCH_LIBRARIES}" libxlsxwriter.so ArffFiles mdlp stdc++fs)
|
||||
target_link_libraries(best "${TORCH_LIBRARIES}" libxlsxwriter.so stdc++fs)
|
||||
else()
|
||||
target_link_libraries(manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
||||
target_link_libraries(best "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}")
|
||||
endif()
|
||||
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
@@ -1,31 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <argparse/argparse.hpp>
|
||||
#include "platformUtils.h"
|
||||
#include "Paths.h"
|
||||
#include "Results.h"
|
||||
#include "BestResults.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
argparse::ArgumentParser manageArguments(int argc, char** argv)
|
||||
{
|
||||
argparse::ArgumentParser program("best");
|
||||
program.add_argument("-n", "--number").default_value(0).help("Number of results to show (0 = all)").scan<'i', int>();
|
||||
program.add_argument("-m", "--model").default_value("any").help("Filter results of the selected model)");
|
||||
program.add_argument("-s", "--score").default_value("any").help("Filter results of the score name supplied");
|
||||
program.add_argument("--complete").help("Show only results with all datasets").default_value(false).implicit_value(true);
|
||||
program.add_argument("--partial").help("Show only partial results").default_value(false).implicit_value(true);
|
||||
program.add_argument("--compare").help("Compare with best results").default_value(false).implicit_value(true);
|
||||
program.add_argument("--build").help("build best score results file").default_value(false).implicit_value(true);
|
||||
program.add_argument("--report").help("report of best score results file").default_value(false).implicit_value(true);
|
||||
try {
|
||||
program.parse_args(argc, argv);
|
||||
auto number = program.get<int>("number");
|
||||
if (number < 0) {
|
||||
throw runtime_error("Number of results must be greater than or equal to 0");
|
||||
}
|
||||
auto model = program.get<string>("model");
|
||||
auto score = program.get<string>("score");
|
||||
auto complete = program.get<bool>("complete");
|
||||
auto partial = program.get<bool>("partial");
|
||||
auto compare = program.get<bool>("compare");
|
||||
auto build = program.get<bool>("build");
|
||||
auto report = program.get<bool>("report");
|
||||
}
|
||||
catch (const exception& err) {
|
||||
cerr << err.what() << endl;
|
||||
@@ -38,15 +30,20 @@ argparse::ArgumentParser manageArguments(int argc, char** argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto program = manageArguments(argc, argv);
|
||||
auto number = program.get<int>("number");
|
||||
auto model = program.get<string>("model");
|
||||
auto score = program.get<string>("score");
|
||||
auto complete = program.get<bool>("complete");
|
||||
auto partial = program.get<bool>("partial");
|
||||
auto compare = program.get<bool>("compare");
|
||||
if (complete)
|
||||
partial = false;
|
||||
auto results = platform::Results(platform::Paths::results(), number, model, score, complete, partial, compare);
|
||||
results.manage();
|
||||
auto build = program.get<bool>("build");
|
||||
auto report = program.get<bool>("report");
|
||||
if (!report && !build) {
|
||||
cout << "Either build, report or both, have to be selected to do anything!" << endl;
|
||||
exit(1);
|
||||
}
|
||||
auto results = platform::BestResults(platform::Paths::results(), model, score);
|
||||
if (build) {
|
||||
results.build();
|
||||
}
|
||||
if (report) {
|
||||
results.report();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include "ArffFiles.h"
|
||||
#include "CPPFImdlp.h"
|
||||
using namespace std;
|
||||
const string PATH = "../../data/";
|
||||
|
||||
bool file_exists(const std::string& name);
|
||||
vector<string> split(const string& text, char delimiter);
|
||||
|
Reference in New Issue
Block a user