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
|
|
|
|
Solver::printAllPosterioris (void)
|
|
|
|
{
|
2012-04-05 23:00:48 +01:00
|
|
|
const VarNodes& vars = fg_.varNodes();
|
2011-12-12 15:29:51 +00:00
|
|
|
for (unsigned i = 0; i < vars.size(); i++) {
|
|
|
|
printPosterioriOf (vars[i]->varId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Solver::printPosterioriOf (VarId vid)
|
|
|
|
{
|
2012-04-05 23:00:48 +01:00
|
|
|
VarNode* vn = fg_.getVarNode (vid);
|
2012-03-22 11:33:24 +00:00
|
|
|
const Params& posterioriDist = getPosterioriOf (vid);
|
2012-04-05 23:00:48 +01:00
|
|
|
const States& states = vn->states();
|
2011-12-12 15:29:51 +00:00
|
|
|
for (unsigned i = 0; i < states.size(); i++) {
|
2012-04-05 23:00:48 +01:00
|
|
|
cout << "P(" << vn->label() << "=" << states[i] << ") = " ;
|
2012-03-31 23:27:37 +01:00
|
|
|
cout << setprecision (Constants::PRECISION) << posterioriDist[i];
|
2011-12-12 15:29:51 +00:00
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-03-22 11:33:24 +00:00
|
|
|
Solver::printJointDistributionOf (const VarIds& vids)
|
2011-12-12 15:29:51 +00:00
|
|
|
{
|
2012-04-05 23:00:48 +01:00
|
|
|
Vars vars;
|
2012-03-22 11:33:24 +00:00
|
|
|
VarIds vidsWithoutEvidence;
|
2011-12-12 15:29:51 +00:00
|
|
|
for (unsigned i = 0; i < vids.size(); i++) {
|
2012-04-05 23:00:48 +01:00
|
|
|
VarNode* vn = fg_.getVarNode (vids[i]);
|
|
|
|
if (vn->hasEvidence() == false) {
|
|
|
|
vars.push_back (vn);
|
2011-12-12 15:29:51 +00:00
|
|
|
vidsWithoutEvidence.push_back (vids[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 11:33:24 +00:00
|
|
|
const Params& jointDist = getJointDistributionOf (vidsWithoutEvidence);
|
2011-12-12 15:29:51 +00:00
|
|
|
vector<string> jointStrings = Util::getJointStateStrings (vars);
|
|
|
|
for (unsigned i = 0; i < jointDist.size(); i++) {
|
|
|
|
cout << "P(" << jointStrings[i] << ") = " ;
|
2012-03-31 23:27:37 +01:00
|
|
|
cout << setprecision (Constants::PRECISION) << jointDist[i];
|
2011-12-12 15:29:51 +00:00
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|