From 559b3e3b541c9c12d091063ba04c6c1e50b53e11 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Sun, 30 Sep 2012 22:04:44 +0100 Subject: [PATCH] watch out for division by 0 in message calculation for BP --- packages/CLPBN/horus/BeliefProp.cpp | 10 ++++++---- packages/CLPBN/horus/WeightedBp.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/CLPBN/horus/BeliefProp.cpp b/packages/CLPBN/horus/BeliefProp.cpp index ed94e8c12..314f4a6c5 100644 --- a/packages/CLPBN/horus/BeliefProp.cpp +++ b/packages/CLPBN/horus/BeliefProp.cpp @@ -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; diff --git a/packages/CLPBN/horus/WeightedBp.cpp b/packages/CLPBN/horus/WeightedBp.cpp index c4e308d4f..d8a32a246 100644 --- a/packages/CLPBN/horus/WeightedBp.cpp +++ b/packages/CLPBN/horus/WeightedBp.cpp @@ -275,7 +275,7 @@ void WeightedBp::printLinkInformation (void) const { for (size_t i = 0; i < links_.size(); i++) { - WeightedLink* l = static_cast (links_[i]); + WeightedLink* l = static_cast (links_[i]); cout << l->toString() << ":" << endl; cout << " curr msg = " << l->message() << endl; cout << " next msg = " << l->nextMessage() << endl;