diff --git a/src/BayesNet/AODELd.cc b/src/BayesNet/AODELd.cc index 8a656cc..fbfaefd 100644 --- a/src/BayesNet/AODELd.cc +++ b/src/BayesNet/AODELd.cc @@ -22,22 +22,15 @@ namespace bayesnet { void AODELd::buildModel() { models.clear(); - cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!" << endl; for (int i = 0; i < features.size(); ++i) { - models.push_back(Models::instance().create("SPODELd")); - models[i]->test(); + models.push_back(std::make_unique(i)); } 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(); + model->fit(Xf, y, features, className, states); } } vector AODELd::graph(const string& name) const diff --git a/src/BayesNet/SPODELd.cc b/src/BayesNet/SPODELd.cc index 8c47df1..0e58775 100644 --- a/src/BayesNet/SPODELd.cc +++ b/src/BayesNet/SPODELd.cc @@ -2,11 +2,10 @@ namespace bayesnet { using namespace std; - SPODELd::SPODELd(int root) : SPODE(root), Proposal(dataset, features, className) { cout << "SPODELd constructor" << endl; } + SPODELd::SPODELd(int root) : SPODE(root), Proposal(dataset, features, className) {} 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_; @@ -19,15 +18,28 @@ namespace bayesnet { localDiscretizationProposal(states, model); return *this; } + SPODELd& SPODELd::fit(torch::Tensor& dataset, vector& features_, string className_, map>& states_) + { + Xf = dataset.index({ torch::indexing::Slice(0, dataset.size(0) - 1), "..." }).clone(); + cout << "Xf " << Xf.sizes() << " dtype: " << Xf.dtype() << endl; + y = dataset.index({ -1, "..." }).clone(); + // This first part should go in a Classifier method called fit_local_discretization o fit_float... + features = features_; + className = className_; + // 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 SPODE structure, SPODE::fit initializes the base Bayesian network + SPODE::fit(dataset, features, className, states); + localDiscretizationProposal(states, model); + return *this; + } + Tensor SPODELd::predict(Tensor& X) { auto Xt = prepareX(X); return SPODE::predict(Xt); } - 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 f949c09..b94fc6c 100644 --- a/src/BayesNet/SPODELd.h +++ b/src/BayesNet/SPODELd.h @@ -7,10 +7,10 @@ namespace bayesnet { using namespace std; class SPODELd : public SPODE, public Proposal { 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; + SPODELd& fit(torch::Tensor& dataset, vector& features, string className, map>& states) override; vector graph(const string& name = "SPODE") const override; Tensor predict(Tensor& X) override; static inline string version() { return "0.0.1"; };