Refactor library structure

This commit is contained in:
Ricardo Montañana Gómez 2024-03-08 22:20:54 +01:00
parent 1231f4522a
commit 635ef22520
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
56 changed files with 64 additions and 68 deletions

View File

@ -10,7 +10,7 @@ Checks: '-*,
-modernize-use-trailing-return-type,
-bugprone-exception-escape'
HeaderFilterRegex: 'src/*'
HeaderFilterRegex: 'bayesnet/*'
AnalyzeTemporaryDtors: false
WarningsAsErrors: ''
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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [unpublished]
## [unreleased]
### Added

View File

@ -66,7 +66,7 @@ add_git_submodule("lib/json")
# --------------
add_subdirectory(config)
add_subdirectory(lib/Files)
add_subdirectory(src)
add_subdirectory(bayesnet)
# Testing
# -------
@ -83,5 +83,5 @@ install(TARGETS BayesNet
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
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)

View File

@ -69,6 +69,7 @@ release: ## Build a Release version of the project
fname = "tests/data/iris.arff"
sample: ## Build 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
sample/build/bayesnet_sample $(fname)
@echo ">>> Done";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#include "Proposal.h"
#include <ArffFiles.h>
#include "Proposal.h"
namespace bayesnet {
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 <map>
#include <torch/torch.h>
#include "bayesian_network/Network.h"
#include <CPPFImdlp.h>
#include "bayesnet/network/Network.h"
#include "Classifier.h"
namespace bayesnet {

View File

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

View File

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

View File

@ -3,10 +3,10 @@
#include <limits.h>
#include <tuple>
#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 "feature_selection/CFS.h"
#include "feature_selection/FCBF.h"
#include "feature_selection/IWSS.h"
namespace bayesnet {
struct {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#include "FeatureSelect.h"
#include <limits>
#include "utils/bayesnetUtils.h"
#include "bayesnet/utils/bayesnetUtils.h"
#include "FeatureSelect.h"
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) :
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
#include <torch/torch.h>
#include <vector>
#include "utils/BayesMetrics.h"
#include "bayesnet/utils/BayesMetrics.h"
namespace bayesnet {
class FeatureSelect : public Metrics {
public:

View File

@ -1,6 +1,6 @@
#include "IWSS.h"
#include <limits>
#include "utils/bayesnetUtils.h"
#include "bayesnet/utils/bayesnetUtils.h"
#include "IWSS.h"
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) :
FeatureSelect(samples, features, className, maxFeatures, classNumStates, weights), threshold(threshold)

View File

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

View File

@ -1,7 +1,7 @@
#include <thread>
#include <mutex>
#include "Network.h"
#include "utils/bayesnetUtils.h"
#include "bayesnet/utils/bayesnetUtils.h"
namespace bayesnet {
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) {}

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#include "BayesMetrics.h"
#include "Mst.h"
#include "BayesMetrics.h"
namespace bayesnet {
//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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#include <ArffFiles.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)
{

View File

@ -1,19 +1,14 @@
if(ENABLE_TESTING)
set(TEST_BAYESNET "unit_tests_bayesnet")
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/mdlp
${BayesNet_SOURCE_DIR}/lib/folding
${BayesNet_SOURCE_DIR}/lib/json/include
${BayesNet_SOURCE_DIR}
${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})
add_executable(${TEST_BAYESNET} ${TEST_SOURCES_BAYESNET})
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_approx.hpp>
#include <catch2/generators/catch_generators.hpp>
#include "BayesMetrics.h"
#include "bayesnet/utils/BayesMetrics.h"
#include "TestUtils.h"

View File

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

View File

@ -3,7 +3,7 @@
#include <catch2/generators/catch_generators.hpp>
#include <string>
#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)
{

View File

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