From 6a23e2cc2625e7d0181eb55c2b54ca5ea16b7a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Sun, 12 Nov 2023 22:14:29 +0100 Subject: [PATCH] Add CMakelist integration --- CMakeLists.txt | 7 ++++++- src/Platform/CMakeLists.txt | 3 ++- src/Platform/Models.h | 1 + src/Platform/modelRegister.h | 2 ++ src/PyClassifiers/CMakeLists.txt | 5 +++-- src/PyClassifiers/Classifier.h | 7 ++----- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f8b8c8..4d1bc2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,12 +36,16 @@ option(CODE_COVERAGE "Collect coverage from test library" OFF) set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.66.0 REQUIRED) +find_package(Boost 1.66.0 REQUIRED COMPONENTS python3 numpy3) if(Boost_FOUND) message("Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") include_directories(${Boost_INCLUDE_DIRS}) endif() +# Python +find_package(Python3 3.11...3.11.9 COMPONENTS Interpreter Development REQUIRED) +message("Python3_LIBRARIES=${Python3_LIBRARIES}") + # CMakes modules # -------------- set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) @@ -77,6 +81,7 @@ add_subdirectory(config) add_subdirectory(lib/Files) add_subdirectory(src/BayesNet) add_subdirectory(src/Platform) +add_subdirectory(src/PyClassifiers) add_subdirectory(sample) file(GLOB BayesNet_HEADERS CONFIGURE_DEPENDS ${BayesNet_SOURCE_DIR}/src/BayesNet/*.h ${BayesNet_SOURCE_DIR}/BayesNet/*.h) diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 0588ff2..99f0afc 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(${BayesNet_SOURCE_DIR}/src/BayesNet) include_directories(${BayesNet_SOURCE_DIR}/src/Platform) +include_directories(${BayesNet_SOURCE_DIR}/src/PyClassifiers) include_directories(${BayesNet_SOURCE_DIR}/lib/Files) include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp) include_directories(${BayesNet_SOURCE_DIR}/lib/argparse/include) @@ -11,7 +12,7 @@ add_executable(b_manage b_manage.cc Results.cc ManageResults.cc CommandParser.cc add_executable(b_list b_list.cc Datasets.cc Dataset.cc) 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) -target_link_libraries(b_main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}") +target_link_libraries(b_main BayesNet ArffFiles mdlp "${TORCH_LIBRARIES}" PyWrap) target_link_libraries(b_manage "${TORCH_LIBRARIES}" "${XLSXWRITER_LIB}" ArffFiles mdlp) target_link_libraries(b_best Boost::boost "${XLSXWRITER_LIB}" "${TORCH_LIBRARIES}" ArffFiles mdlp) target_link_libraries(b_list ArffFiles mdlp "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/Platform/Models.h b/src/Platform/Models.h index bcf6792..8e250d5 100644 --- a/src/Platform/Models.h +++ b/src/Platform/Models.h @@ -11,6 +11,7 @@ #include "SPODELd.h" #include "AODELd.h" #include "BoostAODE.h" +#include "STree.h" namespace platform { class Models { private: diff --git a/src/Platform/modelRegister.h b/src/Platform/modelRegister.h index 04b48cf..f8a0e67 100644 --- a/src/Platform/modelRegister.h +++ b/src/Platform/modelRegister.h @@ -18,4 +18,6 @@ static platform::Registrar registrarALD("AODELd", [](void) -> bayesnet::BaseClassifier* { return new bayesnet::AODELd();}); static platform::Registrar registrarBA("BoostAODE", [](void) -> bayesnet::BaseClassifier* { return new bayesnet::BoostAODE();}); +static pywrap::Registrar registrarSt("STree", + [](void) -> bayesnet::BaseClassifier* { return new pywrap::STree();}); #endif \ No newline at end of file diff --git a/src/PyClassifiers/CMakeLists.txt b/src/PyClassifiers/CMakeLists.txt index 9c99a7e..61af573 100644 --- a/src/PyClassifiers/CMakeLists.txt +++ b/src/PyClassifiers/CMakeLists.txt @@ -1,5 +1,6 @@ -include_directories(${PyWrap_SOURCE_DIR}/lib/Files) -include_directories(${PyWrap_SOURCE_DIR}/lib/json/include) +include_directories(${BayesNet_SOURCE_DIR}/lib/Files) +include_directories(${BayesNet_SOURCE_DIR}/lib/json/include) +include_directories(${BayesNet_SOURCE_DIR}/src/BayesNet) include_directories(${Python3_INCLUDE_DIRS}) include_directories(${TORCH_INCLUDE_DIRS}) diff --git a/src/PyClassifiers/Classifier.h b/src/PyClassifiers/Classifier.h index 8160aa9..083496f 100644 --- a/src/PyClassifiers/Classifier.h +++ b/src/PyClassifiers/Classifier.h @@ -1,23 +1,20 @@ #ifndef CLASSIFIER_H #define CLASSIFIER_H #include +#include "BaseClassifier.h" #include #include #include #include namespace pywrap { - class Classifier { + class Classifier : bayesnet::BaseClassifier { public: Classifier() = default; virtual ~Classifier() = default; - virtual Classifier& fit(torch::Tensor& X, torch::Tensor& y, const std::vector& features, const std::string& className, std::map>& states) = 0; virtual Classifier& fit(torch::Tensor& X, torch::Tensor& y) = 0; - virtual torch::Tensor predict(torch::Tensor& X) = 0; - virtual double score(torch::Tensor& X, torch::Tensor& y) = 0; virtual std::string version() = 0; virtual std::string sklearnVersion() = 0; - virtual void setHyperparameters(const nlohmann::json& hyperparameters) = 0; protected: virtual void checkHyperparameters(const std::vector& validKeys, const nlohmann::json& hyperparameters) = 0; };