Refactor library structure

This commit is contained in:
2024-03-08 22:20:54 +01:00
parent 1231f4522a
commit 635ef22520
56 changed files with 64 additions and 68 deletions

View File

@@ -10,7 +10,7 @@ Checks: '-*,
-modernize-use-trailing-return-type, -modernize-use-trailing-return-type,
-bugprone-exception-escape' -bugprone-exception-escape'
HeaderFilterRegex: 'src/*' HeaderFilterRegex: 'bayesnet/*'
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
WarningsAsErrors: '' WarningsAsErrors: ''
FormatStyle: file FormatStyle: file

View File

@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [unpublished] ## [unreleased]
### Added ### Added

View File

@@ -66,7 +66,7 @@ add_git_submodule("lib/json")
# -------------- # --------------
add_subdirectory(config) add_subdirectory(config)
add_subdirectory(lib/Files) add_subdirectory(lib/Files)
add_subdirectory(src) add_subdirectory(bayesnet)
# Testing # Testing
# ------- # -------
@@ -83,5 +83,5 @@ install(TARGETS BayesNet
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
CONFIGURATIONS Release) CONFIGURATIONS Release)
install(DIRECTORY src/ DESTINATION include/bayesnet FILES_MATCHING CONFIGURATIONS Release PATTERN "*.h") install(DIRECTORY bayesnet/ DESTINATION include/bayesnet FILES_MATCHING CONFIGURATIONS Release PATTERN "*.h")
install(FILES ${CMAKE_BINARY_DIR}/configured_files/include/config.h DESTINATION include/bayesnet CONFIGURATIONS Release) install(FILES ${CMAKE_BINARY_DIR}/configured_files/include/config.h DESTINATION include/bayesnet CONFIGURATIONS Release)

View File

@@ -69,6 +69,7 @@ release: ## Build a Release version of the project
fname = "tests/data/iris.arff" fname = "tests/data/iris.arff"
sample: ## Build sample sample: ## Build sample
@echo ">>> Building Sample..."; @echo ">>> Building Sample...";
@if [ -d ./sample/build ]; then rm -rf ./sample/build; fi
@cd sample && cmake -B build -S . && cmake --build build -t bayesnet_sample @cd sample && cmake -B build -S . && cmake --build build -t bayesnet_sample
sample/build/bayesnet_sample $(fname) sample/build/bayesnet_sample $(fname)
@echo ">>> Done"; @echo ">>> Done";

View File

