mirror of
https://github.com/rmontanana/mdlp.git
synced 2025-08-21 10:26:02 +00:00
Compare commits
3 Commits
d9bd0126f9
...
2d8b949abd
Author | SHA1 | Date | |
---|---|---|---|
2d8b949abd
|
|||
ab12622009
|
|||
248a511972
|
@@ -1,11 +1,24 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
project(fimdlp)
|
project(fimdlp
|
||||||
|
LANGUAGES CXX
|
||||||
|
DESCRIPTION "Discretization algorithm based on the paper by Fayyad & Irani Multi-Interval Discretization of Continuous-Valued Attributes for Classification Learning."
|
||||||
|
HOMEPAGE_URL "https://github.com/rmontanana/mdlp"
|
||||||
|
VERSION 2.0.1
|
||||||
|
)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
cmake_policy(SET CMP0135 NEW)
|
cmake_policy(SET CMP0135 NEW)
|
||||||
|
|
||||||
find_package(Torch CONFIG REQUIRED)
|
find_package(Torch CONFIG REQUIRED)
|
||||||
|
|
||||||
|
# Options
|
||||||
|
# -------
|
||||||
|
option(ENABLE_TESTING OFF)
|
||||||
|
option(ENABLE_SAMPLE OFF)
|
||||||
|
option(COVERAGE OFF)
|
||||||
|
|
||||||
|
add_subdirectory(config)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-elide-constructors")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-elide-constructors")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||||
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
@@ -13,22 +26,54 @@ if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_TESTING)
|
if (ENABLE_TESTING)
|
||||||
MESSAGE("Debug mode")
|
message("Debug mode")
|
||||||
enable_testing()
|
enable_testing()
|
||||||
set(CODE_COVERAGE ON)
|
set(CODE_COVERAGE ON)
|
||||||
SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage")
|
set(GCC_COVERAGE_LINK_FLAGS "${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage")
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
else(ENABLE_TESTING)
|
else()
|
||||||
MESSAGE("Release mode")
|
message("Release mode")
|
||||||
endif(ENABLE_TESTING)
|
endif()
|
||||||
|
|
||||||
|
if (ENABLE_SAMPLE)
|
||||||
add_subdirectory(sample)
|
message("Building sample")
|
||||||
|
add_subdirectory(sample)
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${TORCH_INCLUDE_DIRS}
|
${TORCH_INCLUDE_DIRS}
|
||||||
${fimdlp_SOURCE_DIR}/src
|
${fimdlp_SOURCE_DIR}/src
|
||||||
|
${CMAKE_BINARY_DIR}/configured_files/include
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(fimdlp src/CPPFImdlp.cpp src/Metrics.cpp src/BinDisc.cpp src/Discretizer.cpp)
|
add_library(fimdlp src/CPPFImdlp.cpp src/Metrics.cpp src/BinDisc.cpp src/Discretizer.cpp)
|
||||||
target_link_libraries(fimdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(fimdlp "${TORCH_LIBRARIES}")
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
# ------------
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/fimdlpConfigVersion.cmake"
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY AnyNewerVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS fimdlp
|
||||||
|
EXPORT fimdlpTargets
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
CONFIGURATIONS Release)
|
||||||
|
|
||||||
|
install(DIRECTORY src/ DESTINATION include/fimdlp FILES_MATCHING CONFIGURATIONS Release PATTERN "*.h")
|
||||||
|
install(FILES ${CMAKE_BINARY_DIR}/configured_files/include/config.h DESTINATION include/fimdlp CONFIGURATIONS Release)
|
||||||
|
|
||||||
|
install(EXPORT fimdlpTargets
|
||||||
|
FILE fimdlpTargets.cmake
|
||||||
|
NAMESPACE fimdlp::
|
||||||
|
DESTINATION lib/cmake/fimdlp)
|
||||||
|
|
||||||
|
configure_file(fimdlpConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/fimdlpConfig.cmake" @ONLY)
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/fimdlpConfig.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/fimdlpConfigVersion.cmake"
|
||||||
|
DESTINATION lib/cmake/fimdlp)
|
||||||
|
|
||||||
|
7
Makefile
7
Makefile
@@ -6,13 +6,16 @@ lcov := lcov
|
|||||||
build:
|
build:
|
||||||
@if [ -d build_release ]; then rm -fr build_release; fi
|
@if [ -d build_release ]; then rm -fr build_release; fi
|
||||||
@mkdir build_release
|
@mkdir build_release
|
||||||
@cmake -B build_release -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF
|
@cmake -B build_release -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF -DENABLE_SAMPLE=ON
|
||||||
@cmake --build build_release -j 8
|
@cmake --build build_release -j 8
|
||||||
|
|
||||||
|
install:
|
||||||
|
@cmake --build build_release --target install -j 8
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@if [ -d build_debug ]; then rm -fr build_debug; fi
|
@if [ -d build_debug ]; then rm -fr build_debug; fi
|
||||||
@mkdir build_debug
|
@mkdir build_debug
|
||||||
@cmake -B build_debug -S . -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON
|
@cmake -B build_debug -S . -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON -DENABLE_SAMPLE=ON
|
||||||
@cmake --build build_debug -j 8
|
@cmake --build build_debug -j 8
|
||||||
@cd build_debug/tests && ctest --output-on-failure -j 8
|
@cd build_debug/tests && ctest --output-on-failure -j 8
|
||||||
@cd build_debug/tests && $(lcov) --capture --directory ../ --demangle-cpp --ignore-errors source,source --ignore-errors mismatch --output-file coverage.info >/dev/null 2>&1; \
|
@cd build_debug/tests && $(lcov) --capture --directory ../ --demangle-cpp --ignore-errors source,source --ignore-errors mismatch --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
4
config/CMakeLists.txt
Normal file
4
config/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
configure_file(
|
||||||
|
"config.h.in"
|
||||||
|
"${CMAKE_BINARY_DIR}/configured_files/include/config.h" ESCAPE_QUOTES
|
||||||
|
)
|
13
config/config.h.in
Normal file
13
config/config.h.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR @
|
||||||
|
#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR @
|
||||||
|
#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH @
|
||||||
|
|
||||||
|
static constexpr std::string_view project_name = "@PROJECT_NAME@";
|
||||||
|
static constexpr std::string_view project_version = "@PROJECT_VERSION@";
|
||||||
|
static constexpr std::string_view project_description = "@PROJECT_DESCRIPTION@";
|
||||||
|
static constexpr std::string_view git_sha = "@GIT_SHA@";
|
2
fimdlpConfig.cmake.in
Normal file
2
fimdlpConfig.cmake.in
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/fimdlpTargets.cmake")
|
@@ -5,6 +5,7 @@ set(CMAKE_BUILD_TYPE Debug)
|
|||||||
include_directories(
|
include_directories(
|
||||||
${fimdlp_SOURCE_DIR}/src
|
${fimdlp_SOURCE_DIR}/src
|
||||||
${fimdlp_SOURCE_DIR}/tests/lib/Files
|
${fimdlp_SOURCE_DIR}/tests/lib/Files
|
||||||
|
${CMAKE_BINARY_DIR}/configured_files/include
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(sample sample.cpp )
|
add_executable(sample sample.cpp )
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "typesFImdlp.h"
|
#include "typesFImdlp.h"
|
||||||
#include <torch/torch.h>
|
#include <torch/torch.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
enum class bound_dir_t {
|
enum class bound_dir_t {
|
||||||
@@ -29,7 +30,7 @@ namespace mdlp {
|
|||||||
void fit_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
void fit_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
||||||
torch::Tensor transform_t(const torch::Tensor& X_);
|
torch::Tensor transform_t(const torch::Tensor& X_);
|
||||||
torch::Tensor fit_transform_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
torch::Tensor fit_transform_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
||||||
static inline std::string version() { return "2.0.1"; };
|
static inline std::string version() { return { project_version.begin(), project_version.end() };; };
|
||||||
protected:
|
protected:
|
||||||
labels_t discretizedData = labels_t();
|
labels_t discretizedData = labels_t();
|
||||||
cutPoints_t cutPoints; // At least two cutpoints must be provided, the first and the last will be ignored in transform
|
cutPoints_t cutPoints; // At least two cutpoints must be provided, the first and the last will be ignored in transform
|
||||||
|
@@ -12,6 +12,7 @@ include_directories(
|
|||||||
${TORCH_INCLUDE_DIRS}
|
${TORCH_INCLUDE_DIRS}
|
||||||
${fimdlp_SOURCE_DIR}/src
|
${fimdlp_SOURCE_DIR}/src
|
||||||
${fimdlp_SOURCE_DIR}/tests/lib/Files
|
${fimdlp_SOURCE_DIR}/tests/lib/Files
|
||||||
|
${CMAKE_BINARY_DIR}/configured_files/include
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(Metrics_unittest ${fimdlp_SOURCE_DIR}/src/Metrics.cpp Metrics_unittest.cpp)
|
add_executable(Metrics_unittest ${fimdlp_SOURCE_DIR}/src/Metrics.cpp Metrics_unittest.cpp)
|
||||||
|
Reference in New Issue
Block a user