Add states as result in Proposal methods
This commit is contained in:
parent
405887f833
commit
182b52a887
@ -15,7 +15,7 @@ namespace bayesnet {
|
||||
// We have discretized the input data
|
||||
// 1st we need to fit the model to build the normal KDB structure, KDB::fit initializes the base Bayesian network
|
||||
KDB::fit(dataset, features, className, states);
|
||||
localDiscretizationProposal(states, model);
|
||||
states = localDiscretizationProposal(states, model);
|
||||
return *this;
|
||||
}
|
||||
Tensor KDBLd::predict(Tensor& X)
|
||||
|
@ -9,12 +9,13 @@ namespace bayesnet {
|
||||
delete value;
|
||||
}
|
||||
}
|
||||
void Proposal::localDiscretizationProposal(map<string, vector<int>>& states, Network& model)
|
||||
map<string, vector<int>> Proposal::localDiscretizationProposal(const map<string, vector<int>>& oldStates, Network& model)
|
||||
{
|
||||
// order of local discretization is important. no good 0, 1, 2...
|
||||
// although we rediscretize features after the local discretization of every feature
|
||||
auto order = model.topological_sort();
|
||||
auto& nodes = model.getNodes();
|
||||
map<string, vector<int>> states = oldStates;
|
||||
vector<int> indicesToReDiscretize;
|
||||
bool upgrade = false; // Flag to check if we need to upgrade the model
|
||||
for (auto feature : order) {
|
||||
@ -66,8 +67,9 @@ namespace bayesnet {
|
||||
}
|
||||
model.fit(pDataset, pFeatures, pClassName, states);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
map<string, vector<int>> Proposal::fit_local_discretization(torch::Tensor& y)
|
||||
map<string, vector<int>> Proposal::fit_local_discretization(const torch::Tensor& y)
|
||||
{
|
||||
// Discretize the continuous input data and build pDataset (Classifier::dataset)
|
||||
int m = Xf.size(1);
|
||||
|
@ -14,8 +14,8 @@ namespace bayesnet {
|
||||
virtual ~Proposal();
|
||||
protected:
|
||||
torch::Tensor prepareX(torch::Tensor& X);
|
||||
void localDiscretizationProposal(map<string, vector<int>>& states, Network& model);
|
||||
map<string, vector<int>> fit_local_discretization(torch::Tensor& y);
|
||||
map<string, vector<int>> localDiscretizationProposal(const map<string, vector<int>>& states, Network& model);
|
||||
map<string, vector<int>> fit_local_discretization(const torch::Tensor& y);
|
||||
torch::Tensor Xf; // X continuous nxm tensor
|
||||
torch::Tensor y; // y discrete nx1 tensor
|
||||
map<string, mdlp::CPPFImdlp*> discretizers;
|
||||
|
@ -15,7 +15,7 @@ namespace bayesnet {
|
||||
// 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);
|
||||
states = localDiscretizationProposal(states, model);
|
||||
return *this;
|
||||
}
|
||||
SPODELd& SPODELd::fit(torch::Tensor& dataset, vector<string>& features_, string className_, map<string, vector<int>>& states_)
|
||||
@ -31,7 +31,7 @@ namespace bayesnet {
|
||||
// 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);
|
||||
states = localDiscretizationProposal(states, model);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace bayesnet {
|
||||
// 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
|
||||
TAN::fit(dataset, features, className, states);
|
||||
localDiscretizationProposal(states, model);
|
||||
states = localDiscretizationProposal(states, model);
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user