diff --git a/CLAUDE.md b/CLAUDE.md index 9d294cd..347e617 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,14 +9,17 @@ BayesNet is a C++ library implementing Bayesian Network Classifiers. It provides ## Build System & Dependencies ### Dependency Management + The project supports **two package managers**: #### vcpkg (Default) -- Uses vcpkg with private registry at https://github.com/rmontanana/vcpkg-stash + +- Uses vcpkg with private registry at - Core dependencies: libtorch, nlohmann-json, folding, fimdlp, arff-files, catch2 - All dependencies defined in `vcpkg.json` with version overrides #### Conan (Alternative) + - Modern C++ package manager with better dependency resolution - Configured via `conanfile.py` for packaging and distribution - Supports subset of dependencies (libtorch, nlohmann-json, catch2) @@ -25,6 +28,7 @@ The project supports **two package managers**: ### Build Commands #### Using vcpkg (Default) + ```bash # Initialize dependencies make init @@ -49,6 +53,7 @@ make clean ``` #### Using Conan + ```bash # Install Conan first: pip install conan @@ -74,6 +79,7 @@ make conan-clean ``` ### CMake Configuration + - Uses CMake 3.27+ with C++17 standard - Debug builds automatically enable testing and coverage - Release builds optimize with `-Ofast` @@ -89,6 +95,7 @@ make conan-clean - Coverage reporting with lcov/genhtml ### Test Categories + - A2DE, BoostA2DE, BoostAODE, XSPODE, XSPnDE, XBAODE, XBA2DE - Classifier, Ensemble, FeatureSelection, Metrics, Models - Network, Node, MST, Modules @@ -96,6 +103,7 @@ make conan-clean ## Code Architecture ### Core Structure + ``` bayesnet/ ├── BaseClassifier.h # Abstract base for all classifiers @@ -107,12 +115,14 @@ bayesnet/ ``` ### Key Design Patterns + - **BaseClassifier** abstract interface for all algorithms - Template-based design with both std::vector and torch::Tensor support - Network/Node abstraction for Bayesian network representation - Feature selection as separate, composable modules ### Data Handling + - Supports both discrete integer data and continuous data with discretization - ARFF file format support through arff-files library - Tensor operations via PyTorch C++ (libtorch) @@ -128,6 +138,7 @@ bayesnet/ ## Sample Applications Sample code in `sample/` directory demonstrates library usage: + ```bash make sample fname=tests/data/iris.arff model=TANLd ``` @@ -135,6 +146,7 @@ make sample fname=tests/data/iris.arff model=TANLd ## Package Distribution ### Creating Conan Packages + ```bash # Create package locally make conan-create @@ -148,7 +160,9 @@ make conan-upload remote=myremote profile=myprofile ``` ### Using the Library + With Conan: + ```python # conanfile.txt or conanfile.py [requires] @@ -159,6 +173,7 @@ cmake ``` With vcpkg: + ```json { "dependencies": ["bayesnet"] @@ -170,7 +185,7 @@ With vcpkg: - **Add new classifier**: Extend BaseClassifier, implement in appropriate subdirectory - **Add new test**: Update `tests/CMakeLists.txt` and create test in `tests/` - **Modify build**: Edit main `CMakeLists.txt` or use Makefile targets -- **Update dependencies**: +- **Update dependencies**: - vcpkg: Modify `vcpkg.json` and run `make init` - Conan: Modify `conanfile.py` and run `make conan-init` -- **Package for distribution**: Use `make conan-create` for Conan packaging \ No newline at end of file +- **Package for distribution**: Use `make conan-create` for Conan packaging diff --git a/CMakeLists.txt b/CMakeLists.txt index 00a3ac3..23c55c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -fno-elide-constructors") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast") if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-default-inline") endif() @@ -68,18 +67,19 @@ target_link_libraries(bayesnet # ------- if (CMAKE_BUILD_TYPE STREQUAL "Debug") MESSAGE("Debug mode") - set(ENABLE_TESTING ON) - set(CODE_COVERAGE ON) +else(CMAKE_BUILD_TYPE STREQUAL "Debug") + MESSAGE("Release mode") endif (CMAKE_BUILD_TYPE STREQUAL "Debug") if (ENABLE_TESTING) MESSAGE(STATUS "Testing enabled") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -fno-elide-constructors") find_package(Catch2 CONFIG REQUIRED) find_package(arff-files CONFIG REQUIRED) enable_testing() include(CTest) add_subdirectory(tests) else(ENABLE_TESTING) - message("Release mode") + endif (ENABLE_TESTING) # Installation @@ -99,17 +99,14 @@ configure_package_config_file( install(TARGETS bayesnet EXPORT bayesnetTargets ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - CONFIGURATIONS Release) + LIBRARY DESTINATION lib) install(DIRECTORY bayesnet/ DESTINATION include/bayesnet FILES_MATCHING - CONFIGURATIONS Release PATTERN "*.h") install(FILES ${CMAKE_BINARY_DIR}/configured_files/include/bayesnet/config.h - DESTINATION include/bayesnet - CONFIGURATIONS Release) + DESTINATION include/bayesnet) install(EXPORT bayesnetTargets FILE bayesnetTargets.cmake diff --git a/CONAN_README.md b/CONAN_README.md index a563cdd..a8d3fa5 100644 --- a/CONAN_README.md +++ b/CONAN_README.md @@ -16,29 +16,28 @@ conan profile new default --detect 1. Create a `conanfile.txt` in your project: -```ini -[requires] -libtorch/2.7.0 -bayesnet/1.2.0 + ```ini + [requires] + libtorch/2.7.0 + bayesnet/1.2.0 -[generators] -CMakeDeps -CMakeToolchain + [generators] + CMakeDeps + CMakeToolchain + ``` -``` +1. Install dependencies: -2. Install dependencies: + ```bash + conan install . --build=missing + ``` -```bash -conan install . --build=missing -``` +1. In your CMakeLists.txt: -3. In your CMakeLists.txt: - -```cmake -find_package(bayesnet REQUIRED) -target_link_libraries(your_target bayesnet::bayesnet) -``` + ```cmake + find_package(bayesnet REQUIRED) + target_link_libraries(your_target bayesnet::bayesnet) + ``` ### Building BayesNet with Conan @@ -69,8 +68,8 @@ make conan-create For the custom dependencies, you'll need to create Conan recipes: 1. **folding**: Cross-validation library -2. **fimdlp**: Discretization library -3. **arff-files**: ARFF file format parser +1. **fimdlp**: Discretization library +1. **arff-files**: ARFF file format parser Contact the maintainer or create custom recipes for these packages. diff --git a/Makefile b/Makefile index bbb0647..df32f36 100644 --- a/Makefile +++ b/Makefile @@ -218,8 +218,8 @@ release: ## Build release version using Conan conan-create: ## Create Conan package @echo ">>> Creating Conan package..." - @conan create . --build=missing -tf "" --profile=release -tf "" - @conan create . --build=missing -tf "" --profile=debug + @conan create . --build=missing -tf "" --profile=release + @conan create . --build=missing -tf "" --profile=debug -o "&:enable_coverage=False" -o "&:enable_testing=False" @echo ">>> Done" profile ?= release diff --git a/conanfile.py b/conanfile.py index 9821866..d300869 100644 --- a/conanfile.py +++ b/conanfile.py @@ -18,7 +18,7 @@ class BayesNetConan(ConanFile): "enable_testing": False, "enable_coverage": False } - + # Sources are located in the same place as this recipe, copy them to the recipe exports_sources = "CMakeLists.txt", "bayesnet/*", "config/*", "cmake/*", "docs/*", "tests/*", "bayesnetConfig.cmake.in" @@ -35,7 +35,7 @@ class BayesNetConan(ConanFile): self.version = match.group(1) else: raise Exception("Version not found in CMakeLists.txt") - self.version = match.group(1) + self.version = match.group(1) def config_options(self): if self.settings.os == "Windows": @@ -50,7 +50,7 @@ class BayesNetConan(ConanFile): self.requires("libtorch/2.7.0") self.requires("nlohmann_json/3.11.3") self.requires("folding/1.1.1") # Custom package - self.requires("fimdlp/2.1.0") # Custom package + self.requires("fimdlp/2.1.0") # Custom package def build_requirements(self): self.build_requires("cmake/[>=3.27]")