Spodeld working with poor accuracy

This commit is contained in:
Ricardo Montañana Gómez 2023-08-10 02:06:18 +02:00
parent 323444b74a
commit 0ad5505c16
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
3 changed files with 21 additions and 16 deletions

View File

@ -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<SPODELd>(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<string> AODELd::graph(const string& name) const

View File

@ -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<string>& features_, string className_, map<string, vector<int>>& 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<string>& features_, string className_, map<string, vector<int>>& 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<string> SPODELd::graph(const string& name) const
{
return SPODE::graph(name);

View File

@ -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<string>& features, string className, map<string, vector<int>>& states) override;
SPODELd& fit(torch::Tensor& dataset, vector<string>& features, string className, map<string, vector<int>>& states) override;
vector<string> graph(const string& name = "SPODE") const override;
Tensor predict(Tensor& X) override;
static inline string version() { return "0.0.1"; };