@@ -1,8 +1,8 @@
#ifndef BASE_H #ifndef BASE_H
#define BASE_H #define BASE_H
#include <vector>
#include <torch/torch.h> #include <torch/torch.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <vector>
namespace bayesnet { namespace bayesnet {
enum status_t { NORMAL, WARNING, ERROR }; enum status_t { NORMAL, WARNING, ERROR };
class BaseClassifier { class BaseClassifier {

View File

@@ -3,7 +3,7 @@ include_directories(
${BayesNet_SOURCE_DIR}/lib/Files ${BayesNet_SOURCE_DIR}/lib/Files
${BayesNet_SOURCE_DIR}/lib/folding ${BayesNet_SOURCE_DIR}/lib/folding
${BayesNet_SOURCE_DIR}/lib/json/include ${BayesNet_SOURCE_DIR}/lib/json/include
${BayesNet_SOURCE_DIR}/src ${BayesNet_SOURCE_DIR}
${CMAKE_BINARY_DIR}/configured_files/include ${CMAKE_BINARY_DIR}/configured_files/include
) )

View File

@@ -1,5 +1,5 @@
#include "bayesnet/utils/bayesnetUtils.h"
#include "Classifier.h" #include "Classifier.h"
#include "utils/bayesnetUtils.h"
namespace bayesnet { namespace bayesnet {
Classifier::Classifier(Network model) : model(model), m(0), n(0), metrics(Metrics()), fitted(false) {} Classifier::Classifier(Network model) : model(model), m(0), n(0), metrics(Metrics()), fitted(false) {}

View File

@@ -1,9 +1,9 @@
#ifndef CLASSIFIER_H #ifndef CLASSIFIER_H
#define CLASSIFIER_H #define CLASSIFIER_H
#include <torch/torch.h> #include <torch/torch.h>
#include "BaseClassifier.h" #include "bayesnet/utils/BayesMetrics.h"
#include "bayesian_network/Network.h" #include "bayesnet/network/Network.h"
#include "utils/BayesMetrics.h" #include "bayesnet/BaseClassifier.h"
namespace bayesnet { namespace bayesnet {
class Classifier : public BaseClassifier { class Classifier : public BaseClassifier {

View File

@@ -1,8 +1,8 @@
#ifndef KDB_H #ifndef KDB_H
#define KDB_H #define KDB_H
#include <torch/torch.h> #include <torch/torch.h>
#include "bayesnet/utils/bayesnetUtils.h"
#include "Classifier.h" #include "Classifier.h"
#include "utils/bayesnetUtils.h"
namespace bayesnet { namespace bayesnet {
class KDB : public Classifier { class KDB : public Classifier {
private: private:

View File

@@ -1,7 +1,7 @@
#ifndef KDBLD_H #ifndef KDBLD_H
#define KDBLD_H #define KDBLD_H
#include "KDB.h"
#include "Proposal.h" #include "Proposal.h"
#include "KDB.h"
namespace bayesnet { namespace bayesnet {
class KDBLd : public KDB, public Proposal { class KDBLd : public KDB, public Proposal {

View File

@@ -1,5 +1,5 @@
#include "Proposal.h"
#include <ArffFiles.h> #include <ArffFiles.h>
#include "Proposal.h"
namespace bayesnet { namespace bayesnet {
Proposal::Proposal(torch::Tensor& dataset_, std::vector<std::string>& features_, std::string& className_) : pDataset(dataset_), pFeatures(features_), pClassName(className_) {} Proposal::Proposal(torch::Tensor& dataset_, std::vector<std::string>& features_, std::string& className_) : pDataset(dataset_), pFeatures(features_), pClassName(className_) {}

View File

@@ -3,8 +3,8 @@
#include <string> #include <string>
#include <map> #include <map>
#include <torch/torch.h> #include <torch/torch.h>
#include "bayesian_network/Network.h"
#include <CPPFImdlp.h> #include <CPPFImdlp.h>
#include "bayesnet/network/Network.h"
#include "Classifier.h" #include "Classifier.h"
namespace bayesnet { namespace bayesnet {

View File

@@ -1,7 +1,7 @@
#ifndef AODE_H #ifndef AODE_H
#define AODE_H #define AODE_H
#include "bayesnet/classifiers/SPODE.h"
#include "Ensemble.h" #include "Ensemble.h"
#include "classifiers/SPODE.h"
namespace bayesnet { namespace bayesnet {
class AODE : public Ensemble { class AODE : public Ensemble {
public: public:

View File

@@ -1,8 +1,8 @@
#ifndef AODELD_H #ifndef AODELD_H
#define AODELD_H #define AODELD_H
#include "bayesnet/classifiers/Proposal.h"
#include "bayesnet/classifiers/SPODELd.h"
#include "Ensemble.h" #include "Ensemble.h"
#include "classifiers/Proposal.h"
#include "classifiers/SPODELd.h"
namespace bayesnet { namespace bayesnet {
class AODELd : public Ensemble, public Proposal { class AODELd : public Ensemble, public Proposal {

View File

@@ -3,10 +3,10 @@
#include <limits.h> #include <limits.h>
#include <tuple> #include <tuple>
#include <folding.hpp> #include <folding.hpp>
#include "bayesnet/feature_selection/CFS.h"
#include "bayesnet/feature_selection/FCBF.h"
#include "bayesnet/feature_selection/IWSS.h"
#include "BoostAODE.h" #include "BoostAODE.h"
#include "feature_selection/CFS.h"
#include "feature_selection/FCBF.h"
#include "feature_selection/IWSS.h"
namespace bayesnet { namespace bayesnet {
struct { struct {

View File

@@ -1,9 +1,9 @@
#ifndef BOOSTAODE_H #ifndef BOOSTAODE_H
#define BOOSTAODE_H #define BOOSTAODE_H
#include "Ensemble.h"
#include <map> #include <map>
#include "classifiers/SPODE.h" #include "bayesnet/classifiers/SPODE.h"
#include "feature_selection/FeatureSelect.h" #include "bayesnet/feature_selection/FeatureSelect.h"
#include "Ensemble.h"
namespace bayesnet { namespace bayesnet {
class BoostAODE : public Ensemble { class BoostAODE : public Ensemble {
public: public:

View File

@@ -1,9 +1,9 @@
#ifndef ENSEMBLE_H #ifndef ENSEMBLE_H
#define ENSEMBLE_H #define ENSEMBLE_H
#include <torch/torch.h> #include <torch/torch.h>
#include "classifiers/Classifier.h" #include "bayesnet/utils/BayesMetrics.h"
#include "utils/BayesMetrics.h" #include "bayesnet/utils/bayesnetUtils.h"
#include "utils/bayesnetUtils.h" #include "bayesnet/classifiers/Classifier.h"
namespace bayesnet { namespace bayesnet {
class Ensemble : public Classifier { class Ensemble : public Classifier {

View File

@@ -1,6 +1,6 @@
#include "CFS.h"
#include <limits> #include <limits>
#include "utils/bayesnetUtils.h" #include "bayesnet/utils/bayesnetUtils.h"
#include "CFS.h"
namespace bayesnet { namespace bayesnet {
void CFS::fit() void CFS::fit()
{ {

View File

@@ -2,7 +2,7 @@
#define CFS_H #define CFS_H
#include <torch/torch.h> #include <torch/torch.h>
#include <vector> #include <vector>
#include "feature_selection/FeatureSelect.h" #include "bayesnet/feature_selection/FeatureSelect.h"
namespace bayesnet { namespace bayesnet {
class CFS : public FeatureSelect { class CFS : public FeatureSelect {
public: public:

View File

@@ -1,4 +1,4 @@
#include "utils/bayesnetUtils.h" #include "bayesnet/utils/bayesnetUtils.h"
#include "FCBF.h" #include "FCBF.h"
namespace bayesnet { namespace bayesnet {

View File

@@ -2,7 +2,7 @@
#define FCBF_H #define FCBF_H
#include <torch/torch.h> #include <torch/torch.h>
#include <vector> #include <vector>
#include "feature_selection/FeatureSelect.h" #include "bayesnet/feature_selection/FeatureSelect.h"
namespace bayesnet { namespace bayesnet {
class FCBF : public FeatureSelect { class FCBF : public FeatureSelect {
public: public:

View File

@@ -1,6 +1,6 @@
#include "FeatureSelect.h"
#include <limits> #include <limits>
#include "utils/bayesnetUtils.h" #include "bayesnet/utils/bayesnetUtils.h"
#include "FeatureSelect.h"
namespace bayesnet { namespace bayesnet {
FeatureSelect::FeatureSelect(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int maxFeatures, const int classNumStates, const torch::Tensor& weights) : FeatureSelect::FeatureSelect(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int maxFeatures, const int classNumStates, const torch::Tensor& weights) :
Metrics(samples, features, className, classNumStates), maxFeatures(maxFeatures == 0 ? samples.size(0) - 1 : maxFeatures), weights(weights) Metrics(samples, features, className, classNumStates), maxFeatures(maxFeatures == 0 ? samples.size(0) - 1 : maxFeatures), weights(weights)

View File

@@ -2,7 +2,7 @@
#define FEATURE_SELECT_H #define FEATURE_SELECT_H
#include <torch/torch.h> #include <torch/torch.h>
#include <vector> #include <vector>
#include "utils/BayesMetrics.h" #include "bayesnet/utils/BayesMetrics.h"
namespace bayesnet { namespace bayesnet {
class FeatureSelect : public Metrics { class FeatureSelect : public Metrics {
public: public:

View File

@@ -1,6 +1,6 @@
#include "IWSS.h"
#include <limits> #include <limits>
#include "utils/bayesnetUtils.h" #include "bayesnet/utils/bayesnetUtils.h"
#include "IWSS.h"
namespace bayesnet { namespace bayesnet {
IWSS::IWSS(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int maxFeatures, const int classNumStates, const torch::Tensor& weights, const double threshold) : IWSS::IWSS(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int maxFeatures, const int classNumStates, const torch::Tensor& weights, const double threshold) :
FeatureSelect(samples, features, className, maxFeatures, classNumStates, weights), threshold(threshold) FeatureSelect(samples, features, className, maxFeatures, classNumStates, weights), threshold(threshold)

View File

@@ -1,7 +1,7 @@
#ifndef IWSS_H #ifndef IWSS_H
#define IWSS_H #define IWSS_H
#include <torch/torch.h>
#include <vector> #include <vector>
#include <torch/torch.h>
#include "FeatureSelect.h" #include "FeatureSelect.h"
namespace bayesnet { namespace bayesnet {
class IWSS : public FeatureSelect { class IWSS : public FeatureSelect {

View File

@@ -1,7 +1,7 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include "Network.h" #include "Network.h"
#include "utils/bayesnetUtils.h" #include "bayesnet/utils/bayesnetUtils.h"
namespace bayesnet { namespace bayesnet {
Network::Network() : features(std::vector<std::string>()), className(""), classNumStates(0), fitted(false), laplaceSmoothing(0) {} Network::Network() : features(std::vector<std::string>()), className(""), classNumStates(0), fitted(false), laplaceSmoothing(0) {}
Network::Network(float maxT) : features(std::vector<std::string>()), className(""), classNumStates(0), maxThreads(maxT), fitted(false), laplaceSmoothing(0) {} Network::Network(float maxT) : features(std::vector<std::string>()), className(""), classNumStates(0), maxThreads(maxT), fitted(false), laplaceSmoothing(0) {}

View File

@@ -1,9 +1,9 @@
#ifndef NETWORK_H #ifndef NETWORK_H
#define NETWORK_H #define NETWORK_H
#include "Node.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include "config.h" #include "bayesnet/config.h"
#include "Node.h"
namespace bayesnet { namespace bayesnet {
class Network { class Network {

View File

@@ -1,9 +1,9 @@
#ifndef NODE_H #ifndef NODE_H
#define NODE_H #define NODE_H
#include <torch/torch.h>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <string> #include <string>
#include <torch/torch.h>
namespace bayesnet { namespace bayesnet {
class Node { class Node {
private: private:

View File

@@ -1,5 +1,5 @@
#include "BayesMetrics.h"
#include "Mst.h" #include "Mst.h"
#include "BayesMetrics.h"
namespace bayesnet { namespace bayesnet {
//samples is n+1xm tensor used to fit the model //samples is n+1xm tensor used to fit the model
Metrics::Metrics(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int classNumStates) Metrics::Metrics(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int classNumStates)

View File

@@ -1,8 +1,8 @@
#ifndef BAYESNET_METRICS_H #ifndef BAYESNET_METRICS_H
#define BAYESNET_METRICS_H #define BAYESNET_METRICS_H
#include <torch/torch.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <torch/torch.h>
namespace bayesnet { namespace bayesnet {
class Metrics { class Metrics {
private: private:

View File

@@ -1,6 +1,6 @@
#include "Mst.h"
#include <vector> #include <vector>
#include <list> #include <list>
#include "Mst.h"
/* /*
Based on the code from https://www.softwaretestinghelp.com/minimum-spanning-tree-tutorial/ Based on the code from https://www.softwaretestinghelp.com/minimum-spanning-tree-tutorial/

View File

@@ -1,8 +1,8 @@
#ifndef MST_H #ifndef MST_H
#define MST_H #define MST_H
#include <torch/torch.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <torch/torch.h>
namespace bayesnet { namespace bayesnet {
class MST { class MST {
private: private:

View File

@@ -1,7 +1,7 @@
#ifndef BAYESNET_UTILS_H #ifndef BAYESNET_UTILS_H
#define BAYESNET_UTILS_H #define BAYESNET_UTILS_H
#include <torch/torch.h>
#include <vector> #include <vector>
#include <torch/torch.h>
namespace bayesnet { namespace bayesnet {
std::vector<int> argsort(std::vector<double>& nums); std::vector<int> argsort(std::vector<double>& nums);
std::vector<std::vector<int>> tensorToVector(torch::Tensor& dtensor); std::vector<std::vector<int>> tensorToVector(torch::Tensor& dtensor);

View File

@@ -1,4 +1,4 @@
filter = src/ filter = bayesnet/
exclude-directories = build_debug/lib/ exclude-directories = build_debug/lib/
print-summary = yes print-summary = yes
sort = uncovered-percent sort = uncovered-percent

View File

@@ -11,7 +11,7 @@ include_directories(
lib/Files lib/Files
lib/mdlp lib/mdlp
lib/json/include lib/json/include
/usr/local/include/bayesnet /usr/local/include/
) )
add_subdirectory(lib/Files) add_subdirectory(lib/Files)

View File

@@ -1,6 +1,6 @@
#include <ArffFiles.h> #include <ArffFiles.h>
#include <CPPFImdlp.h> #include <CPPFImdlp.h>
#include <ensembles/BoostAODE.h> #include <bayesnet/ensembles/BoostAODE.h>
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)
{ {

View File

@@ -1,19 +1,14 @@
if(ENABLE_TESTING) if(ENABLE_TESTING)
set(TEST_BAYESNET "unit_tests_bayesnet") set(TEST_BAYESNET "unit_tests_bayesnet")
include_directories( include_directories(
${BayesNet_SOURCE_DIR}/src
${BayesNet_SOURCE_DIR}/src/feature_selection
${BayesNet_SOURCE_DIR}/src/bayesian_network
${BayesNet_SOURCE_DIR}/src/classifiers
${BayesNet_SOURCE_DIR}/src/utils
${BayesNet_SOURCE_DIR}/src/ensembles
${BayesNet_SOURCE_DIR}/lib/Files ${BayesNet_SOURCE_DIR}/lib/Files
${BayesNet_SOURCE_DIR}/lib/mdlp ${BayesNet_SOURCE_DIR}/lib/mdlp
${BayesNet_SOURCE_DIR}/lib/folding ${BayesNet_SOURCE_DIR}/lib/folding
${BayesNet_SOURCE_DIR}/lib/json/include ${BayesNet_SOURCE_DIR}/lib/json/include
${BayesNet_SOURCE_DIR}
${CMAKE_BINARY_DIR}/configured_files/include ${CMAKE_BINARY_DIR}/configured_files/include
) )
file(GLOB_RECURSE BayesNet_SOURCES "${BayesNet_SOURCE_DIR}/src/*.cc") file(GLOB_RECURSE BayesNet_SOURCES "${BayesNet_SOURCE_DIR}/bayesnet/*.cc")
set(TEST_SOURCES_BAYESNET TestBayesModels.cc TestBayesNetwork.cc TestBayesMetrics.cc TestUtils.cc ${BayesNet_SOURCES}) set(TEST_SOURCES_BAYESNET TestBayesModels.cc TestBayesNetwork.cc TestBayesMetrics.cc TestUtils.cc ${BayesNet_SOURCES})
add_executable(${TEST_BAYESNET} ${TEST_SOURCES_BAYESNET}) add_executable(${TEST_BAYESNET} ${TEST_SOURCES_BAYESNET})
target_link_libraries(${TEST_BAYESNET} PUBLIC "${TORCH_LIBRARIES}" ArffFiles mdlp Catch2::Catch2WithMain ) target_link_libraries(${TEST_BAYESNET} PUBLIC "${TORCH_LIBRARIES}" ArffFiles mdlp Catch2::Catch2WithMain )

View File

@@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp> #include <catch2/catch_approx.hpp>
#include <catch2/generators/catch_generators.hpp> #include <catch2/generators/catch_generators.hpp>
#include "BayesMetrics.h" #include "bayesnet/utils/BayesMetrics.h"
#include "TestUtils.h" #include "TestUtils.h"

View File

@@ -2,15 +2,15 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp> #include <catch2/catch_approx.hpp>
#include <catch2/generators/catch_generators.hpp> #include <catch2/generators/catch_generators.hpp>
#include "KDB.h" #include "bayesnet/classifiers/KDB.h"
#include "TAN.h" #include "bayesnet/classifiers/TAN.h"
#include "SPODE.h" #include "bayesnet/classifiers/SPODE.h"
#include "AODE.h" #include "bayesnet/classifiers/TANLd.h"
#include "BoostAODE.h" #include "bayesnet/classifiers/KDBLd.h"
#include "TANLd.h" #include "bayesnet/classifiers/SPODELd.h"
#include "KDBLd.h" #include "bayesnet/ensembles/AODE.h"
#include "SPODELd.h" #include "bayesnet/ensembles/AODELd.h"
#include "AODELd.h" #include "bayesnet/ensembles/BoostAODE.h"
#include "TestUtils.h" #include "TestUtils.h"
const std::string ACTUAL_VERSION = "1.0.4"; const std::string ACTUAL_VERSION = "1.0.4";

View File

@@ -3,7 +3,7 @@
#include <catch2/generators/catch_generators.hpp> #include <catch2/generators/catch_generators.hpp>
#include <string> #include <string>
#include "TestUtils.h" #include "TestUtils.h"
#include "Network.h" #include "bayesnet/network/Network.h"
void buildModel(bayesnet::Network& net, const std::vector<std::string>& features, const std::string& className) void buildModel(bayesnet::Network& net, const std::vector<std::string>& features, const std::string& className)
{ {

View File

@@ -1,5 +1,5 @@
#include "TestUtils.h" #include "TestUtils.h"
#include "config.h" #include "bayesnet/config.h"
class Paths { class Paths {
public: public: