diff --git a/.vscode/launch.json b/.vscode/launch.json index f9a89d3..ae39398 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "type": "lldb", "request": "launch", "name": "bayesnet", - "program": "${workspaceFolder}/build/bayesnet", + "program": "${workspaceFolder}/build/sample/main", "args": [], "cwd": "${workspaceFolder}", "preLaunchTask": "CMake: build" diff --git a/CMakeLists.txt b/CMakeLists.txt index ff8bb56..4d7b7f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) -project(bayesnet) +project(BayesNet) find_package(Torch REQUIRED) if (POLICY CMP0135) @@ -10,8 +10,5 @@ endif () set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") -# add_library(BayesNet Node.cc Network.cc) -add_executable(BayesNet main.cc ArffFiles.cc Node.cc Network.cc CPPFImdlp.cpp Metrics.cpp) -add_executable(test test.cc) -target_link_libraries(BayesNet "${TORCH_LIBRARIES}") -target_link_libraries(test "${TORCH_LIBRARIES}") \ No newline at end of file +add_subdirectory(src) +add_subdirectory(sample) \ No newline at end of file diff --git a/iris.arff b/data/iris.arff similarity index 100% rename from iris.arff rename to data/iris.arff diff --git a/ArffFiles.cc b/sample/ArffFiles.cc similarity index 100% rename from ArffFiles.cc rename to sample/ArffFiles.cc diff --git a/ArffFiles.h b/sample/ArffFiles.h similarity index 100% rename from ArffFiles.h rename to sample/ArffFiles.h diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..d9f6886 --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(${BayesNet_SOURCE_DIR}/src) +link_directories(${MyProject_SOURCE_DIR}/src) +add_executable(main main.cc ArffFiles.cc CPPFImdlp.cpp Metrics.cpp) +add_executable(test test.cc) +target_link_libraries(main BayesNet "${TORCH_LIBRARIES}") +target_link_libraries(test "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/CPPFImdlp.cpp b/sample/CPPFImdlp.cpp similarity index 100% rename from CPPFImdlp.cpp rename to sample/CPPFImdlp.cpp diff --git a/CPPFImdlp.h b/sample/CPPFImdlp.h similarity index 100% rename from CPPFImdlp.h rename to sample/CPPFImdlp.h diff --git a/Metrics.cpp b/sample/Metrics.cpp similarity index 100% rename from Metrics.cpp rename to sample/Metrics.cpp diff --git a/Metrics.h b/sample/Metrics.h similarity index 100% rename from Metrics.h rename to sample/Metrics.h diff --git a/main copy.cc b/sample/main copy.cc similarity index 100% rename from main copy.cc rename to sample/main copy.cc diff --git a/main.cc b/sample/main.cc similarity index 98% rename from main.cc rename to sample/main.cc index 7003854..167e347 100644 --- a/main.cc +++ b/sample/main.cc @@ -27,7 +27,7 @@ vector discretize(vector& X, mdlp::labels_t& y) int main() { auto handler = ArffFiles(); - handler.load("iris.arff"); + handler.load("data/iris.arff"); // Get Dataset X, y vector& X = handler.getX(); mdlp::labels_t& y = handler.getY(); diff --git a/test.cc b/sample/test.cc similarity index 100% rename from test.cc rename to sample/test.cc diff --git a/typesFImdlp.h b/sample/typesFImdlp.h similarity index 100% rename from typesFImdlp.h rename to sample/typesFImdlp.h diff --git a/simple/Network.cc b/simple/Network.cc deleted file mode 100644 index f16a1dd..0000000 --- a/simple/Network.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include "Network.h" - -namespace bayesnet { - Network::Network() {} - - Network::~Network() - { - for (auto& pair : nodes) { - delete pair.second; - } - } - - void Network::addNode(std::string name) - { - nodes[name] = new Node(name); - } - - void Network::addEdge(std::string parentName, std::string childName) - { - Node* parent = nodes[parentName]; - Node* child = nodes[childName]; - - if (parent == nullptr || child == nullptr) { - throw std::invalid_argument("Parent or child node not found."); - } - - child->addParent(parent); - } - - // to be implemented - void Network::fit(const std::vector>& dataset) - { - // ... learn parameters (i.e., CPTs) using the dataset - } - - // to be implemented - std::vector Network::predict(const std::vector>& testset) - { - std::vector predictions; - // ... use the CPTs and network structure to predict values - return predictions; - } -} - diff --git a/simple/Network.h b/simple/Network.h deleted file mode 100644 index d09ac72..0000000 --- a/simple/Network.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef NETWORK_H -#define NETWORK_H -#include -#include -#include -#include "Node.h" - -namespace bayesnet { - class Network { - private: - std::map nodes; - public: - Network(); - ~Network(); - void addNode(std::string); - void addEdge(std::string, std::string); - void fit(const std::vector>&); - std::vector predict(const std::vector>&); - }; -} -#endif diff --git a/simple/Node.cc b/simple/Node.cc deleted file mode 100644 index 0d04c87..0000000 --- a/simple/Node.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include "Node.h" - -namespace bayesnet { - Node::Node(std::string name) : name(name) {} - - void Node::addParent(Node* parent) - { - parents.push_back(parent); - parent->children.push_back(this); - } -} diff --git a/simple/Node.h b/simple/Node.h deleted file mode 100644 index 7f017f9..0000000 --- a/simple/Node.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef NODE_H -#define NODE_H -#include -#include -#include -namespace bayesnet { - class Node { - private: - std::string name; - std::vector parents; - std::vector children; - std::map, double> cpt; // Conditional Probability Table - public: - Node(std::string); - void addParent(Node*); - }; -} -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..e2b3ce9 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(BayesNet Network.cc Node.cc) +target_link_libraries(BayesNet "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/Network.cc b/src/Network.cc similarity index 100% rename from Network.cc rename to src/Network.cc diff --git a/Network.h b/src/Network.h similarity index 100% rename from Network.h rename to src/Network.h diff --git a/Node.cc b/src/Node.cc similarity index 100% rename from Node.cc rename to src/Node.cc diff --git a/Node.h b/src/Node.h similarity index 100% rename from Node.h rename to src/Node.h