Compare commits

..

4 Commits

45 changed files with 148 additions and 108 deletions

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef PLATFORM_H
#define PLATFORM_H
#include <string> #include <string>
#include <string_view> #include <string_view>
@@ -8,3 +8,4 @@ static constexpr std::string_view platform_project_version = "@PROJECT_VERSION@"
static constexpr std::string_view platform_project_description = "@PROJECT_DESCRIPTION@"; static constexpr std::string_view platform_project_description = "@PROJECT_DESCRIPTION@";
static constexpr std::string_view platform_git_sha = "@GIT_SHA@"; static constexpr std::string_view platform_git_sha = "@GIT_SHA@";
static constexpr std::string_view platform_data_path = "@Platform_SOURCE_DIR@/tests/data/"; static constexpr std::string_view platform_data_path = "@Platform_SOURCE_DIR@/tests/data/";
#endif

View File

@@ -1,9 +1,10 @@
#pragma once #ifndef BESTRESULTS_H
#define BESTRESULTS_H
#include <string> #include <string>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::ordered_json;
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class BestResults { class BestResults {
public: public:
explicit BestResults(const std::string& path, const std::string& score, const std::string& model, const std::string& dataset, bool friedman, double significance = 0.05) explicit BestResults(const std::string& path, const std::string& score, const std::string& model, const std::string& dataset, bool friedman, double significance = 0.05)
@@ -34,3 +35,4 @@ namespace platform {
int maxDatasetName = 0; int maxDatasetName = 0;
}; };
} }
#endif

View File

