// *************************************************************** // SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez // SPDX-FileType: SOURCE // SPDX-License-Identifier: MIT // *************************************************************** #ifndef NODE_H #define NODE_H #include #include #include #include namespace bayesnet { class Node { public: explicit Node(const std::string&); void clear(); void addParent(Node*); void addChild(Node*); void removeParent(Node*); void removeChild(Node*); std::string getName() const; std::vector& getParents(); std::vector& getChildren(); torch::Tensor& getCPT(); void computeCPT(const torch::Tensor& dataset, const std::vector& features, const double laplaceSmoothing, const torch::Tensor& weights); int getNumStates() const; void setNumStates(int); unsigned minFill(); std::vector graph(const std::string& clasName); // Returns a std::vector of std::strings representing the graph in graphviz format float getFactorValue(std::map&); private: std::string name; std::vector parents; std::vector children; int numStates = 0; // number of states of the variable torch::Tensor cpTable; // Order of indices is 0-> node variable, 1-> 1st parent, 2-> 2nd parent, ... std::vector dimensions; // dimensions of the cpTable std::vector> combinations(const std::vector&); }; } #endif