watch out for division by 0 in message calculation for BP

This commit is contained in:
Tiago Gomes 2012-09-30 22:04:44 +01:00
parent fec0bd44b4
commit 559b3e3b54
2 changed files with 7 additions and 5 deletions

View File

@ -349,20 +349,22 @@ BeliefProp::getVarToFactorMsg (const BpLink* link) const
const BpLinks& links = ninf (src)->getLinks();
if (Globals::logDomain) {
for (it = links.begin(); it != links.end(); ++it) {
msg += (*it)->message();
if (*it != link) {
msg += (*it)->message();
}
if (Constants::SHOW_BP_CALCS) {
cout << " x " << (*it)->message();
}
}
msg -= link->message();
} else {
for (it = links.begin(); it != links.end(); ++it) {
msg *= (*it)->message();
if (*it != link) {
msg *= (*it)->message();
}
if (Constants::SHOW_BP_CALCS) {
cout << " x " << (*it)->message();
}
}
msg /= link->message();
}
if (Constants::SHOW_BP_CALCS) {
cout << " = " << msg;

View File

@ -275,7 +275,7 @@ void
WeightedBp::printLinkInformation (void) const
{
for (size_t i = 0; i < links_.size(); i++) {
WeightedLink* l = static_cast<WeightedLink*> (links_[i]);
WeightedLink* l = static_cast<WeightedLink*> (links_[i]);
cout << l->toString() << ":" << endl;
cout << " curr msg = " << l->message() << endl;
cout << " next msg = " << l->nextMessage() << endl;