Refactor folder structure of the project
This commit is contained in:
parent
52cb85b41b
commit
79e7912ab3
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -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"
|
||||
|
@ -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}")
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(sample)
|
6
sample/CMakeLists.txt
Normal file
6
sample/CMakeLists.txt
Normal file
@ -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}")
|
@ -27,7 +27,7 @@ vector<mdlp::labels_t> discretize(vector<mdlp::samples_t>& X, mdlp::labels_t& y)
|
||||
int main()
|
||||
{
|
||||
auto handler = ArffFiles();
|
||||
handler.load("iris.arff");
|
||||
handler.load("data/iris.arff");
|
||||
// Get Dataset X, y
|
||||
vector<mdlp::samples_t>& X = handler.getX();
|
||||
mdlp::labels_t& y = handler.getY();
|
@ -1,47 +0,0 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#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<std::vector<double>>& dataset)
|
||||
{
|
||||
// ... learn parameters (i.e., CPTs) using the dataset
|
||||
}
|
||||
|
||||
// to be implemented
|
||||
std::vector<double> Network::predict(const std::vector<std::vector<double>>& testset)
|
||||
{
|
||||
std::vector<double> predictions;
|
||||
// ... use the CPTs and network structure to predict values
|
||||
return predictions;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "Node.h"
|
||||
|
||||
namespace bayesnet {
|
||||
class Network {
|
||||
private:
|
||||
std::map<std::string, Node*> nodes;
|
||||
public:
|
||||
Network();
|
||||
~Network();
|
||||
void addNode(std::string);
|
||||
void addEdge(std::string, std::string);
|
||||
void fit(const std::vector<std::vector<double>>&);
|
||||
std::vector<double> predict(const std::vector<std::vector<double>>&);
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#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);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#ifndef NODE_H
|
||||
#define NODE_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
namespace bayesnet {
|
||||
class Node {
|
||||
private:
|
||||
std::string name;
|
||||
std::vector<Node*> parents;
|
||||
std::vector<Node*> children;
|
||||
std::map<std::vector<bool>, double> cpt; // Conditional Probability Table
|
||||
public:
|
||||
Node(std::string);
|
||||
void addParent(Node*);
|
||||
};
|
||||
}
|
||||
#endif
|
2
src/CMakeLists.txt
Normal file
2
src/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
add_library(BayesNet Network.cc Node.cc)
|
||||
target_link_libraries(BayesNet "${TORCH_LIBRARIES}")
|
Loading…
Reference in New Issue
Block a user