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/clpbn/bp/Solver.cpp

38 lines
840 B
C++
Raw Normal View History

2011-12-12 15:29:51 +00:00
#include "Solver.h"
2012-03-22 11:33:24 +00:00
#include "Util.h"
2011-12-12 15:29:51 +00:00
void
2012-04-10 15:00:18 +01:00
Solver::printAnswer (const VarIds& vids)
2011-12-12 15:29:51 +00:00
{
2012-04-10 15:00:18 +01:00
Vars unobservedVars;
VarIds unobservedVids;
for (unsigned i = 0; i < vids.size(); i++) {
2012-04-10 20:43:08 +01:00
VarNode* vn = fg.getVarNode (vids[i]);
2012-04-10 15:00:18 +01:00
if (vn->hasEvidence() == false) {
unobservedVars.push_back (vn);
unobservedVids.push_back (vids[i]);
}
2011-12-12 15:29:51 +00:00
}
2012-04-10 15:00:18 +01:00
Params res = solveQuery (unobservedVids);
vector<string> stateLines = Util::getStateLines (unobservedVars);
for (unsigned i = 0; i < res.size(); i++) {
cout << "P(" << stateLines[i] << ") = " ;
cout << std::setprecision (Constants::PRECISION) << res[i];
2011-12-12 15:29:51 +00:00
cout << endl;
}
cout << endl;
}
void
2012-04-10 15:00:18 +01:00
Solver::printAllPosterioris (void)
2011-12-12 15:29:51 +00:00
{
2012-04-10 20:43:08 +01:00
const VarNodes& vars = fg.varNodes();
2012-04-10 15:00:18 +01:00
for (unsigned i = 0; i < vars.size(); i++) {
printAnswer ({vars[i]->varId()});
2011-12-12 15:29:51 +00:00
}
}