From 323444b74ad9fd372ed5e96cb1352808f612e526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Tue, 8 Aug 2023 01:53:41 +0200 Subject: [PATCH] const functions --- .vscode/launch.json | 3 +-- src/BayesNet/AODE.cc | 2 +- src/BayesNet/AODE.h | 2 +- src/BayesNet/AODELd.cc | 31 ++++++++++++++++++++----------- src/BayesNet/AODELd.h | 7 +++---- src/BayesNet/BaseClassifier.h | 14 ++++++++------ src/BayesNet/CMakeLists.txt | 4 +++- src/BayesNet/Classifier.cc | 12 ++++++------ src/BayesNet/Classifier.h | 14 +++++++------- src/BayesNet/Ensemble.cc | 10 +++++----- src/BayesNet/Ensemble.h | 14 +++++++------- src/BayesNet/KDB.cc | 2 +- src/BayesNet/KDB.h | 2 +- src/BayesNet/KDBLd.cc | 2 +- src/BayesNet/KDBLd.h | 2 +- src/BayesNet/Network.cc | 20 ++++++++++++-------- src/BayesNet/Network.h | 17 +++++++++-------- src/BayesNet/Proposal.cc | 9 ++++++--- src/BayesNet/Proposal.h | 1 - src/BayesNet/SPODE.cc | 2 +- src/BayesNet/SPODE.h | 2 +- src/BayesNet/SPODELd.cc | 10 +++++++--- src/BayesNet/SPODELd.h | 4 ++-- src/BayesNet/TAN.cc | 2 +- src/BayesNet/TAN.h | 2 +- src/BayesNet/TANLd.cc | 4 ++-- src/BayesNet/TANLd.h | 2 +- 27 files changed, 109 insertions(+), 87 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8eeff68..7241ae2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,8 +25,7 @@ "program": "${workspaceFolder}/build/src/Platform/main", "args": [ "-m", - "AODE", - "--discretize", + "AODELd", "-p", "/Users/rmontanana/Code/discretizbench/datasets", "--stratified", diff --git a/src/BayesNet/AODE.cc b/src/BayesNet/AODE.cc index 66c71da..7e6a95f 100644 --- a/src/BayesNet/AODE.cc +++ b/src/BayesNet/AODE.cc @@ -9,7 +9,7 @@ namespace bayesnet { models.push_back(std::make_unique(i)); } } - vector AODE::graph(const string& title) + vector AODE::graph(const string& title) const { return Ensemble::graph(title); } diff --git a/src/BayesNet/AODE.h b/src/BayesNet/AODE.h index 5447fc0..3d58851 100644 --- a/src/BayesNet/AODE.h +++ b/src/BayesNet/AODE.h @@ -9,7 +9,7 @@ namespace bayesnet { public: AODE(); virtual ~AODE() {}; - vector graph(const string& title = "AODE") override; + vector graph(const string& title = "AODE") const override; }; } #endif \ No newline at end of file diff --git a/src/BayesNet/AODELd.cc b/src/BayesNet/AODELd.cc index 18e3761..8a656cc 100644 --- a/src/BayesNet/AODELd.cc +++ b/src/BayesNet/AODELd.cc @@ -1,37 +1,46 @@ #include "AODELd.h" +#include "Models.h" namespace bayesnet { using namespace std; AODELd::AODELd() : Ensemble(), Proposal(dataset, features, className) {} AODELd& AODELd::fit(torch::Tensor& X_, torch::Tensor& y_, vector& features_, string className_, map>& states_) { + // This first part should go in a Classifier method called fit_local_discretization o fit_float... features = features_; className = className_; - states = states_; - buildModel(); - trainModel(); - n_models = models.size(); - fitted = true; + Xf = X_; + y = y_; + // Fills vectors Xv & yv with the data from tensors X_ (discretized) & y + fit_local_discretization(states, y); + // We have discretized the input data + // 1st we need to fit the model to build the normal TAN structure, TAN::fit initializes the base Bayesian network + Ensemble::fit(dataset, features, className, states); return *this; + } void AODELd::buildModel() { models.clear(); + cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!" << endl; for (int i = 0; i < features.size(); ++i) { - models.push_back(std::make_unique(i)); + models.push_back(Models::instance().create("SPODELd")); + models[i]->test(); } + n_models = models.size(); } void AODELd::trainModel() { + cout << "dataset: " << dataset.sizes() << endl; + cout << "features: " << features.size() << endl; + cout << "className: " << className << endl; + cout << "states: " << states.size() << endl; for (const auto& model : models) { model->fit(dataset, features, className, states); + model->test(); } } - Tensor AODELd::predict(Tensor& X) - { - return Ensemble::predict(X); - } - vector AODELd::graph(const string& name) + vector AODELd::graph(const string& name) const { return Ensemble::graph(name); } diff --git a/src/BayesNet/AODELd.h b/src/BayesNet/AODELd.h index 74b74b1..14be0c4 100644 --- a/src/BayesNet/AODELd.h +++ b/src/BayesNet/AODELd.h @@ -7,15 +7,14 @@ namespace bayesnet { using namespace std; class AODELd : public Ensemble, public Proposal { - private: + protected: void trainModel() override; void buildModel() override; public: AODELd(); + AODELd& fit(torch::Tensor& X_, torch::Tensor& y_, vector& features_, string className_, map>& states_) override; virtual ~AODELd() = default; - AODELd& fit(torch::Tensor& X, torch::Tensor& y, vector& features, string className, map>& states) override; - vector graph(const string& name = "AODE") override; - Tensor predict(Tensor& X) override; + vector graph(const string& name = "AODE") const override; static inline string version() { return "0.0.1"; }; }; } diff --git a/src/BayesNet/BaseClassifier.h b/src/BayesNet/BaseClassifier.h index e95fafc..ff202e1 100644 --- a/src/BayesNet/BaseClassifier.h +++ b/src/BayesNet/BaseClassifier.h @@ -5,6 +5,8 @@ namespace bayesnet { using namespace std; class BaseClassifier { + protected: + virtual void trainModel() = 0; public: // X is nxm vector, y is nx1 vector virtual BaseClassifier& fit(vector>& X, vector& y, vector& features, string className, map>& states) = 0; @@ -16,14 +18,14 @@ namespace bayesnet { vector virtual predict(vector>& X) = 0; float virtual score(vector>& X, vector& y) = 0; float virtual score(torch::Tensor& X, torch::Tensor& y) = 0; - int virtual getNumberOfNodes() = 0; - int virtual getNumberOfEdges() = 0; - int virtual getNumberOfStates() = 0; - vector virtual show() = 0; - vector virtual graph(const string& title = "") = 0; + int virtual getNumberOfNodes()const = 0; + int virtual getNumberOfEdges()const = 0; + int virtual getNumberOfStates() const = 0; + vector virtual show() const = 0; + vector virtual graph(const string& title = "") const = 0; const string inline getVersion() const { return "0.1.0"; }; vector virtual topological_order() = 0; - void virtual dump_cpt() = 0; + void virtual dump_cpt()const = 0; }; } #endif \ No newline at end of file diff --git a/src/BayesNet/CMakeLists.txt b/src/BayesNet/CMakeLists.txt index 5df47d5..a2b9126 100644 --- a/src/BayesNet/CMakeLists.txt +++ b/src/BayesNet/CMakeLists.txt @@ -1,5 +1,7 @@ include_directories(${BayesNet_SOURCE_DIR}/lib/mdlp) include_directories(${BayesNet_SOURCE_DIR}/lib/Files) +include_directories(${BayesNet_SOURCE_DIR}/src/BayesNet) +include_directories(${BayesNet_SOURCE_DIR}/src/Platform) add_library(BayesNet bayesnetUtils.cc Network.cc Node.cc BayesMetrics.cc Classifier.cc - KDB.cc TAN.cc SPODE.cc Ensemble.cc AODE.cc TANLd.cc KDBLd.cc SPODELd.cc AODELd.cc Mst.cc Proposal.cc) + KDB.cc TAN.cc SPODE.cc Ensemble.cc AODE.cc TANLd.cc KDBLd.cc SPODELd.cc AODELd.cc Mst.cc Proposal.cc ${BayesNet_SOURCE_DIR}/src/Platform/Models.cc) target_link_libraries(BayesNet mdlp ArffFiles "${TORCH_LIBRARIES}") \ No newline at end of file diff --git a/src/BayesNet/Classifier.cc b/src/BayesNet/Classifier.cc index c0f1895..7f41839 100644 --- a/src/BayesNet/Classifier.cc +++ b/src/BayesNet/Classifier.cc @@ -112,7 +112,7 @@ namespace bayesnet { } return model.score(X, y); } - vector Classifier::show() + vector Classifier::show() const { return model.show(); } @@ -124,16 +124,16 @@ namespace bayesnet { } model.addNode(className); } - int Classifier::getNumberOfNodes() + int Classifier::getNumberOfNodes() const { // Features does not include class return fitted ? model.getFeatures().size() + 1 : 0; } - int Classifier::getNumberOfEdges() + int Classifier::getNumberOfEdges() const { - return fitted ? model.getEdges().size() : 0; + return fitted ? model.getNumEdges() : 0; } - int Classifier::getNumberOfStates() + int Classifier::getNumberOfStates() const { return fitted ? model.getStates() : 0; } @@ -141,7 +141,7 @@ namespace bayesnet { { return model.topological_sort(); } - void Classifier::dump_cpt() + void Classifier::dump_cpt() const { model.dump_cpt(); } diff --git a/src/BayesNet/Classifier.h b/src/BayesNet/Classifier.h index 7e88bd3..2e736a3 100644 --- a/src/BayesNet/Classifier.h +++ b/src/BayesNet/Classifier.h @@ -23,7 +23,7 @@ namespace bayesnet { map> states; void checkFitParameters(); virtual void buildModel() = 0; - virtual void trainModel(); + void trainModel() override; public: Classifier(Network model); virtual ~Classifier() = default; @@ -31,16 +31,16 @@ namespace bayesnet { Classifier& fit(torch::Tensor& X, torch::Tensor& y, vector& features, string className, map>& states) override; Classifier& fit(torch::Tensor& dataset, vector& features, string className, map>& states) override; void addNodes(); - int getNumberOfNodes() override; - int getNumberOfEdges() override; - int getNumberOfStates() override; + int getNumberOfNodes() const override; + int getNumberOfEdges() const override; + int getNumberOfStates() const override; Tensor predict(Tensor& X) override; vector predict(vector>& X) override; float score(Tensor& X, Tensor& y) override; float score(vector>& X, vector& y) override; - vector show() override; - vector topological_order() override; - void dump_cpt() override; + vector show() const override; + vector topological_order() override; + void dump_cpt() const override; }; } #endif diff --git a/src/BayesNet/Ensemble.cc b/src/BayesNet/Ensemble.cc index d38430d..34c6894 100644 --- a/src/BayesNet/Ensemble.cc +++ b/src/BayesNet/Ensemble.cc @@ -94,7 +94,7 @@ namespace bayesnet { } return (double)correct / y_pred.size(); } - vector Ensemble::show() + vector Ensemble::show() const { auto result = vector(); for (auto i = 0; i < n_models; ++i) { @@ -103,7 +103,7 @@ namespace bayesnet { } return result; } - vector Ensemble::graph(const string& title) + vector Ensemble::graph(const string& title) const { auto result = vector(); for (auto i = 0; i < n_models; ++i) { @@ -112,7 +112,7 @@ namespace bayesnet { } return result; } - int Ensemble::getNumberOfNodes() + int Ensemble::getNumberOfNodes() const { int nodes = 0; for (auto i = 0; i < n_models; ++i) { @@ -120,7 +120,7 @@ namespace bayesnet { } return nodes; } - int Ensemble::getNumberOfEdges() + int Ensemble::getNumberOfEdges() const { int edges = 0; for (auto i = 0; i < n_models; ++i) { @@ -128,7 +128,7 @@ namespace bayesnet { } return edges; } - int Ensemble::getNumberOfStates() + int Ensemble::getNumberOfStates() const { int nstates = 0; for (auto i = 0; i < n_models; ++i) { diff --git a/src/BayesNet/Ensemble.h b/src/BayesNet/Ensemble.h index f36d1ad..f0d750b 100644 --- a/src/BayesNet/Ensemble.h +++ b/src/BayesNet/Ensemble.h @@ -23,16 +23,16 @@ namespace bayesnet { vector predict(vector>& X) override; float score(Tensor& X, Tensor& y) override; float score(vector>& X, vector& y) override; - int getNumberOfNodes() override; - int getNumberOfEdges() override; - int getNumberOfStates() override; - vector show() override; - vector graph(const string& title) override; - vector topological_order() override + int getNumberOfNodes() const override; + int getNumberOfEdges() const override; + int getNumberOfStates() const override; + vector show() const override; + vector graph(const string& title) const override; + vector topological_order() override { return vector(); } - void dump_cpt() override + void dump_cpt() const override { } }; diff --git a/src/BayesNet/KDB.cc b/src/BayesNet/KDB.cc index 6988671..74566b0 100644 --- a/src/BayesNet/KDB.cc +++ b/src/BayesNet/KDB.cc @@ -79,7 +79,7 @@ namespace bayesnet { exit_cond = num == n_edges || candidates.size(0) == 0; } } - vector KDB::graph(const string& title) + vector KDB::graph(const string& title) const { string header{ title }; if (title == "KDB") { diff --git a/src/BayesNet/KDB.h b/src/BayesNet/KDB.h index 028bee8..e7af8c5 100644 --- a/src/BayesNet/KDB.h +++ b/src/BayesNet/KDB.h @@ -15,7 +15,7 @@ namespace bayesnet { public: explicit KDB(int k, float theta = 0.03); virtual ~KDB() {}; - vector graph(const string& name = "KDB") override; + vector graph(const string& name = "KDB") const override; }; } #endif \ No newline at end of file diff --git a/src/BayesNet/KDBLd.cc b/src/BayesNet/KDBLd.cc index 63344af..4b8b91c 100644 --- a/src/BayesNet/KDBLd.cc +++ b/src/BayesNet/KDBLd.cc @@ -23,7 +23,7 @@ namespace bayesnet { auto Xt = prepareX(X); return KDB::predict(Xt); } - vector KDBLd::graph(const string& name) + vector KDBLd::graph(const string& name) const { return KDB::graph(name); } diff --git a/src/BayesNet/KDBLd.h b/src/BayesNet/KDBLd.h index b91999b..50a1b95 100644 --- a/src/BayesNet/KDBLd.h +++ b/src/BayesNet/KDBLd.h @@ -11,7 +11,7 @@ namespace bayesnet { explicit KDBLd(int k); virtual ~KDBLd() = default; KDBLd& fit(torch::Tensor& X, torch::Tensor& y, vector& features, string className, map>& states) override; - vector graph(const string& name = "KDB") override; + vector graph(const string& name = "KDB") const override; Tensor predict(Tensor& X) override; static inline string version() { return "0.0.1"; }; }; diff --git a/src/BayesNet/Network.cc b/src/BayesNet/Network.cc index 5b6307a..59903f3 100644 --- a/src/BayesNet/Network.cc +++ b/src/BayesNet/Network.cc @@ -43,15 +43,15 @@ namespace bayesnet { } nodes[name] = std::make_unique(name); } - vector Network::getFeatures() + vector Network::getFeatures() const { return features; } - int Network::getClassNumStates() + int Network::getClassNumStates() const { return classNumStates; } - int Network::getStates() + int Network::getStates() const { int result = 0; for (auto& node : nodes) { @@ -59,7 +59,7 @@ namespace bayesnet { } return result; } - string Network::getClassName() + string Network::getClassName() const { return className; } @@ -343,7 +343,7 @@ namespace bayesnet { transform(result.begin(), result.end(), result.begin(), [sum](double& value) { return value / sum; }); return result; } - vector Network::show() + vector Network::show() const { vector result; // Draw the network @@ -356,7 +356,7 @@ namespace bayesnet { } return result; } - vector Network::graph(const string& title) + vector Network::graph(const string& title) const { auto output = vector(); auto prefix = "digraph BayesNet {\nlabel=> Network::getEdges() + vector> Network::getEdges() const { auto edges = vector>(); for (const auto& node : nodes) { @@ -382,6 +382,10 @@ namespace bayesnet { } return edges; } + int Network::getNumEdges() const + { + return getEdges().size(); + } vector Network::topological_sort() { /* Check if al the fathers of every node are before the node */ @@ -420,7 +424,7 @@ namespace bayesnet { } return result; } - void Network::dump_cpt() + void Network::dump_cpt() const { for (auto& node : nodes) { cout << "* " << node.first << ": (" << node.second->getNumStates() << ") : " << node.second->getCPT().sizes() << endl; diff --git a/src/BayesNet/Network.h b/src/BayesNet/Network.h index 616235a..eb65957 100644 --- a/src/BayesNet/Network.h +++ b/src/BayesNet/Network.h @@ -37,11 +37,12 @@ namespace bayesnet { void addNode(const string&); void addEdge(const string&, const string&); map>& getNodes(); - vector getFeatures(); - int getStates(); - vector> getEdges(); - int getClassNumStates(); - string getClassName(); + vector getFeatures() const; + int getStates() const; + vector> getEdges() const; + int getNumEdges() const; + int getClassNumStates() const; + string getClassName() const; void fit(const vector>&, const vector&, const vector&, const string&); void fit(const torch::Tensor&, const torch::Tensor&, const vector&, const string&); void fit(const torch::Tensor&, const vector&, const string&); @@ -54,10 +55,10 @@ namespace bayesnet { torch::Tensor predict_proba(const torch::Tensor&); // Return mxn tensor of probabilities double score(const vector>&, const vector&); vector topological_sort(); - vector show(); - vector graph(const string& title); // Returns a vector of strings representing the graph in graphviz format + vector show() const; + vector graph(const string& title) const; // Returns a vector of strings representing the graph in graphviz format void initialize(); - void dump_cpt(); + void dump_cpt() const; inline string version() { return "0.1.0"; } }; } diff --git a/src/BayesNet/Proposal.cc b/src/BayesNet/Proposal.cc index 19992c6..80cb7ee 100644 --- a/src/BayesNet/Proposal.cc +++ b/src/BayesNet/Proposal.cc @@ -2,7 +2,7 @@ #include "ArffFiles.h" namespace bayesnet { - Proposal::Proposal(torch::Tensor& dataset_, vector& features_, string& className_) : pDataset(dataset_), pFeatures(features_), pClassName(className_), m(dataset_.size(1)), n(dataset_.size(0) - 1) {} + Proposal::Proposal(torch::Tensor& dataset_, vector& features_, string& className_) : pDataset(dataset_), pFeatures(features_), pClassName(className_) {} Proposal::~Proposal() { for (auto& [key, value] : discretizers) { @@ -32,9 +32,9 @@ namespace bayesnet { indices.push_back(-1); // Add class index transform(parents.begin(), parents.end(), back_inserter(indices), [&](const auto& p) {return find(pFeatures.begin(), pFeatures.end(), p) - pFeatures.begin(); }); // Now we fit the discretizer of the feature, conditioned on its parents and the class i.e. discretizer.fit(X[index], X[indices] + y) - vector yJoinParents(indices.size()); + vector yJoinParents(Xf.size(1)); for (auto idx : indices) { - for (int i = 0; i < n; ++i) { + for (int i = 0; i < Xf.size(1); ++i) { yJoinParents[i] += to_string(pDataset.index({ idx, i }).item()); } } @@ -64,10 +64,13 @@ namespace bayesnet { //Update new states of the feature/node states[pFeatures[index]] = xStates; } + model.fit(pDataset, pFeatures, pClassName); } } void Proposal::fit_local_discretization(map>& states, torch::Tensor& y) { + int m = Xf.size(1); + int n = Xf.size(0); pDataset = torch::zeros({ n + 1, m }, kInt32); auto yv = vector(y.data_ptr(), y.data_ptr() + y.size(0)); // discretize input data by feature(row) diff --git a/src/BayesNet/Proposal.h b/src/BayesNet/Proposal.h index 606ed5a..06d9dd6 100644 --- a/src/BayesNet/Proposal.h +++ b/src/BayesNet/Proposal.h @@ -19,7 +19,6 @@ namespace bayesnet { torch::Tensor Xf; // X continuous nxm tensor torch::Tensor y; // y discrete nx1 tensor map discretizers; - int m, n; private: torch::Tensor& pDataset; // (n+1)xm tensor vector& pFeatures; diff --git a/src/BayesNet/SPODE.cc b/src/BayesNet/SPODE.cc index eba6542..a90e5ef 100644 --- a/src/BayesNet/SPODE.cc +++ b/src/BayesNet/SPODE.cc @@ -17,7 +17,7 @@ namespace bayesnet { } } } - vector SPODE::graph(const string& name) + vector SPODE::graph(const string& name) const { return model.graph(name); } diff --git a/src/BayesNet/SPODE.h b/src/BayesNet/SPODE.h index d441e66..f9b6af0 100644 --- a/src/BayesNet/SPODE.h +++ b/src/BayesNet/SPODE.h @@ -11,7 +11,7 @@ namespace bayesnet { public: explicit SPODE(int root); virtual ~SPODE() {}; - vector graph(const string& name = "SPODE") override; + vector graph(const string& name = "SPODE") const override; }; } #endif \ No newline at end of file diff --git a/src/BayesNet/SPODELd.cc b/src/BayesNet/SPODELd.cc index 8b9fe2f..8c47df1 100644 --- a/src/BayesNet/SPODELd.cc +++ b/src/BayesNet/SPODELd.cc @@ -2,10 +2,11 @@ namespace bayesnet { using namespace std; - SPODELd::SPODELd(int root) : SPODE(root), Proposal(dataset, features, className) {} + SPODELd::SPODELd(int root) : SPODE(root), Proposal(dataset, features, className) { cout << "SPODELd constructor" << endl; } SPODELd& SPODELd::fit(torch::Tensor& X_, torch::Tensor& y_, vector& features_, string className_, map>& states_) { // This first part should go in a Classifier method called fit_local_discretization o fit_float... + cout << "YOOOOOOOOOOOOOOOOOOOo" << endl; features = features_; className = className_; Xf = X_; @@ -16,7 +17,6 @@ namespace bayesnet { // 1st we need to fit the model to build the normal SPODE structure, SPODE::fit initializes the base Bayesian network SPODE::fit(dataset, features, className, states); localDiscretizationProposal(states, model); - //model.fit(SPODE::Xv, SPODE::yv, features, className); return *this; } Tensor SPODELd::predict(Tensor& X) @@ -24,7 +24,11 @@ namespace bayesnet { auto Xt = prepareX(X); return SPODE::predict(Xt); } - vector SPODELd::graph(const string& name) + void SPODELd::test() + { + cout << "SPODELd test" << endl; + } + vector SPODELd::graph(const string& name) const { return SPODE::graph(name); } diff --git a/src/BayesNet/SPODELd.h b/src/BayesNet/SPODELd.h index 789af7f..f949c09 100644 --- a/src/BayesNet/SPODELd.h +++ b/src/BayesNet/SPODELd.h @@ -6,12 +6,12 @@ namespace bayesnet { using namespace std; class SPODELd : public SPODE, public Proposal { - private: public: + void test(); explicit SPODELd(int root); virtual ~SPODELd() = default; SPODELd& fit(torch::Tensor& X, torch::Tensor& y, vector& features, string className, map>& states) override; - vector graph(const string& name = "SPODE") override; + vector graph(const string& name = "SPODE") const override; Tensor predict(Tensor& X) override; static inline string version() { return "0.0.1"; }; }; diff --git a/src/BayesNet/TAN.cc b/src/BayesNet/TAN.cc index c77275c..7b3e3a6 100644 --- a/src/BayesNet/TAN.cc +++ b/src/BayesNet/TAN.cc @@ -34,7 +34,7 @@ namespace bayesnet { model.addEdge(className, feature); } } - vector TAN::graph(const string& title) + vector TAN::graph(const string& title) const { return model.graph(title); } diff --git a/src/BayesNet/TAN.h b/src/BayesNet/TAN.h index 6d95e21..4c1c5f5 100644 --- a/src/BayesNet/TAN.h +++ b/src/BayesNet/TAN.h @@ -11,7 +11,7 @@ namespace bayesnet { public: TAN(); virtual ~TAN() {}; - vector graph(const string& name = "TAN") override; + vector graph(const string& name = "TAN") const override; }; } #endif \ No newline at end of file diff --git a/src/BayesNet/TANLd.cc b/src/BayesNet/TANLd.cc index 49ffa96..dba803c 100644 --- a/src/BayesNet/TANLd.cc +++ b/src/BayesNet/TANLd.cc @@ -16,15 +16,15 @@ namespace bayesnet { // 1st we need to fit the model to build the normal TAN structure, TAN::fit initializes the base Bayesian network TAN::fit(dataset, features, className, states); localDiscretizationProposal(states, model); - //model.fit(dataset, features, className); return *this; + } Tensor TANLd::predict(Tensor& X) { auto Xt = prepareX(X); return TAN::predict(Xt); } - vector TANLd::graph(const string& name) + vector TANLd::graph(const string& name) const { return TAN::graph(name); } diff --git a/src/BayesNet/TANLd.h b/src/BayesNet/TANLd.h index d9172ac..c35e843 100644 --- a/src/BayesNet/TANLd.h +++ b/src/BayesNet/TANLd.h @@ -11,7 +11,7 @@ namespace bayesnet { TANLd(); virtual ~TANLd() = default; TANLd& fit(torch::Tensor& X, torch::Tensor& y, vector& features, string className, map>& states) override; - vector graph(const string& name = "TAN") override; + vector graph(const string& name = "TAN") const override; Tensor predict(Tensor& X) override; static inline string version() { return "0.0.1"; }; };