BayesNet 1.0.7.
Bayesian Network and basic classifiers Library.
Loading...
Searching...
No Matches
Node.h
1// ***************************************************************
2// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
3// SPDX-FileType: SOURCE
4// SPDX-License-Identifier: MIT
5// ***************************************************************
6
7#ifndef NODE_H
8#define NODE_H
9#include <unordered_set>
10#include <vector>
11#include <string>
12#include <torch/torch.h>
13namespace bayesnet {
14 class Node {
15 public:
16 explicit Node(const std::string&);
17 void clear();
18 void addParent(Node*);
19 void addChild(Node*);
20 void removeParent(Node*);
21 void removeChild(Node*);
22 std::string getName() const;
23 std::vector<Node*>& getParents();
24 std::vector<Node*>& getChildren();
25 torch::Tensor& getCPT();
26 void computeCPT(const torch::Tensor& dataset, const std::vector<std::string>& features, const double smoothing, const torch::Tensor& weights);
27 int getNumStates() const;
28 void setNumStates(int);
29 unsigned minFill();
30 std::vector<std::string> graph(const std::string& clasName); // Returns a std::vector of std::strings representing the graph in graphviz format
31 double getFactorValue(std::map<std::string, int>&);
32 private:
33 std::string name;
34 std::vector<Node*> parents;
35 std::vector<Node*> children;
36 int numStates = 0; // number of states of the variable
37 torch::Tensor cpTable; // Order of indices is 0-> node variable, 1-> 1st parent, 2-> 2nd parent, ...
38 std::vector<int64_t> dimensions; // dimensions of the cpTable
39 std::vector<std::pair<std::string, std::string>> combinations(const std::vector<std::string>&);
40 };
41}
42#endif