From 6660e8b6ced56e2238c4d0d88dea62938956b8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Wed, 10 Jan 2024 12:31:22 +0100 Subject: [PATCH] Separate commands from modules in folders --- CMakeLists.txt | 1 + sample/CMakeLists.txt | 2 +- src/Platform/CMakeLists.txt | 20 ++++-- src/Platform/{ => modules}/BestResults.cc | 0 src/Platform/{ => modules}/BestResults.h | 0 .../{ => modules}/BestResultsExcel.cc | 0 src/Platform/{ => modules}/BestResultsExcel.h | 0 src/Platform/{ => modules}/BestScore.h | 0 src/Platform/{ => modules}/CLocale.h | 0 src/Platform/{ => modules}/Colors.h | 0 src/Platform/{ => modules}/CommandParser.cc | 0 src/Platform/{ => modules}/CommandParser.h | 0 src/Platform/{ => modules}/Dataset.cc | 0 src/Platform/{ => modules}/Dataset.h | 0 src/Platform/{ => modules}/Datasets.cc | 0 src/Platform/{ => modules}/Datasets.h | 0 src/Platform/{ => modules}/DotEnv.h | 0 src/Platform/{ => modules}/ExcelFile.cc | 0 src/Platform/{ => modules}/ExcelFile.h | 0 src/Platform/{ => modules}/Experiment.cc | 0 src/Platform/{ => modules}/Experiment.h | 0 src/Platform/{ => modules}/GridData.cc | 0 src/Platform/{ => modules}/GridData.h | 0 src/Platform/{ => modules}/GridSearch.cc | 0 src/Platform/{ => modules}/GridSearch.h | 0 src/Platform/{ => modules}/HyperParameters.cc | 0 src/Platform/{ => modules}/HyperParameters.h | 0 src/Platform/{ => modules}/ManageResults.cc | 0 src/Platform/{ => modules}/ManageResults.h | 0 src/Platform/{ => modules}/Models.cc | 0 src/Platform/{ => modules}/Models.h | 0 src/Platform/{ => modules}/Paths.h | 0 src/Platform/{ => modules}/ReportBase.cc | 0 src/Platform/{ => modules}/ReportBase.h | 0 src/Platform/{ => modules}/ReportConsole.cc | 0 src/Platform/{ => modules}/ReportConsole.h | 0 src/Platform/{ => modules}/ReportExcel.cc | 0 src/Platform/{ => modules}/ReportExcel.h | 0 src/Platform/{ => modules}/Result.cc | 0 src/Platform/{ => modules}/Result.h | 0 src/Platform/{ => modules}/Results.cc | 0 src/Platform/{ => modules}/Results.h | 0 src/Platform/{ => modules}/Statistics.cc | 0 src/Platform/{ => modules}/Statistics.h | 0 src/Platform/{ => modules}/Symbols.h | 0 src/Platform/{ => modules}/Timer.h | 0 src/Platform/{ => modules}/Utils.h | 0 src/Platform/{ => modules}/modelRegister.h | 0 tests/CMakeLists.txt | 2 +- tests/TestPlatform.cc | 70 +++++++++++++++++++ 50 files changed, 87 insertions(+), 8 deletions(-) rename src/Platform/{ => modules}/BestResults.cc (100%) rename src/Platform/{ => modules}/BestResults.h (100%) rename src/Platform/{ => modules}/BestResultsExcel.cc (100%) rename src/Platform/{ => modules}/BestResultsExcel.h (100%) rename src/Platform/{ => modules}/BestScore.h (100%) rename src/Platform/{ => modules}/CLocale.h (100%) rename src/Platform/{ => modules}/Colors.h (100%) rename src/Platform/{ => modules}/CommandParser.cc (100%) rename src/Platform/{ => modules}/CommandParser.h (100%) rename src/Platform/{ => modules}/Dataset.cc (100%) rename src/Platform/{ => modules}/Dataset.h (100%) rename src/Platform/{ => modules}/Datasets.cc (100%) rename src/Platform/{ => modules}/Datasets.h (100%) rename src/Platform/{ => modules}/DotEnv.h (100%) rename src/Platform/{ => modules}/ExcelFile.cc (100%) rename src/Platform/{ => modules}/ExcelFile.h (100%) rename src/Platform/{ => modules}/Experiment.cc (100%) rename src/Platform/{ => modules}/Experiment.h (100%) rename src/Platform/{ => modules}/GridData.cc (100%) rename src/Platform/{ => modules}/GridData.h (100%) rename src/Platform/{ => modules}/GridSearch.cc (100%) rename src/Platform/{ => modules}/GridSearch.h (100%) rename src/Platform/{ => modules}/HyperParameters.cc (100%) rename src/Platform/{ => modules}/HyperParameters.h (100%) rename src/Platform/{ => modules}/ManageResults.cc (100%) rename src/Platform/{ => modules}/ManageResults.h (100%) rename src/Platform/{ => modules}/Models.cc (100%) rename src/Platform/{ => modules}/Models.h (100%) rename src/Platform/{ => modules}/Paths.h (100%) rename src/Platform/{ => modules}/ReportBase.cc (100%) rename src/Platform/{ => modules}/ReportBase.h (100%) rename src/Platform/{ => modules}/ReportConsole.cc (100%) rename src/Platform/{ => modules}/ReportConsole.h (100%) rename src/Platform/{ => modules}/ReportExcel.cc (100%) rename src/Platform/{ => modules}/ReportExcel.h (100%) rename src/Platform/{ => modules}/Result.cc (100%) rename src/Platform/{ => modules}/Result.h (100%) rename src/Platform/{ => modules}/Results.cc (100%) rename src/Platform/{ => modules}/Results.h (100%) rename src/Platform/{ => modules}/Statistics.cc (100%) rename src/Platform/{ => modules}/Statistics.h (100%) rename src/Platform/{ => modules}/Symbols.h (100%) rename src/Platform/{ => modules}/Timer.h (100%) rename src/Platform/{ => modules}/Utils.h (100%) rename src/Platform/{ => modules}/modelRegister.h (100%) create mode 100644 tests/TestPlatform.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 16f7d22..afd9e64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ message("XLSXWRITER_LIB=${XLSXWRITER_LIB}") # Subdirectories # -------------- +set(Platform_MODULES ${Platform_SOURCE_DIR}/src/Platform/modules/) add_subdirectory(config) add_subdirectory(src/Platform) add_subdirectory(sample) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 43ebfcc..f8ccf8d 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -10,5 +10,5 @@ include_directories( ${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/json/include ${CMAKE_BINARY_DIR}/configured_files/include ) -add_executable(PlatformSample sample.cc ${Platform_SOURCE_DIR}/src/Platform/Models.cc) +add_executable(PlatformSample sample.cc ${Platform_MODULES}/Models.cc) target_link_libraries(PlatformSample PyClassifiers ArffFiles mdlp "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 6a972dd..7fad509 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories( ${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/mdlp ${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/json/include ${Platform_SOURCE_DIR}/lib/PyClassifiers/src/PyClassifiers - ${Platform_SOURCE_DIR}/src/Platform + ${Platform_MODULES} ${Platform_SOURCE_DIR}/lib/Files ${Platform_SOURCE_DIR}/lib/mdlp ${Platform_SOURCE_DIR}/lib/argparse/include @@ -15,11 +15,19 @@ include_directories( ${CMAKE_BINARY_DIR}/configured_files/include ) -add_executable(b_best b_best.cc BestResults.cc Result.cc Statistics.cc BestResultsExcel.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc) -add_executable(b_grid b_grid.cc GridSearch.cc GridData.cc HyperParameters.cc Datasets.cc Dataset.cc Models.cc) -add_executable(b_list b_list.cc Datasets.cc Dataset.cc) -add_executable(b_main b_main.cc Experiment.cc Datasets.cc Dataset.cc Models.cc HyperParameters.cc ReportConsole.cc ReportBase.cc) -add_executable(b_manage b_manage.cc Results.cc ManageResults.cc CommandParser.cc Result.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc) +set(best_sources BestResults.cc Result.cc Statistics.cc BestResultsExcel.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc) +list(TRANSFORM best_sources PREPEND ${Platform_MODULES}) +add_executable(b_best b_best.cc ${best_sources}) +set(grid_sources GridSearch.cc GridData.cc HyperParameters.cc Datasets.cc Dataset.cc Models.cc) +list(TRANSFORM grid_sources PREPEND ${Platform_MODULES}) +add_executable(b_grid b_grid.cc ${grid_sources}) +add_executable(b_list b_list.cc ${Platform_MODULES}Datasets.cc ${Platform_MODULES}Dataset.cc) +set(main_sources Experiment.cc Datasets.cc Dataset.cc Models.cc HyperParameters.cc ReportConsole.cc ReportBase.cc) +list(TRANSFORM main_sources PREPEND ${Platform_MODULES}) +add_executable(b_main b_main.cc ${main_sources}) +set(manage_sources Results.cc ManageResults.cc CommandParser.cc Result.cc ReportConsole.cc ReportExcel.cc ReportBase.cc Datasets.cc Dataset.cc ExcelFile.cc) +list(TRANSFORM manage_sources PREPEND ${Platform_MODULES}) +add_executable(b_manage b_manage.cc ${manage_sources}) target_link_libraries(b_best Boost::boost "${XLSXWRITER_LIB}" "${TORCH_LIBRARIES}" ArffFiles mdlp) target_link_libraries(b_grid PyClassifiers ${MPI_CXX_LIBRARIES} ArffFiles) diff --git a/src/Platform/BestResults.cc b/src/Platform/modules/BestResults.cc similarity index 100% rename from src/Platform/BestResults.cc rename to src/Platform/modules/BestResults.cc diff --git a/src/Platform/BestResults.h b/src/Platform/modules/BestResults.h similarity index 100% rename from src/Platform/BestResults.h rename to src/Platform/modules/BestResults.h diff --git a/src/Platform/BestResultsExcel.cc b/src/Platform/modules/BestResultsExcel.cc similarity index 100% rename from src/Platform/BestResultsExcel.cc rename to src/Platform/modules/BestResultsExcel.cc diff --git a/src/Platform/BestResultsExcel.h b/src/Platform/modules/BestResultsExcel.h similarity index 100% rename from src/Platform/BestResultsExcel.h rename to src/Platform/modules/BestResultsExcel.h diff --git a/src/Platform/BestScore.h b/src/Platform/modules/BestScore.h similarity index 100% rename from src/Platform/BestScore.h rename to src/Platform/modules/BestScore.h diff --git a/src/Platform/CLocale.h b/src/Platform/modules/CLocale.h similarity index 100% rename from src/Platform/CLocale.h rename to src/Platform/modules/CLocale.h diff --git a/src/Platform/Colors.h b/src/Platform/modules/Colors.h similarity index 100% rename from src/Platform/Colors.h rename to src/Platform/modules/Colors.h diff --git a/src/Platform/CommandParser.cc b/src/Platform/modules/CommandParser.cc similarity index 100% rename from src/Platform/CommandParser.cc rename to src/Platform/modules/CommandParser.cc diff --git a/src/Platform/CommandParser.h b/src/Platform/modules/CommandParser.h similarity index 100% rename from src/Platform/CommandParser.h rename to src/Platform/modules/CommandParser.h diff --git a/src/Platform/Dataset.cc b/src/Platform/modules/Dataset.cc similarity index 100% rename from src/Platform/Dataset.cc rename to src/Platform/modules/Dataset.cc diff --git a/src/Platform/Dataset.h b/src/Platform/modules/Dataset.h similarity index 100% rename from src/Platform/Dataset.h rename to src/Platform/modules/Dataset.h diff --git a/src/Platform/Datasets.cc b/src/Platform/modules/Datasets.cc similarity index 100% rename from src/Platform/Datasets.cc rename to src/Platform/modules/Datasets.cc diff --git a/src/Platform/Datasets.h b/src/Platform/modules/Datasets.h similarity index 100% rename from src/Platform/Datasets.h rename to src/Platform/modules/Datasets.h diff --git a/src/Platform/DotEnv.h b/src/Platform/modules/DotEnv.h similarity index 100% rename from src/Platform/DotEnv.h rename to src/Platform/modules/DotEnv.h diff --git a/src/Platform/ExcelFile.cc b/src/Platform/modules/ExcelFile.cc similarity index 100% rename from src/Platform/ExcelFile.cc rename to src/Platform/modules/ExcelFile.cc diff --git a/src/Platform/ExcelFile.h b/src/Platform/modules/ExcelFile.h similarity index 100% rename from src/Platform/ExcelFile.h rename to src/Platform/modules/ExcelFile.h diff --git a/src/Platform/Experiment.cc b/src/Platform/modules/Experiment.cc similarity index 100% rename from src/Platform/Experiment.cc rename to src/Platform/modules/Experiment.cc diff --git a/src/Platform/Experiment.h b/src/Platform/modules/Experiment.h similarity index 100% rename from src/Platform/Experiment.h rename to src/Platform/modules/Experiment.h diff --git a/src/Platform/GridData.cc b/src/Platform/modules/GridData.cc similarity index 100% rename from src/Platform/GridData.cc rename to src/Platform/modules/GridData.cc diff --git a/src/Platform/GridData.h b/src/Platform/modules/GridData.h similarity index 100% rename from src/Platform/GridData.h rename to src/Platform/modules/GridData.h diff --git a/src/Platform/GridSearch.cc b/src/Platform/modules/GridSearch.cc similarity index 100% rename from src/Platform/GridSearch.cc rename to src/Platform/modules/GridSearch.cc diff --git a/src/Platform/GridSearch.h b/src/Platform/modules/GridSearch.h similarity index 100% rename from src/Platform/GridSearch.h rename to src/Platform/modules/GridSearch.h diff --git a/src/Platform/HyperParameters.cc b/src/Platform/modules/HyperParameters.cc similarity index 100% rename from src/Platform/HyperParameters.cc rename to src/Platform/modules/HyperParameters.cc diff --git a/src/Platform/HyperParameters.h b/src/Platform/modules/HyperParameters.h similarity index 100% rename from src/Platform/HyperParameters.h rename to src/Platform/modules/HyperParameters.h diff --git a/src/Platform/ManageResults.cc b/src/Platform/modules/ManageResults.cc similarity index 100% rename from src/Platform/ManageResults.cc rename to src/Platform/modules/ManageResults.cc diff --git a/src/Platform/ManageResults.h b/src/Platform/modules/ManageResults.h similarity index 100% rename from src/Platform/ManageResults.h rename to src/Platform/modules/ManageResults.h diff --git a/src/Platform/Models.cc b/src/Platform/modules/Models.cc similarity index 100% rename from src/Platform/Models.cc rename to src/Platform/modules/Models.cc diff --git a/src/Platform/Models.h b/src/Platform/modules/Models.h similarity index 100% rename from src/Platform/Models.h rename to src/Platform/modules/Models.h diff --git a/src/Platform/Paths.h b/src/Platform/modules/Paths.h similarity index 100% rename from src/Platform/Paths.h rename to src/Platform/modules/Paths.h diff --git a/src/Platform/ReportBase.cc b/src/Platform/modules/ReportBase.cc similarity index 100% rename from src/Platform/ReportBase.cc rename to src/Platform/modules/ReportBase.cc diff --git a/src/Platform/ReportBase.h b/src/Platform/modules/ReportBase.h similarity index 100% rename from src/Platform/ReportBase.h rename to src/Platform/modules/ReportBase.h diff --git a/src/Platform/ReportConsole.cc b/src/Platform/modules/ReportConsole.cc similarity index 100% rename from src/Platform/ReportConsole.cc rename to src/Platform/modules/ReportConsole.cc diff --git a/src/Platform/ReportConsole.h b/src/Platform/modules/ReportConsole.h similarity index 100% rename from src/Platform/ReportConsole.h rename to src/Platform/modules/ReportConsole.h diff --git a/src/Platform/ReportExcel.cc b/src/Platform/modules/ReportExcel.cc similarity index 100% rename from src/Platform/ReportExcel.cc rename to src/Platform/modules/ReportExcel.cc diff --git a/src/Platform/ReportExcel.h b/src/Platform/modules/ReportExcel.h similarity index 100% rename from src/Platform/ReportExcel.h rename to src/Platform/modules/ReportExcel.h diff --git a/src/Platform/Result.cc b/src/Platform/modules/Result.cc similarity index 100% rename from src/Platform/Result.cc rename to src/Platform/modules/Result.cc diff --git a/src/Platform/Result.h b/src/Platform/modules/Result.h similarity index 100% rename from src/Platform/Result.h rename to src/Platform/modules/Result.h diff --git a/src/Platform/Results.cc b/src/Platform/modules/Results.cc similarity index 100% rename from src/Platform/Results.cc rename to src/Platform/modules/Results.cc diff --git a/src/Platform/Results.h b/src/Platform/modules/Results.h similarity index 100% rename from src/Platform/Results.h rename to src/Platform/modules/Results.h diff --git a/src/Platform/Statistics.cc b/src/Platform/modules/Statistics.cc similarity index 100% rename from src/Platform/Statistics.cc rename to src/Platform/modules/Statistics.cc diff --git a/src/Platform/Statistics.h b/src/Platform/modules/Statistics.h similarity index 100% rename from src/Platform/Statistics.h rename to src/Platform/modules/Statistics.h diff --git a/src/Platform/Symbols.h b/src/Platform/modules/Symbols.h similarity index 100% rename from src/Platform/Symbols.h rename to src/Platform/modules/Symbols.h diff --git a/src/Platform/Timer.h b/src/Platform/modules/Timer.h similarity index 100% rename from src/Platform/Timer.h rename to src/Platform/modules/Timer.h diff --git a/src/Platform/Utils.h b/src/Platform/modules/Utils.h similarity index 100% rename from src/Platform/Utils.h rename to src/Platform/modules/Utils.h diff --git a/src/Platform/modelRegister.h b/src/Platform/modules/modelRegister.h similarity index 100% rename from src/Platform/modelRegister.h rename to src/Platform/modules/modelRegister.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 951e73e..a0d9e4e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,7 +7,7 @@ if(ENABLE_TESTING) ${Platform_SOURCE_DIR}/lib/Files ${CMAKE_BINARY_DIR}/configured_files/include ) - set(TEST_SOURCES_PLATFORM TestUtils.cc) + set(TEST_SOURCES_PLATFORM TestUtils.cc TestPlatform.cc) add_executable(${TEST_PLATFORM} ${TEST_SOURCES_PLATFORM}) target_link_libraries(${TEST_PLATFORM} PUBLIC "${TORCH_LIBRARIES}" ArffFiles mdlp Catch2::Catch2WithMain) add_test(NAME ${TEST_PLATFORM} COMMAND ${TEST_PLATFORM}) diff --git a/tests/TestPlatform.cc b/tests/TestPlatform.cc new file mode 100644 index 0000000..3737f21 --- /dev/null +++ b/tests/TestPlatform.cc @@ -0,0 +1,70 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do +#include +#include +#include +#include +#include +#include +#include "TestUtils.h" + +TEST_CASE("Test Python Classifiers score", "[PyClassifiers]") +{ + map , float> scores = { + // Diabetes + {{"diabetes", "STree"}, 0.81641}, {{"diabetes", "ODTE"}, 0.84635}, {{"diabetes", "SVC"}, 0.76823}, {{"diabetes", "RandomForest"}, 1.0}, + // Ecoli + {{"ecoli", "STree"}, 0.8125}, {{"ecoli", "ODTE"}, 0.84821}, {{"ecoli", "SVC"}, 0.89583}, {{"ecoli", "RandomForest"}, 1.0}, + // Glass + {{"glass", "STree"}, 0.57009}, {{"glass", "ODTE"}, 0.77103}, {{"glass", "SVC"}, 0.35514}, {{"glass", "RandomForest"}, 1.0}, + // Iris + {{"iris", "STree"}, 0.99333}, {{"iris", "ODTE"}, 0.98667}, {{"iris", "SVC"}, 0.97333}, {{"iris", "RandomForest"}, 1.0}, + }; + + std::string file_name = GENERATE("glass", "iris", "ecoli", "diabetes"); + auto raw = RawDatasets(file_name, false); + + SECTION("Test STree classifier (" + file_name + ")") + { + auto clf = pywrap::STree(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + auto score = clf.score(raw.Xt, raw.yt); + REQUIRE(score == Catch::Approx(scores[{file_name, "STree"}]).epsilon(raw.epsilon)); + } + SECTION("Test ODTE classifier (" + file_name + ")") + { + auto clf = pywrap::ODTE(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + auto score = clf.score(raw.Xt, raw.yt); + REQUIRE(score == Catch::Approx(scores[{file_name, "ODTE"}]).epsilon(raw.epsilon)); + } + SECTION("Test SVC classifier (" + file_name + ")") + { + auto clf = pywrap::SVC(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + auto score = clf.score(raw.Xt, raw.yt); + REQUIRE(score == Catch::Approx(scores[{file_name, "SVC"}]).epsilon(raw.epsilon)); + } + SECTION("Test RandomForest classifier (" + file_name + ")") + { + auto clf = pywrap::RandomForest(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + auto score = clf.score(raw.Xt, raw.yt); + REQUIRE(score == Catch::Approx(scores[{file_name, "RandomForest"}]).epsilon(raw.epsilon)); + } +} +TEST_CASE("Classifiers features", "[PyClassifiers]") +{ + auto raw = RawDatasets("iris", true); + auto clf = pywrap::STree(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + REQUIRE(clf.getNumberOfNodes() == 3); + REQUIRE(clf.getNumberOfEdges() == 2); +} +TEST_CASE("Get num features & num edges", "[PyClassifiers]") +{ + auto raw = RawDatasets("iris", true); + auto clf = pywrap::ODTE(); + clf.fit(raw.Xt, raw.yt, raw.featurest, raw.classNamet, raw.statest); + REQUIRE(clf.getNumberOfNodes() == 10); + REQUIRE(clf.getNumberOfEdges() == 10); +} \ No newline at end of file