Revert "Improve namespace names"
This reverts commit 973df43fe0
.
On a second thought, namespaces are close to classes in the sense that both encapsulate data, so they should both use Pascal case notation.
This commit is contained in:
@@ -26,24 +26,24 @@ WeightedBp::getPosterioriOf (VarId vid)
|
||||
assert (var);
|
||||
Params probs;
|
||||
if (var->hasEvidence()) {
|
||||
probs.resize (var->range(), log_aware::noEvidence());
|
||||
probs[var->getEvidence()] = log_aware::withEvidence();
|
||||
probs.resize (var->range(), LogAware::noEvidence());
|
||||
probs[var->getEvidence()] = LogAware::withEvidence();
|
||||
} else {
|
||||
probs.resize (var->range(), log_aware::multIdenty());
|
||||
probs.resize (var->range(), LogAware::multIdenty());
|
||||
const BpLinks& links = ninf(var)->getLinks();
|
||||
if (globals::logDomain) {
|
||||
if (Globals::logDomain) {
|
||||
for (size_t i = 0; i < links.size(); i++) {
|
||||
WeightedLink* l = static_cast<WeightedLink*> (links[i]);
|
||||
probs += l->powMessage();
|
||||
}
|
||||
log_aware::normalize (probs);
|
||||
util::exp (probs);
|
||||
LogAware::normalize (probs);
|
||||
Util::exp (probs);
|
||||
} else {
|
||||
for (size_t i = 0; i < links.size(); i++) {
|
||||
WeightedLink* l = static_cast<WeightedLink*> (links[i]);
|
||||
probs *= l->powMessage();
|
||||
}
|
||||
log_aware::normalize (probs);
|
||||
LogAware::normalize (probs);
|
||||
}
|
||||
}
|
||||
return probs;
|
||||
@@ -56,7 +56,7 @@ WeightedBp::createLinks (void)
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
if (globals::verbosity > 0) {
|
||||
if (Globals::verbosity > 0) {
|
||||
cout << "compressed factor graph contains " ;
|
||||
cout << fg.nrVarNodes() << " variables and " ;
|
||||
cout << fg.nrFacNodes() << " factors " << endl;
|
||||
@@ -66,7 +66,7 @@ WeightedBp::createLinks (void)
|
||||
for (size_t i = 0; i < facNodes.size(); i++) {
|
||||
const VarNodes& neighs = facNodes[i]->neighbors();
|
||||
for (size_t j = 0; j < neighs.size(); j++) {
|
||||
if (globals::verbosity > 1) {
|
||||
if (Globals::verbosity > 1) {
|
||||
cout << "creating link " ;
|
||||
cout << facNodes[i]->getLabel();
|
||||
cout << " -- " ;
|
||||
@@ -77,7 +77,7 @@ WeightedBp::createLinks (void)
|
||||
facNodes[i], neighs[j], j, weights_[i][j]));
|
||||
}
|
||||
}
|
||||
if (globals::verbosity > 1) {
|
||||
if (Globals::verbosity > 1) {
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ WeightedBp::maxResidualSchedule (void)
|
||||
calculateMessage (links_[i]);
|
||||
SortedOrder::iterator it = sortedOrder_.insert (links_[i]);
|
||||
linkMap_.insert (make_pair (links_[i], it));
|
||||
if (globals::verbosity >= 1) {
|
||||
if (Globals::verbosity >= 1) {
|
||||
std::cout << "calculating " << links_[i]->toString() << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ WeightedBp::maxResidualSchedule (void)
|
||||
}
|
||||
|
||||
for (size_t c = 0; c < links_.size(); c++) {
|
||||
if (globals::verbosity > 1) {
|
||||
if (Globals::verbosity > 1) {
|
||||
std::cout << std::endl << "current residuals:" << std::endl;
|
||||
for (SortedOrder::iterator it = sortedOrder_.begin();
|
||||
it != sortedOrder_.end(); ++it) {
|
||||
@@ -112,7 +112,7 @@ WeightedBp::maxResidualSchedule (void)
|
||||
|
||||
SortedOrder::iterator it = sortedOrder_.begin();
|
||||
BpLink* link = *it;
|
||||
if (globals::verbosity >= 1) {
|
||||
if (Globals::verbosity >= 1) {
|
||||
std::cout << "updating " << (*sortedOrder_.begin())->toString();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ WeightedBp::maxResidualSchedule (void)
|
||||
const BpLinks& links = ninf(factorNeighbors[i])->getLinks();
|
||||
for (size_t j = 0; j < links.size(); j++) {
|
||||
if (links[j]->varNode() != link->varNode()) {
|
||||
if (globals::verbosity > 1) {
|
||||
if (Globals::verbosity > 1) {
|
||||
std::cout << " calculating " << links[j]->toString();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ WeightedBp::maxResidualSchedule (void)
|
||||
const BpLinks& links = ninf(link->facNode())->getLinks();
|
||||
for (size_t i = 0; i < links.size(); i++) {
|
||||
if (links[i]->varNode() != link->varNode()) {
|
||||
if (globals::verbosity > 1) {
|
||||
if (Globals::verbosity > 1) {
|
||||
std::cout << " calculating " << links[i]->toString();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -171,19 +171,19 @@ WeightedBp::calcFactorToVarMsg (BpLink* _link)
|
||||
// calculate the product of messages that were sent
|
||||
// to factor `src', except from var `dst'
|
||||
unsigned reps = 1;
|
||||
unsigned msgSize = util::sizeExpected (src->factor().ranges());
|
||||
Params msgProduct (msgSize, log_aware::multIdenty());
|
||||
if (globals::logDomain) {
|
||||
unsigned msgSize = Util::sizeExpected (src->factor().ranges());
|
||||
Params msgProduct (msgSize, LogAware::multIdenty());
|
||||
if (Globals::logDomain) {
|
||||
for (size_t i = links.size(); i-- > 0; ) {
|
||||
const WeightedLink* l = static_cast<const WeightedLink*> (links[i]);
|
||||
if ( ! (l->varNode() == dst && l->index() == link->index())) {
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " message from " << links[i]->varNode()->label();
|
||||
std::cout << ": " ;
|
||||
}
|
||||
util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]),
|
||||
Util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]),
|
||||
reps, std::plus<double>());
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -193,13 +193,13 @@ WeightedBp::calcFactorToVarMsg (BpLink* _link)
|
||||
for (size_t i = links.size(); i-- > 0; ) {
|
||||
const WeightedLink* l = static_cast<const WeightedLink*> (links[i]);
|
||||
if ( ! (l->varNode() == dst && l->index() == link->index())) {
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " message from " << links[i]->varNode()->label();
|
||||
std::cout << ": " ;
|
||||
}
|
||||
util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]),
|
||||
Util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]),
|
||||
reps, std::multiplies<double>());
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -209,12 +209,12 @@ WeightedBp::calcFactorToVarMsg (BpLink* _link)
|
||||
Factor result (src->factor().arguments(),
|
||||
src->factor().ranges(), msgProduct);
|
||||
assert (msgProduct.size() == src->factor().size());
|
||||
if (globals::logDomain) {
|
||||
if (Globals::logDomain) {
|
||||
result.params() += src->factor().params();
|
||||
} else {
|
||||
result.params() *= src->factor().params();
|
||||
}
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " message product: " ;
|
||||
std::cout << msgProduct << std::endl;
|
||||
std::cout << " original factor: " ;
|
||||
@@ -223,13 +223,13 @@ WeightedBp::calcFactorToVarMsg (BpLink* _link)
|
||||
std::cout << result.params() << std::endl;
|
||||
}
|
||||
result.sumOutAllExceptIndex (link->index());
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " marginalized: " ;
|
||||
std::cout << result.params() << std::endl;
|
||||
}
|
||||
link->nextMessage() = result.params();
|
||||
log_aware::normalize (link->nextMessage());
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
LogAware::normalize (link->nextMessage());
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " curr msg: " ;
|
||||
std::cout << link->message() << std::endl;
|
||||
std::cout << " next msg: " ;
|
||||
@@ -247,22 +247,22 @@ WeightedBp::getVarToFactorMsg (const BpLink* _link) const
|
||||
const FacNode* dst = link->facNode();
|
||||
Params msg;
|
||||
if (src->hasEvidence()) {
|
||||
msg.resize (src->range(), log_aware::noEvidence());
|
||||
msg.resize (src->range(), LogAware::noEvidence());
|
||||
double value = link->message()[src->getEvidence()];
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
msg[src->getEvidence()] = value;
|
||||
std::cout << msg << "^" << link->weight() << "-1" ;
|
||||
}
|
||||
msg[src->getEvidence()] = log_aware::pow (value, link->weight() - 1);
|
||||
msg[src->getEvidence()] = LogAware::pow (value, link->weight() - 1);
|
||||
} else {
|
||||
msg = link->message();
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << msg << "^" << link->weight() << "-1" ;
|
||||
}
|
||||
log_aware::pow (msg, link->weight() - 1);
|
||||
LogAware::pow (msg, link->weight() - 1);
|
||||
}
|
||||
const BpLinks& links = ninf(src)->getLinks();
|
||||
if (globals::logDomain) {
|
||||
if (Globals::logDomain) {
|
||||
for (size_t i = 0; i < links.size(); i++) {
|
||||
WeightedLink* l = static_cast<WeightedLink*> (links[i]);
|
||||
if ( ! (l->facNode() == dst && l->index() == link->index())) {
|
||||
@@ -274,13 +274,13 @@ WeightedBp::getVarToFactorMsg (const BpLink* _link) const
|
||||
WeightedLink* l = static_cast<WeightedLink*> (links[i]);
|
||||
if ( ! (l->facNode() == dst && l->index() == link->index())) {
|
||||
msg *= l->powMessage();
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " x " << l->nextMessage() << "^" << link->weight();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constants::SHOW_BP_CALCS) {
|
||||
if (Constants::SHOW_BP_CALCS) {
|
||||
std::cout << " = " << msg;
|
||||
}
|
||||
return msg;
|
||||
|
Reference in New Issue
Block a user