@@ -1,14 +1,13 @@
#pragma once #ifndef BESTRESULTSEXCEL_H
#define BESTRESULTSEXCEL_H
#include <vector> #include <vector>
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "reports/ExcelFile.h" #include "reports/ExcelFile.h"
using json = nlohmann::ordered_json;
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class BestResultsExcel : public ExcelFile { class BestResultsExcel : public ExcelFile {
public: public:
BestResultsExcel(const std::string& score, const std::vector<std::string>& datasets); BestResultsExcel(const std::string& score, const std::vector<std::string>& datasets);
@@ -34,3 +33,4 @@ namespace platform {
int datasetNameSize = 25; // Min size of the column int datasetNameSize = 25; // Min size of the column
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef BESTSCORE_H
#define BESTSCORE_H
#include <string> #include <string>
#include <map> #include <map>
#include <utility> #include <utility>
@@ -24,3 +24,4 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,13 +1,13 @@
#pragma once #ifndef STATISTICS_H
#define STATISTICS_H
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
namespace platform {
using json = nlohmann::ordered_json; using json = nlohmann::ordered_json;
namespace platform {
struct WTL { struct WTL {
int win; int win;
int tie; int tie;
@@ -60,3 +60,4 @@ namespace platform {
std::map<std::string, std::map<std::string, float>> ranksModels; std::map<std::string, std::map<std::string, float>> ranksModels;
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef CLOCALE_H
#define CLOCALE_H
#include <locale> #include <locale>
#include <iostream> #include <iostream>
#include <string> #include <string>
@@ -19,3 +19,4 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef COLORS_H
#define COLORS_H
#include <string> #include <string>
class Colors { class Colors {
public: public:
@@ -27,3 +27,4 @@ public:
static std::string CONCEALED() { return "\033[8m"; } static std::string CONCEALED() { return "\033[8m"; }
static std::string CLRSCR() { return "\033[2J\033[1;1H"; } static std::string CLRSCR() { return "\033[2J\033[1;1H"; }
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef DATASET_H
#define DATASET_H
#include <torch/torch.h> #include <torch/torch.h>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -48,4 +48,4 @@ namespace platform {
std::vector<mdlp::labels_t> discretizeDataset(std::vector<mdlp::samples_t>& X, mdlp::labels_t& y); std::vector<mdlp::labels_t> discretizeDataset(std::vector<mdlp::samples_t>& X, mdlp::labels_t& y);
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef DATASETS_H
#define DATASETS_H
#include "Dataset.h" #include "Dataset.h"
namespace platform { namespace platform {
class Datasets { class Datasets {
@@ -28,3 +28,4 @@ namespace platform {
void load(); // Loads the list of datasets void load(); // Loads the list of datasets
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef DOTENV_H
#define DOTENV_H
#include <string> #include <string>
#include <map> #include <map>
#include <fstream> #include <fstream>
@@ -59,3 +59,4 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef PATHS_H
#define PATHS_H
#include <string> #include <string>
#include <filesystem> #include <filesystem>
#include "DotEnv.h" #include "DotEnv.h"
@@ -36,3 +36,4 @@ namespace platform {
} }
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef SYMBOLS_H
#define SYMBOLS_H
#include <string> #include <string>
namespace platform { namespace platform {
class Symbols { class Symbols {
@@ -17,3 +17,4 @@ namespace platform {
inline static const std::string notebook{ "\U0001F5C8" }; inline static const std::string notebook{ "\U0001F5C8" };
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef TIMER_H
#define TIMER_H
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -40,3 +40,4 @@ namespace platform {
} }
}; };
} /* namespace platform */ } /* namespace platform */
#endif

View File

@@ -1,10 +1,9 @@
#pragma once #ifndef UTILS_H
#define UTILS_H
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
namespace platform { namespace platform {
//static std::vector<std::string> split(const std::string& text, char delimiter);
static std::vector<std::string> split(const std::string& text, char delimiter) static std::vector<std::string> split(const std::string& text, char delimiter)
{ {
std::vector<std::string> result; std::vector<std::string> result;
@@ -27,3 +26,4 @@ namespace platform {
return result; return result;
} }
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef GRIDDATA_H
#define GRIDDATA_H
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -23,3 +23,4 @@ namespace platform {
std::map<std::string, json> grid; std::map<std::string, json> grid;
}; };
} /* namespace platform */ } /* namespace platform */
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef GRIDSEARCH_H
#define GRIDSEARCH_H
#include <string> #include <string>
#include <map> #include <map>
#include <mpi.h> #include <mpi.h>
@@ -57,3 +57,4 @@ namespace platform {
Timer timer; // used to measure the time of the whole process Timer timer; // used to measure the time of the whole process
}; };
} /* namespace platform */ } /* namespace platform */
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef EXPERIMENT_H
#define EXPERIMENT_H
#include <torch/torch.h> #include <torch/torch.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
@@ -43,3 +43,4 @@ namespace platform {
int max_name{ 7 }; // max length of dataset name for formatting (default 7) int max_name{ 7 }; // max length of dataset name for formatting (default 7)
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef HYPERPARAMETERS_H
#define HYPERPARAMETERS_H
#include <string> #include <string>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -20,3 +20,4 @@ namespace platform {
std::map<std::string, json> hyperparameters; std::map<std::string, json> hyperparameters;
}; };
} /* namespace platform */ } /* namespace platform */
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef MODELS_H
#define MODELS_H
#include <map> #include <map>
#include <bayesnet/BaseClassifier.h> #include <bayesnet/BaseClassifier.h>
#include <bayesnet/ensembles/AODE.h> #include <bayesnet/ensembles/AODE.h>
@@ -42,3 +42,4 @@ namespace platform {
Registrar(const std::string& className, function<bayesnet::BaseClassifier* (void)> classFactoryFunction); Registrar(const std::string& className, function<bayesnet::BaseClassifier* (void)> classFactoryFunction);
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef PARTIAL_RESULT_H
#define PARTIAL_RESULT_H
#include <string> #include <string>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -73,3 +73,4 @@ namespace platform {
json data; json data;
}; };
} }
#endif

View File

@@ -40,6 +40,15 @@ namespace platform {
} }
compute_accuracy_value(); compute_accuracy_value();
} }
Scores Scores::create_aggregate(json& data, std::string key)
{
auto scores = Scores(data[key][0]);
for (int i = 1; i < data[key].size(); i++) {
auto score = Scores(data[key][i]);
scores.aggregate(score);
}
return scores;
}
void Scores::compute_accuracy_value() void Scores::compute_accuracy_value()
{ {
accuracy_value = 0; accuracy_value = 0;

View File

@@ -2,14 +2,17 @@
#define SCORES_H #define SCORES_H
#include <vector> #include <vector>
#include <string> #include <string>
#include <torch/torch.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <torch/torch.h>
#include <xlsxwriter.h>
namespace platform { namespace platform {
using json = nlohmann::ordered_json; using json = nlohmann::ordered_json;
class Scores { class Scores {
public: public:
Scores(torch::Tensor& y_test, torch::Tensor& y_pred, int num_classes, std::vector<std::string> labels = {}); Scores(torch::Tensor& y_test, torch::Tensor& y_pred, int num_classes, std::vector<std::string> labels = {});
explicit Scores(json& confusion_matrix_); explicit Scores(json& confusion_matrix_);
static Scores create_aggregate(json& data, std::string key);
float accuracy(); float accuracy();
float f1_score(int num_class); float f1_score(int num_class);
float f1_weighted(); float f1_weighted();

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef MODELREGISTER_H
#define MODELREGISTER_H
static platform::Registrar registrarT("TAN", static platform::Registrar registrarT("TAN",
[](void) -> bayesnet::BaseClassifier* { return new bayesnet::TAN();}); [](void) -> bayesnet::BaseClassifier* { return new bayesnet::TAN();});
@@ -34,3 +35,5 @@ static platform::Registrar registrarRaF("RandomForest",
[](void) -> bayesnet::BaseClassifier* { return new pywrap::RandomForest();}); [](void) -> bayesnet::BaseClassifier* { return new pywrap::RandomForest();});
static platform::Registrar registrarXGB("XGBoost", static platform::Registrar registrarXGB("XGBoost",
[](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();}); [](void) -> bayesnet::BaseClassifier* { return new pywrap::XGBoost();});
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef COMMAND_PARSER_H
#define COMMAND_PARSER_H
#include <string> #include <string>
#include <vector> #include <vector>
#include <tuple> #include <tuple>
@@ -18,3 +18,4 @@ namespace platform {
int index; int index;
}; };
} /* namespace platform */ } /* namespace platform */
#endif

View File

@@ -254,7 +254,7 @@ namespace platform {
while (!finished) { while (!finished) {
std::cout << color << "Really want to " << intent << " " << fileName << "? (y/n): "; std::cout << color << "Really want to " << intent << " " << fileName << "? (y/n): ";
getline(std::cin, line); getline(std::cin, line);
finished = line.size() == 1 && (tolower(line[0]) == 'y' || tolower(line[0] == 'n')); finished = line.size() == 1 && (tolower(line[0]) == 'y' || tolower(line[0]) == 'n');
} }
if (tolower(line[0]) == 'y') { if (tolower(line[0]) == 'y') {
return true; return true;

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef MANAGE_SCREEN_H
#define MANAGE_SCREEN_H
#include <xlsxwriter.h> #include <xlsxwriter.h>
#include "ResultsManager.h" #include "ResultsManager.h"
#include "Paginator.hpp" #include "Paginator.hpp"
@@ -50,3 +50,4 @@ namespace platform {
lxw_workbook* workbook; lxw_workbook* workbook;
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef PAGINATOR_HPP
#define PAGINATOR_HPP
#include <utility> #include <utility>
class Paginator { class Paginator {
@@ -54,3 +54,4 @@ private:
int page; int page;
int numPages; int numPages;
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef RESULTSMANAGER_H
#define RESULTSMANAGER_H
#include <vector> #include <vector>
#include <string> #include <string>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -46,3 +46,4 @@ namespace platform {
std::vector<Result> files; std::vector<Result> files;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef DATASETSCONSOLE_H
#define DATASETSCONSOLE_H
#include <locale> #include <locale>
#include <sstream> #include <sstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -8,7 +8,6 @@
namespace platform { namespace platform {
using json = nlohmann::ordered_json; using json = nlohmann::ordered_json;
class DatasetsConsole : public ReportsPaged { class DatasetsConsole : public ReportsPaged {
public: public:
static const int BALANCE_LENGTH; static const int BALANCE_LENGTH;
@@ -19,4 +18,4 @@ namespace platform {
void split_lines(int name_len, std::string line, const std::string& balance); void split_lines(int name_len, std::string line, const std::string& balance);
}; };
} }
#endif

View File

@@ -1,5 +1,4 @@
#include "DatasetsExcel.h" #include "DatasetsExcel.h"
namespace platform { namespace platform {
DatasetsExcel::DatasetsExcel() DatasetsExcel::DatasetsExcel()
{ {

View File

@@ -1,12 +1,11 @@
#pragma once #ifndef DATASETSEXCEL_H
#define DATASETSEXCEL_H
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "reports/ExcelFile.h" #include "reports/ExcelFile.h"
using json = nlohmann::ordered_json;
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class DatasetsExcel : public ExcelFile { class DatasetsExcel : public ExcelFile {
public: public:
DatasetsExcel(); DatasetsExcel();
@@ -14,3 +13,4 @@ namespace platform {
void report(json& data); void report(json& data);
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef EXCELFILE_H
#define EXCELFILE_H
#include <locale> #include <locale>
#include <string> #include <string>
#include <map> #include <map>
@@ -39,3 +39,4 @@ namespace platform {
void setDefault(); void setDefault();
}; };
} }
#endif

View File

@@ -1,14 +1,13 @@
#pragma once #ifndef REPORTBASE_H
#define REPORTBASE_H
#include <string> #include <string>
#include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "common/Paths.h" #include "common/Paths.h"
#include "common/Symbols.h" #include "common/Symbols.h"
using json = nlohmann::ordered_json;
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class ReportBase { class ReportBase {
public: public:
explicit ReportBase(json data_, bool compare); explicit ReportBase(json data_, bool compare);
@@ -36,3 +35,4 @@ namespace platform {
bool existBestFile = true; bool existBestFile = true;
}; };
}; };
#endif

View File

@@ -186,13 +186,13 @@ namespace platform {
int lines_header = 0; int lines_header = 0;
std::string color_line; std::string color_line;
std::string suffix = ""; std::string suffix = "";
auto scores = aggregateScore(result, "confusion_matrices"); auto scores = Scores::create_aggregate(result, "confusion_matrices");
auto output_test = scores.classification_report(color, "Test"); auto output_test = scores.classification_report(color, "Test");
int maxLine = (*std::max_element(output_test.begin(), output_test.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size(); int maxLine = (*std::max_element(output_test.begin(), output_test.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })).size();
bool train_data = result.find("confusion_matrices_train") != result.end(); bool train_data = result.find("confusion_matrices_train") != result.end();
std::vector<std::string> output_train; std::vector<std::string> output_train;
if (train_data) { if (train_data) {
auto scores_train = aggregateScore(result, "confusion_matrices_train"); auto scores_train = Scores::create_aggregate(result, "confusion_matrices_train");
output_train = scores_train.classification_report(color, "Train"); output_train = scores_train.classification_report(color, "Train");
} }
oss << Colors::BLUE(); oss << Colors::BLUE();

View File

@@ -1,12 +1,11 @@
#pragma once #ifndef REPORT_CONSOLE_H
#define REPORT_CONSOLE_H
#include <string> #include <string>
#include "common/Colors.h" #include "common/Colors.h"
#include <sstream> #include <sstream>
#include "ReportBase.h" #include "ReportBase.h"
#include "main/Scores.h" #include "main/Scores.h"
namespace platform { namespace platform {
const int MAXL = 133; const int MAXL = 133;
class ReportConsole : public ReportBase { class ReportConsole : public ReportBase {
@@ -33,3 +32,4 @@ namespace platform {
std::vector<std::string> vbody; std::vector<std::string> vbody;
}; };
}; };
#endif

View File

@@ -2,8 +2,6 @@
#include <locale> #include <locale>
#include "best/BestScore.h" #include "best/BestScore.h"
#include "ReportExcel.h" #include "ReportExcel.h"
namespace platform { namespace platform {
ReportExcel::ReportExcel(json data_, bool compare, lxw_workbook* workbook, lxw_worksheet* worksheet) : ReportBase(data_, compare), ExcelFile(workbook, worksheet) ReportExcel::ReportExcel(json data_, bool compare, lxw_workbook* workbook, lxw_worksheet* worksheet) : ReportBase(data_, compare), ExcelFile(workbook, worksheet)

View File

@@ -1,11 +1,13 @@
#pragma once #ifndef REPORT_EXCEL_H
#define REPORT_EXCEL_H
#include <map> #include <map>
#include <xlsxwriter.h> #include <xlsxwriter.h>
#include "common/Colors.h" #include "common/Colors.h"
#include "ReportBase.h" #include "ReportBase.h"
#include "ExcelFile.h" #include "ExcelFile.h"
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class ReportExcel : public ReportBase, public ExcelFile { class ReportExcel : public ReportBase, public ExcelFile {
public: public:
explicit ReportExcel(json data_, bool compare, lxw_workbook* workbook, lxw_worksheet* worksheet = NULL); explicit ReportExcel(json data_, bool compare, lxw_workbook* workbook, lxw_worksheet* worksheet = NULL);
@@ -22,3 +24,4 @@ namespace platform {
void header_notes(int row); void header_notes(int row);
}; };
}; };
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef REPORT_EXCEL_COMPARED_H
#define REPORT_EXCEL_COMPARED_H
#include "ReportExcel.h" #include "ReportExcel.h"
namespace platform { namespace platform {
class ReportExcelCompared : public ExcelFile { class ReportExcelCompared : public ExcelFile {
@@ -17,3 +18,4 @@ namespace platform {
std::string depth_label; std::string depth_label;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef REPORTS_PAGED_H
#define REPORTS_PAGED_H
#include <locale> #include <locale>
#include <sstream> #include <sstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -23,3 +23,4 @@ namespace platform {
std::locale loc; std::locale loc;
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef RESULTSDATASETSCONSOLE_H
#define RESULTSDATASETSCONSOLE_H
#include <locale> #include <locale>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -15,7 +15,4 @@ namespace platform {
bool report(const std::string& dataset, const std::string& score, const std::string& model); bool report(const std::string& dataset, const std::string& score, const std::string& model);
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef RESULT_H
#define RESULT_H
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
@@ -51,3 +51,4 @@ namespace platform {
double score = 0.0; double score = 0.0;
}; };
}; };
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef RESULTSDATASET_H
#define RESULTSDATASET_H
#include <vector> #include <vector>
#include <string> #include <string>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -32,3 +32,4 @@ namespace platform {
std::vector<Result> files; std::vector<Result> files;
}; };
}; };
#endif

View File

@@ -1,11 +1,11 @@
#pragma once #ifndef RESULTSDATASETEXCEL_H
#define RESULTSDATASETEXCEL_H
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "reports/ExcelFile.h" #include "reports/ExcelFile.h"
using json = nlohmann::ordered_json;
namespace platform { namespace platform {
using json = nlohmann::ordered_json;
class ResultsDatasetExcel : public ExcelFile { class ResultsDatasetExcel : public ExcelFile {
public: public:
@@ -14,3 +14,4 @@ namespace platform {
void report(json& data); void report(json& data);
}; };
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef TESTUTILS_H
#define TESTUTILS_H
#include <torch/torch.h> #include <torch/torch.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -39,4 +39,4 @@ public:
int nSamples, classNumStates; int nSamples, classNumStates;
double epsilon = 1e-5; double epsilon = 1e-5;
}; };
#endif