This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/CLPBN/horus/Solver.cpp

41 lines
943 B
C++
Raw Normal View History

2012-05-23 14:56:01 +01:00
#include "Solver.h"
#include "Util.h"
void
Solver::printAnswer (const VarIds& vids)
{
Vars unobservedVars;
VarIds unobservedVids;
2012-05-24 22:55:20 +01:00
for (size_t i = 0; i < vids.size(); i++) {
2012-05-23 14:56:01 +01:00
VarNode* vn = fg.getVarNode (vids[i]);
if (vn->hasEvidence() == false) {
unobservedVars.push_back (vn);
unobservedVids.push_back (vids[i]);
}
}
2012-05-28 18:26:15 +01:00
if (unobservedVids.empty() == false) {
Params res = solveQuery (unobservedVids);
vector<string> stateLines = Util::getStateLines (unobservedVars);
for (size_t i = 0; i < res.size(); i++) {
cout << "P(" << stateLines[i] << ") = " ;
cout << std::setprecision (Constants::PRECISION) << res[i];
cout << endl;
}
2012-05-23 14:56:01 +01:00
cout << endl;
}
}
void
Solver::printAllPosterioris (void)
{
2012-05-28 18:26:15 +01:00
VarNodes vars = fg.varNodes();
std::sort (vars.begin(), vars.end(), sortByVarId());
2012-05-24 22:55:20 +01:00
for (size_t i = 0; i < vars.size(); i++) {
2012-05-28 18:26:15 +01:00
printAnswer ({vars[i]->varId()});
2012-05-23 14:56:01 +01:00
}
}