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