Begin with parameter estimation
This commit is contained in:
22
main.cc
22
main.cc
@@ -11,10 +11,15 @@ using namespace std;
|
||||
vector<mdlp::labels_t> discretize(vector<mdlp::samples_t>& X, mdlp::labels_t& y)
|
||||
{
|
||||
vector<mdlp::labels_t>Xd;
|
||||
|
||||
auto fimdlp = mdlp::CPPFImdlp();
|
||||
for (int i = 0; i < X.size(); i++) {
|
||||
fimdlp.fit(X[i], y);
|
||||
Xd.push_back(fimdlp.transform(X[i]));
|
||||
mdlp::labels_t& xd = fimdlp.transform(X[i]);
|
||||
cout << "X[" << i << "]: ";
|
||||
auto mm = minmax_element(xd.begin(), xd.end());
|
||||
cout << *mm.first << " " << *mm.second << endl;
|
||||
Xd.push_back(xd);
|
||||
}
|
||||
return Xd;
|
||||
}
|
||||
@@ -33,7 +38,7 @@ int main()
|
||||
features.push_back(feature.first);
|
||||
}
|
||||
// Discretize Dataset
|
||||
vector<mdlp::labels_t> Xd = discretize(X, y);;
|
||||
vector<mdlp::labels_t> Xd = discretize(X, y);
|
||||
// Build Network
|
||||
auto network = bayesnet::Network();
|
||||
network.fit(Xd, y, features, className);
|
||||
@@ -53,6 +58,19 @@ int main()
|
||||
cout << "Root: " << network.getRoot()->getName() << endl;
|
||||
network.setRoot(className);
|
||||
cout << "Now Root should be class: " << network.getRoot()->getName() << endl;
|
||||
cout << "CPDs:" << endl;
|
||||
auto nodes = network.getNodes();
|
||||
auto classNode = nodes[className];
|
||||
for (auto it = nodes.begin(); it != nodes.end(); it++) {
|
||||
cout << "* Name: " << it->first << " " << it->second->getName() << " -> " << it->second->getNumStates() << endl;
|
||||
cout << "Parents: ";
|
||||
for (auto parent : it->second->getParents()) {
|
||||
cout << parent->getName() << " -> " << parent->getNumStates() << ", ";
|
||||
}
|
||||
cout << endl;
|
||||
auto cpd = it->second->getCPT();
|
||||
cout << cpd << endl;
|
||||
}
|
||||
cout << "PyTorch version: " << TORCH_VERSION << endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user