bestResults #9
7
Makefile
7
Makefile
@ -19,13 +19,14 @@ copy: ## Copy binary files to selected folder
|
|||||||
@cp build/src/Platform/main $(dest)
|
@cp build/src/Platform/main $(dest)
|
||||||
@cp build/src/Platform/list $(dest)
|
@cp build/src/Platform/list $(dest)
|
||||||
@cp build/src/Platform/manage $(dest)
|
@cp build/src/Platform/manage $(dest)
|
||||||
|
@cp build/src/Platform/best $(dest)
|
||||||
@echo ">>> Done"
|
@echo ">>> Done"
|
||||||
|
|
||||||
dependency: ## Create a dependency graph diagram of the project (build/dependency.png)
|
dependency: ## Create a dependency graph diagram of the project (build/dependency.png)
|
||||||
cd build && cmake .. --graphviz=dependency.dot && dot -Tpng dependency.dot -o dependency.png
|
cd build && cmake .. --graphviz=dependency.dot && dot -Tpng dependency.dot -o dependency.png
|
||||||
|
|
||||||
build: ## Build the main and BayesNetSample
|
build: ## Build the main and BayesNetSample
|
||||||
cmake --build build -t main -t BayesNetSample -t manage -t list -j 32
|
cmake --build build -t main -t BayesNetSample -t manage -t list -t best -j 32
|
||||||
|
|
||||||
clean: ## Clean the debug info
|
clean: ## Clean the debug info
|
||||||
@echo ">>> Cleaning Debug BayesNet ...";
|
@echo ">>> Cleaning Debug BayesNet ...";
|
||||||
@ -40,7 +41,7 @@ debug: ## Build a debug version of the project
|
|||||||
@if [ -d ./build ]; then rm -rf ./build; fi
|
@if [ -d ./build ]; then rm -rf ./build; fi
|
||||||
@mkdir build;
|
@mkdir build;
|
||||||
cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON; \
|
cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON; \
|
||||||
cmake --build build -t main -t BayesNetSample -t manage -t list unit_tests -j 32;
|
cmake --build build -t main -t BayesNetSample -t manage -t list -t best -t unit_tests -j 32;
|
||||||
@echo ">>> Done";
|
@echo ">>> Done";
|
||||||
|
|
||||||
release: ## Build a Release version of the project
|
release: ## Build a Release version of the project
|
||||||
@ -48,7 +49,7 @@ release: ## Build a Release version of the project
|
|||||||
@if [ -d ./build ]; then rm -rf ./build; fi
|
@if [ -d ./build ]; then rm -rf ./build; fi
|
||||||
@mkdir build;
|
@mkdir build;
|
||||||
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release; \
|
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release; \
|
||||||
cmake --build build -t main -t BayesNetSample -t manage -t list -j 32;
|
cmake --build build -t main -t BayesNetSample -t manage -t list -t best -j 32;
|
||||||
@echo ">>> Done";
|
@echo ">>> Done";
|
||||||
|
|
||||||
test: ## Run tests
|
test: ## Run tests
|
||||||
|
344
sample/sample.cc
344
sample/sample.cc
@ -104,180 +104,180 @@ int main(int argc, char** argv)
|
|||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
cout << weights_.index({ i }).item<double>() << endl;
|
cout << weights_.index({ i }).item<double>() << endl;
|
||||||
}
|
}
|
||||||
// map<string, bool> datasets = {
|
map<string, bool> datasets = {
|
||||||
// {"diabetes", true},
|
{"diabetes", true},
|
||||||
// {"ecoli", true},
|
{"ecoli", true},
|
||||||
// {"glass", true},
|
{"glass", true},
|
||||||
// {"iris", true},
|
{"iris", true},
|
||||||
// {"kdd_JapaneseVowels", false},
|
{"kdd_JapaneseVowels", false},
|
||||||
// {"letter", true},
|
{"letter", true},
|
||||||
// {"liver-disorders", true},
|
{"liver-disorders", true},
|
||||||
// {"mfeat-factors", true},
|
{"mfeat-factors", true},
|
||||||
// };
|
};
|
||||||
// auto valid_datasets = vector<string>();
|
auto valid_datasets = vector<string>();
|
||||||
// transform(datasets.begin(), datasets.end(), back_inserter(valid_datasets),
|
transform(datasets.begin(), datasets.end(), back_inserter(valid_datasets),
|
||||||
// [](const pair<string, bool>& pair) { return pair.first; });
|
[](const pair<string, bool>& pair) { return pair.first; });
|
||||||
// argparse::ArgumentParser program("BayesNetSample");
|
argparse::ArgumentParser program("BayesNetSample");
|
||||||
// program.add_argument("-d", "--dataset")
|
program.add_argument("-d", "--dataset")
|
||||||
// .help("Dataset file name")
|
.help("Dataset file name")
|
||||||
// .action([valid_datasets](const std::string& value) {
|
.action([valid_datasets](const std::string& value) {
|
||||||
// if (find(valid_datasets.begin(), valid_datasets.end(), value) != valid_datasets.end()) {
|
if (find(valid_datasets.begin(), valid_datasets.end(), value) != valid_datasets.end()) {
|
||||||
// return value;
|
return value;
|
||||||
// }
|
}
|
||||||
// throw runtime_error("file must be one of {diabetes, ecoli, glass, iris, kdd_JapaneseVowels, letter, liver-disorders, mfeat-factors}");
|
throw runtime_error("file must be one of {diabetes, ecoli, glass, iris, kdd_JapaneseVowels, letter, liver-disorders, mfeat-factors}");
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
// program.add_argument("-p", "--path")
|
program.add_argument("-p", "--path")
|
||||||
// .help(" folder where the data files are located, default")
|
.help(" folder where the data files are located, default")
|
||||||
// .default_value(string{ PATH }
|
.default_value(string{ PATH }
|
||||||
// );
|
);
|
||||||
// program.add_argument("-m", "--model")
|
program.add_argument("-m", "--model")
|
||||||
// .help("Model to use " + platform::Models::instance()->toString())
|
.help("Model to use " + platform::Models::instance()->toString())
|
||||||
// .action([](const std::string& value) {
|
.action([](const std::string& value) {
|
||||||
// static const vector<string> choices = platform::Models::instance()->getNames();
|
static const vector<string> choices = platform::Models::instance()->getNames();
|
||||||
// if (find(choices.begin(), choices.end(), value) != choices.end()) {
|
if (find(choices.begin(), choices.end(), value) != choices.end()) {
|
||||||
// return value;
|
return value;
|
||||||
// }
|
}
|
||||||
// throw runtime_error("Model must be one of " + platform::Models::instance()->toString());
|
throw runtime_error("Model must be one of " + platform::Models::instance()->toString());
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
// program.add_argument("--discretize").help("Discretize input dataset").default_value(false).implicit_value(true);
|
program.add_argument("--discretize").help("Discretize input dataset").default_value(false).implicit_value(true);
|
||||||
// program.add_argument("--dumpcpt").help("Dump CPT Tables").default_value(false).implicit_value(true);
|
program.add_argument("--dumpcpt").help("Dump CPT Tables").default_value(false).implicit_value(true);
|
||||||
// program.add_argument("--stratified").help("If Stratified KFold is to be done").default_value(false).implicit_value(true);
|
program.add_argument("--stratified").help("If Stratified KFold is to be done").default_value(false).implicit_value(true);
|
||||||
// program.add_argument("--tensors").help("Use tensors to store samples").default_value(false).implicit_value(true);
|
program.add_argument("--tensors").help("Use tensors to store samples").default_value(false).implicit_value(true);
|
||||||
// program.add_argument("-f", "--folds").help("Number of folds").default_value(5).scan<'i', int>().action([](const string& value) {
|
program.add_argument("-f", "--folds").help("Number of folds").default_value(5).scan<'i', int>().action([](const string& value) {
|
||||||
// try {
|
try {
|
||||||
// auto k = stoi(value);
|
auto k = stoi(value);
|
||||||
// if (k < 2) {
|
if (k < 2) {
|
||||||
// throw runtime_error("Number of folds must be greater than 1");
|
throw runtime_error("Number of folds must be greater than 1");
|
||||||
// }
|
}
|
||||||
// return k;
|
return k;
|
||||||
// }
|
}
|
||||||
// catch (const runtime_error& err) {
|
catch (const runtime_error& err) {
|
||||||
// throw runtime_error(err.what());
|
throw runtime_error(err.what());
|
||||||
// }
|
}
|
||||||
// catch (...) {
|
catch (...) {
|
||||||
// throw runtime_error("Number of folds must be an integer");
|
throw runtime_error("Number of folds must be an integer");
|
||||||
// }});
|
}});
|
||||||
// program.add_argument("-s", "--seed").help("Random seed").default_value(-1).scan<'i', int>();
|
program.add_argument("-s", "--seed").help("Random seed").default_value(-1).scan<'i', int>();
|
||||||
// bool class_last, stratified, tensors, dump_cpt;
|
bool class_last, stratified, tensors, dump_cpt;
|
||||||
// string model_name, file_name, path, complete_file_name;
|
string model_name, file_name, path, complete_file_name;
|
||||||
// int nFolds, seed;
|
int nFolds, seed;
|
||||||
// try {
|
try {
|
||||||
// program.parse_args(argc, argv);
|
program.parse_args(argc, argv);
|
||||||
// file_name = program.get<string>("dataset");
|
file_name = program.get<string>("dataset");
|
||||||
// path = program.get<string>("path");
|
path = program.get<string>("path");
|
||||||
// model_name = program.get<string>("model");
|
model_name = program.get<string>("model");
|
||||||
// complete_file_name = path + file_name + ".arff";
|
complete_file_name = path + file_name + ".arff";
|
||||||
// stratified = program.get<bool>("stratified");
|
stratified = program.get<bool>("stratified");
|
||||||
// tensors = program.get<bool>("tensors");
|
tensors = program.get<bool>("tensors");
|
||||||
// nFolds = program.get<int>("folds");
|
nFolds = program.get<int>("folds");
|
||||||
// seed = program.get<int>("seed");
|
seed = program.get<int>("seed");
|
||||||
// dump_cpt = program.get<bool>("dumpcpt");
|
dump_cpt = program.get<bool>("dumpcpt");
|
||||||
// class_last = datasets[file_name];
|
class_last = datasets[file_name];
|
||||||
// if (!file_exists(complete_file_name)) {
|
if (!file_exists(complete_file_name)) {
|
||||||
// throw runtime_error("Data File " + path + file_name + ".arff" + " does not exist");
|
throw runtime_error("Data File " + path + file_name + ".arff" + " does not exist");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// catch (const exception& err) {
|
catch (const exception& err) {
|
||||||
// cerr << err.what() << endl;
|
cerr << err.what() << endl;
|
||||||
// cerr << program;
|
cerr << program;
|
||||||
// exit(1);
|
exit(1);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Begin Processing
|
* Begin Processing
|
||||||
*/
|
*/
|
||||||
// auto handler = ArffFiles();
|
auto handler = ArffFiles();
|
||||||
// handler.load(complete_file_name, class_last);
|
handler.load(complete_file_name, class_last);
|
||||||
// // Get Dataset X, y
|
// Get Dataset X, y
|
||||||
// vector<mdlp::samples_t>& X = handler.getX();
|
vector<mdlp::samples_t>& X = handler.getX();
|
||||||
// mdlp::labels_t& y = handler.getY();
|
mdlp::labels_t& y = handler.getY();
|
||||||
// // Get className & Features
|
// Get className & Features
|
||||||
// auto className = handler.getClassName();
|
auto className = handler.getClassName();
|
||||||
// vector<string> features;
|
vector<string> features;
|
||||||
// auto attributes = handler.getAttributes();
|
auto attributes = handler.getAttributes();
|
||||||
// transform(attributes.begin(), attributes.end(), back_inserter(features),
|
transform(attributes.begin(), attributes.end(), back_inserter(features),
|
||||||
// [](const pair<string, string>& item) { return item.first; });
|
[](const pair<string, string>& item) { return item.first; });
|
||||||
// // Discretize Dataset
|
// Discretize Dataset
|
||||||
// auto [Xd, maxes] = discretize(X, y, features);
|
auto [Xd, maxes] = discretize(X, y, features);
|
||||||
// maxes[className] = *max_element(y.begin(), y.end()) + 1;
|
maxes[className] = *max_element(y.begin(), y.end()) + 1;
|
||||||
// map<string, vector<int>> states;
|
map<string, vector<int>> states;
|
||||||
// for (auto feature : features) {
|
for (auto feature : features) {
|
||||||
// states[feature] = vector<int>(maxes[feature]);
|
states[feature] = vector<int>(maxes[feature]);
|
||||||
// }
|
}
|
||||||
// states[className] = vector<int>(maxes[className]);
|
states[className] = vector<int>(maxes[className]);
|
||||||
// auto clf = platform::Models::instance()->create(model_name);
|
auto clf = platform::Models::instance()->create(model_name);
|
||||||
// clf->fit(Xd, y, features, className, states);
|
clf->fit(Xd, y, features, className, states);
|
||||||
// if (dump_cpt) {
|
if (dump_cpt) {
|
||||||
// cout << "--- CPT Tables ---" << endl;
|
cout << "--- CPT Tables ---" << endl;
|
||||||
// clf->dump_cpt();
|
clf->dump_cpt();
|
||||||
// }
|
}
|
||||||
// auto lines = clf->show();
|
auto lines = clf->show();
|
||||||
// for (auto line : lines) {
|
for (auto line : lines) {
|
||||||
// cout << line << endl;
|
cout << line << endl;
|
||||||
// }
|
}
|
||||||
// cout << "--- Topological Order ---" << endl;
|
cout << "--- Topological Order ---" << endl;
|
||||||
// auto order = clf->topological_order();
|
auto order = clf->topological_order();
|
||||||
// for (auto name : order) {
|
for (auto name : order) {
|
||||||
// cout << name << ", ";
|
cout << name << ", ";
|
||||||
// }
|
}
|
||||||
// cout << "end." << endl;
|
cout << "end." << endl;
|
||||||
// auto score = clf->score(Xd, y);
|
auto score = clf->score(Xd, y);
|
||||||
// cout << "Score: " << score << endl;
|
cout << "Score: " << score << endl;
|
||||||
// auto graph = clf->graph();
|
auto graph = clf->graph();
|
||||||
// auto dot_file = model_name + "_" + file_name;
|
auto dot_file = model_name + "_" + file_name;
|
||||||
// ofstream file(dot_file + ".dot");
|
ofstream file(dot_file + ".dot");
|
||||||
// file << graph;
|
file << graph;
|
||||||
// file.close();
|
file.close();
|
||||||
// cout << "Graph saved in " << model_name << "_" << file_name << ".dot" << endl;
|
cout << "Graph saved in " << model_name << "_" << file_name << ".dot" << endl;
|
||||||
// cout << "dot -Tpng -o " + dot_file + ".png " + dot_file + ".dot " << endl;
|
cout << "dot -Tpng -o " + dot_file + ".png " + dot_file + ".dot " << endl;
|
||||||
// string stratified_string = stratified ? " Stratified" : "";
|
string stratified_string = stratified ? " Stratified" : "";
|
||||||
// cout << nFolds << " Folds" << stratified_string << " Cross validation" << endl;
|
cout << nFolds << " Folds" << stratified_string << " Cross validation" << endl;
|
||||||
// cout << "==========================================" << endl;
|
cout << "==========================================" << endl;
|
||||||
// torch::Tensor Xt = torch::zeros({ static_cast<int>(Xd.size()), static_cast<int>(Xd[0].size()) }, torch::kInt32);
|
torch::Tensor Xt = torch::zeros({ static_cast<int>(Xd.size()), static_cast<int>(Xd[0].size()) }, torch::kInt32);
|
||||||
// torch::Tensor yt = torch::tensor(y, torch::kInt32);
|
torch::Tensor yt = torch::tensor(y, torch::kInt32);
|
||||||
// for (int i = 0; i < features.size(); ++i) {
|
for (int i = 0; i < features.size(); ++i) {
|
||||||
// Xt.index_put_({ i, "..." }, torch::tensor(Xd[i], torch::kInt32));
|
Xt.index_put_({ i, "..." }, torch::tensor(Xd[i], torch::kInt32));
|
||||||
// }
|
}
|
||||||
// float total_score = 0, total_score_train = 0, score_train, score_test;
|
float total_score = 0, total_score_train = 0, score_train, score_test;
|
||||||
// platform::Fold* fold;
|
platform::Fold* fold;
|
||||||
// if (stratified)
|
if (stratified)
|
||||||
// fold = new platform::StratifiedKFold(nFolds, y, seed);
|
fold = new platform::StratifiedKFold(nFolds, y, seed);
|
||||||
// else
|
else
|
||||||
// fold = new platform::KFold(nFolds, y.size(), seed);
|
fold = new platform::KFold(nFolds, y.size(), seed);
|
||||||
// for (auto i = 0; i < nFolds; ++i) {
|
for (auto i = 0; i < nFolds; ++i) {
|
||||||
// auto [train, test] = fold->getFold(i);
|
auto [train, test] = fold->getFold(i);
|
||||||
// cout << "Fold: " << i + 1 << endl;
|
cout << "Fold: " << i + 1 << endl;
|
||||||
// if (tensors) {
|
if (tensors) {
|
||||||
// auto ttrain = torch::tensor(train, torch::kInt64);
|
auto ttrain = torch::tensor(train, torch::kInt64);
|
||||||
// auto ttest = torch::tensor(test, torch::kInt64);
|
auto ttest = torch::tensor(test, torch::kInt64);
|
||||||
// torch::Tensor Xtraint = torch::index_select(Xt, 1, ttrain);
|
torch::Tensor Xtraint = torch::index_select(Xt, 1, ttrain);
|
||||||
// torch::Tensor ytraint = yt.index({ ttrain });
|
torch::Tensor ytraint = yt.index({ ttrain });
|
||||||
// torch::Tensor Xtestt = torch::index_select(Xt, 1, ttest);
|
torch::Tensor Xtestt = torch::index_select(Xt, 1, ttest);
|
||||||
// torch::Tensor ytestt = yt.index({ ttest });
|
torch::Tensor ytestt = yt.index({ ttest });
|
||||||
// clf->fit(Xtraint, ytraint, features, className, states);
|
clf->fit(Xtraint, ytraint, features, className, states);
|
||||||
// auto temp = clf->predict(Xtraint);
|
auto temp = clf->predict(Xtraint);
|
||||||
// score_train = clf->score(Xtraint, ytraint);
|
score_train = clf->score(Xtraint, ytraint);
|
||||||
// score_test = clf->score(Xtestt, ytestt);
|
score_test = clf->score(Xtestt, ytestt);
|
||||||
// } else {
|
} else {
|
||||||
// auto [Xtrain, ytrain] = extract_indices(train, Xd, y);
|
auto [Xtrain, ytrain] = extract_indices(train, Xd, y);
|
||||||
// auto [Xtest, ytest] = extract_indices(test, Xd, y);
|
auto [Xtest, ytest] = extract_indices(test, Xd, y);
|
||||||
// clf->fit(Xtrain, ytrain, features, className, states);
|
clf->fit(Xtrain, ytrain, features, className, states);
|
||||||
// score_train = clf->score(Xtrain, ytrain);
|
score_train = clf->score(Xtrain, ytrain);
|
||||||
// score_test = clf->score(Xtest, ytest);
|
score_test = clf->score(Xtest, ytest);
|
||||||
// }
|
}
|
||||||
// if (dump_cpt) {
|
if (dump_cpt) {
|
||||||
// cout << "--- CPT Tables ---" << endl;
|
cout << "--- CPT Tables ---" << endl;
|
||||||
// clf->dump_cpt();
|
clf->dump_cpt();
|
||||||
// }
|
}
|
||||||
// total_score_train += score_train;
|
total_score_train += score_train;
|
||||||
// total_score += score_test;
|
total_score += score_test;
|
||||||
// cout << "Score Train: " << score_train << endl;
|
cout << "Score Train: " << score_train << endl;
|
||||||
// cout << "Score Test : " << score_test << endl;
|
cout << "Score Test : " << score_test << endl;
|
||||||
// cout << "-------------------------------------------------------------------------------" << endl;
|
cout << "-------------------------------------------------------------------------------" << endl;
|
||||||
// }
|
}
|
||||||
// cout << "**********************************************************************************" << endl;
|
cout << "**********************************************************************************" << endl;
|
||||||
// cout << "Average Score Train: " << total_score_train / nFolds << endl;
|
cout << "Average Score Train: " << total_score_train / nFolds << endl;
|
||||||
// cout << "Average Score Test : " << total_score / nFolds << endl;return 0;
|
cout << "Average Score Test : " << total_score / nFolds << endl;return 0;
|
||||||
}
|
}
|
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(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(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(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}")
|
target_link_libraries(main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}")
|
||||||
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
|
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
|
||||||
target_link_libraries(manage "${TORCH_LIBRARIES}" libxlsxwriter.so ArffFiles mdlp stdc++fs)
|
target_link_libraries(manage "${TORCH_LIBRARIES}" libxlsxwriter.so ArffFiles mdlp stdc++fs)
|
||||||
|
target_link_libraries(best "${TORCH_LIBRARIES}" libxlsxwriter.so stdc++fs)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
target_link_libraries(manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp)
|
||||||
|
target_link_libraries(best "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}")
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(list ArffFiles mdlp "${TORCH_LIBRARIES}")
|
@ -1,31 +1,23 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
#include "platformUtils.h"
|
|
||||||
#include "Paths.h"
|
#include "Paths.h"
|
||||||
#include "Results.h"
|
#include "BestResults.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
argparse::ArgumentParser manageArguments(int argc, char** argv)
|
argparse::ArgumentParser manageArguments(int argc, char** argv)
|
||||||
{
|
{
|
||||||
argparse::ArgumentParser program("best");
|
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("-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("-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("--build").help("build best score results file").default_value(false).implicit_value(true);
|
||||||
program.add_argument("--partial").help("Show only partial results").default_value(false).implicit_value(true);
|
program.add_argument("--report").help("report of best score results file").default_value(false).implicit_value(true);
|
||||||
program.add_argument("--compare").help("Compare with best results").default_value(false).implicit_value(true);
|
|
||||||
try {
|
try {
|
||||||
program.parse_args(argc, argv);
|
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 model = program.get<string>("model");
|
||||||
auto score = program.get<string>("score");
|
auto score = program.get<string>("score");
|
||||||
auto complete = program.get<bool>("complete");
|
auto build = program.get<bool>("build");
|
||||||
auto partial = program.get<bool>("partial");
|
auto report = program.get<bool>("report");
|
||||||
auto compare = program.get<bool>("compare");
|
|
||||||
}
|
}
|
||||||
catch (const exception& err) {
|
catch (const exception& err) {
|
||||||
cerr << err.what() << endl;
|
cerr << err.what() << endl;
|
||||||
@ -38,15 +30,20 @@ argparse::ArgumentParser manageArguments(int argc, char** argv)
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto program = manageArguments(argc, argv);
|
auto program = manageArguments(argc, argv);
|
||||||
auto number = program.get<int>("number");
|
|
||||||
auto model = program.get<string>("model");
|
auto model = program.get<string>("model");
|
||||||
auto score = program.get<string>("score");
|
auto score = program.get<string>("score");
|
||||||
auto complete = program.get<bool>("complete");
|
auto build = program.get<bool>("build");
|
||||||
auto partial = program.get<bool>("partial");
|
auto report = program.get<bool>("report");
|
||||||
auto compare = program.get<bool>("compare");
|
if (!report && !build) {
|
||||||
if (complete)
|
cout << "Either build, report or both, have to be selected to do anything!" << endl;
|
||||||
partial = false;
|
exit(1);
|
||||||
auto results = platform::Results(platform::Paths::results(), number, model, score, complete, partial, compare);
|
}
|
||||||
results.manage();
|
auto results = platform::BestResults(platform::Paths::results(), model, score);
|
||||||
|
if (build) {
|
||||||
|
results.build();
|
||||||
|
}
|
||||||
|
if (report) {
|
||||||
|
results.report();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include "ArffFiles.h"
|
#include "ArffFiles.h"
|
||||||
#include "CPPFImdlp.h"
|
#include "CPPFImdlp.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const string PATH = "../../data/";
|
|
||||||
|
|
||||||
bool file_exists(const std::string& name);
|
bool file_exists(const std::string& name);
|
||||||
vector<string> split(const string& text, char delimiter);
|
vector<string> split(const string& text, char delimiter);
|
||||||
|
Loading…
Reference in New Issue
Block a user