Spodeld working with poor accuracy
This commit is contained in:
parent
323444b74a
commit
0ad5505c16
@ -22,22 +22,15 @@ namespace bayesnet {
|
|||||||
void AODELd::buildModel()
|
void AODELd::buildModel()
|
||||||
{
|
{
|
||||||
models.clear();
|
models.clear();
|
||||||
cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!" << endl;
|
|
||||||
for (int i = 0; i < features.size(); ++i) {
|
for (int i = 0; i < features.size(); ++i) {
|
||||||
models.push_back(Models::instance().create("SPODELd"));
|
models.push_back(std::make_unique<SPODELd>(i));
|
||||||
models[i]->test();
|
|
||||||
}
|
}
|
||||||
n_models = models.size();
|
n_models = models.size();
|
||||||
}
|
}
|
||||||
void AODELd::trainModel()
|
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) {
|
for (const auto& model : models) {
|
||||||
model->fit(dataset, features, className, states);
|
model->fit(Xf, y, features, className, states);
|
||||||
model->test();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vector<string> AODELd::graph(const string& name) const
|
vector<string> AODELd::graph(const string& name) const
|
||||||
|
@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
namespace bayesnet {
|
namespace bayesnet {
|
||||||
using namespace std;
|
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_)
|
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...
|
// This first part should go in a Classifier method called fit_local_discretization o fit_float...
|
||||||
cout << "YOOOOOOOOOOOOOOOOOOOo" << endl;
|
|
||||||
features = features_;
|
features = features_;
|
||||||
className = className_;
|
className = className_;
|
||||||
Xf = X_;
|
Xf = X_;
|
||||||
@ -19,15 +18,28 @@ namespace bayesnet {
|
|||||||
localDiscretizationProposal(states, model);
|
localDiscretizationProposal(states, model);
|
||||||
return *this;
|
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)
|
Tensor SPODELd::predict(Tensor& X)
|
||||||
{
|
{
|
||||||
auto Xt = prepareX(X);
|
auto Xt = prepareX(X);
|
||||||
return SPODE::predict(Xt);
|
return SPODE::predict(Xt);
|
||||||
}
|
}
|
||||||
void SPODELd::test()
|
|
||||||
{
|
|
||||||
cout << "SPODELd test" << endl;
|
|
||||||
}
|
|
||||||
vector<string> SPODELd::graph(const string& name) const
|
vector<string> SPODELd::graph(const string& name) const
|
||||||
{
|
{
|
||||||
return SPODE::graph(name);
|
return SPODE::graph(name);
|
||||||
|
@ -7,10 +7,10 @@ namespace bayesnet {
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
class SPODELd : public SPODE, public Proposal {
|
class SPODELd : public SPODE, public Proposal {
|
||||||
public:
|
public:
|
||||||
void test();
|
|
||||||
explicit SPODELd(int root);
|
explicit SPODELd(int root);
|
||||||
virtual ~SPODELd() = default;
|
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& 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;
|
vector<string> graph(const string& name = "SPODE") const override;
|
||||||
Tensor predict(Tensor& X) override;
|
Tensor predict(Tensor& X) override;
|
||||||
static inline string version() { return "0.0.1"; };
|
static inline string version() { return "0.0.1"; };
|
||||||
|
Loading…
Reference in New Issue
Block a user