From ef4ebb4d7f516e852a50c4f9341eadd27a82c5fd Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Wed, 13 Feb 2013 18:54:15 +0000 Subject: [PATCH] Use camel case for constants and enumerators. All capitals case should be reserved for macros and besides there is no big need to emphasize constness in general. --- packages/CLPBN/horus/BeliefProp.cpp | 44 ++++++------- packages/CLPBN/horus/BeliefProp.h | 8 +-- packages/CLPBN/horus/CountingBp.cpp | 10 +-- packages/CLPBN/horus/ElimGraph.cpp | 12 ++-- packages/CLPBN/horus/ElimGraph.h | 10 +-- packages/CLPBN/horus/FactorGraph.h | 2 +- packages/CLPBN/horus/GroundSolver.cpp | 14 ++--- packages/CLPBN/horus/Horus.h | 18 +++--- packages/CLPBN/horus/HorusCli.cpp | 18 +++--- packages/CLPBN/horus/HorusYap.cpp | 12 ++-- packages/CLPBN/horus/LiftedBp.cpp | 8 +-- packages/CLPBN/horus/LiftedKc.cpp | 76 +++++++++++------------ packages/CLPBN/horus/LiftedKc.h | 18 +++--- packages/CLPBN/horus/LiftedOperations.cpp | 2 +- packages/CLPBN/horus/LiftedWCNF.cpp | 14 ++--- packages/CLPBN/horus/LiftedWCNF.h | 6 +- packages/CLPBN/horus/Util.cpp | 34 +++++----- packages/CLPBN/horus/Util.h | 2 +- packages/CLPBN/horus/Var.h | 4 +- packages/CLPBN/horus/VarElim.cpp | 10 +-- packages/CLPBN/horus/WeightedBp.cpp | 22 +++---- 21 files changed, 172 insertions(+), 172 deletions(-) diff --git a/packages/CLPBN/horus/BeliefProp.cpp b/packages/CLPBN/horus/BeliefProp.cpp index d05acd01d..a5129fa49 100644 --- a/packages/CLPBN/horus/BeliefProp.cpp +++ b/packages/CLPBN/horus/BeliefProp.cpp @@ -62,7 +62,7 @@ BpLink::toString (void) const double BeliefProp::accuracy_ = 0.0001; unsigned BeliefProp::maxIter_ = 1000; -MsgSchedule BeliefProp::schedule_ = MsgSchedule::SEQ_FIXED; +MsgSchedule BeliefProp::schedule_ = MsgSchedule::seqFixedSch; @@ -106,10 +106,10 @@ BeliefProp::printSolverFlags (void) const ss << "belief propagation [" ; ss << "bp_msg_schedule=" ; switch (schedule_) { - case MsgSchedule::SEQ_FIXED: ss << "seq_fixed"; break; - case MsgSchedule::SEQ_RANDOM: ss << "seq_random"; break; - case MsgSchedule::PARALLEL: ss << "parallel"; break; - case MsgSchedule::MAX_RESIDUAL: ss << "max_residual"; break; + case MsgSchedule::seqFixedSch: ss << "seq_fixed"; break; + case MsgSchedule::seqRandomSch: ss << "seq_random"; break; + case MsgSchedule::parallelSch: ss << "parallel"; break; + case MsgSchedule::maxResidualSch: ss << "max_residual"; break; } ss << ",bp_max_iter=" << Util::toString (maxIter_); ss << ",bp_accuracy=" << Util::toString (accuracy_); @@ -259,15 +259,15 @@ BeliefProp::runSolver (void) + Util::toString (nIters_)); } switch (schedule_) { - case MsgSchedule::SEQ_RANDOM: + case MsgSchedule::seqRandomSch: std::random_shuffle (links_.begin(), links_.end()); // no break - case MsgSchedule::SEQ_FIXED: + case MsgSchedule::seqFixedSch: for (size_t i = 0; i < links_.size(); i++) { calculateAndUpdateMessage (links_[i]); } break; - case MsgSchedule::PARALLEL: + case MsgSchedule::parallelSch: for (size_t i = 0; i < links_.size(); i++) { calculateMessage (links_[i]); } @@ -275,7 +275,7 @@ BeliefProp::runSolver (void) updateMessage(links_[i]); } break; - case MsgSchedule::MAX_RESIDUAL: + case MsgSchedule::maxResidualSch: maxResidualSchedule(); break; } @@ -380,13 +380,13 @@ BeliefProp::calcFactorToVarMsg (BpLink* link) if (Globals::logDomain) { for (size_t i = links.size(); i-- > 0; ) { if (links[i]->varNode() != dst) { - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " message from " << links[i]->varNode()->label(); std::cout << ": " ; } Util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]), reps, std::plus()); - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << std::endl; } } @@ -395,13 +395,13 @@ BeliefProp::calcFactorToVarMsg (BpLink* link) } else { for (size_t i = links.size(); i-- > 0; ) { if (links[i]->varNode() != dst) { - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " message from " << links[i]->varNode()->label(); std::cout << ": " ; } Util::apply_n_times (msgProduct, getVarToFactorMsg (links[i]), reps, std::multiplies()); - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << std::endl; } } @@ -411,19 +411,19 @@ BeliefProp::calcFactorToVarMsg (BpLink* link) Factor result (src->factor().arguments(), src->factor().ranges(), msgProduct); result.multiply (src->factor()); - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " message product: " << msgProduct << std::endl; std::cout << " original factor: " << src->factor().params(); std::cout << std::endl; std::cout << " factor product: " << result.params() << std::endl; } result.sumOutAllExcept (dst->varId()); - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " marginalized: " << result.params() << std::endl; } link->nextMessage() = result.params(); LogAware::normalize (link->nextMessage()); - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " curr msg: " << link->message() << std::endl; std::cout << " next msg: " << link->nextMessage() << std::endl; } @@ -442,7 +442,7 @@ BeliefProp::getVarToFactorMsg (const BpLink* link) const } else { msg.resize (src->range(), LogAware::one()); } - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << msg; } BpLinks::const_iterator it; @@ -452,7 +452,7 @@ BeliefProp::getVarToFactorMsg (const BpLink* link) const if (*it != link) { msg += (*it)->message(); } - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " x " << (*it)->message(); } } @@ -461,12 +461,12 @@ BeliefProp::getVarToFactorMsg (const BpLink* link) const if (*it != link) { msg *= (*it)->message(); } - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " x " << (*it)->message(); } } } - if (Constants::SHOW_BP_CALCS) { + if (Constants::showBpCalcs) { std::cout << " = " << msg; } return msg; @@ -478,7 +478,7 @@ Params BeliefProp::getJointByConditioning (const VarIds& jointVarIds) const { return GroundSolver::getJointByConditioning ( - GroundSolverType::BP, fg, jointVarIds); + GroundSolverType::bpSolver, fg, jointVarIds); } @@ -526,7 +526,7 @@ BeliefProp::converged (void) return false; } bool converged = true; - if (schedule_ == MsgSchedule::MAX_RESIDUAL) { + if (schedule_ == MsgSchedule::maxResidualSch) { double maxResidual = (*(sortedOrder_.begin()))->residual(); if (maxResidual > accuracy_) { converged = false; diff --git a/packages/CLPBN/horus/BeliefProp.h b/packages/CLPBN/horus/BeliefProp.h index dbec49860..514a48b0c 100644 --- a/packages/CLPBN/horus/BeliefProp.h +++ b/packages/CLPBN/horus/BeliefProp.h @@ -12,10 +12,10 @@ namespace Horus { enum MsgSchedule { - SEQ_FIXED, - SEQ_RANDOM, - PARALLEL, - MAX_RESIDUAL + seqFixedSch, + seqRandomSch, + parallelSch, + maxResidualSch }; diff --git a/packages/CLPBN/horus/CountingBp.cpp b/packages/CLPBN/horus/CountingBp.cpp index 1a4fbfbf5..0357939f1 100644 --- a/packages/CLPBN/horus/CountingBp.cpp +++ b/packages/CLPBN/horus/CountingBp.cpp @@ -45,10 +45,10 @@ CountingBp::printSolverFlags (void) const ss << "counting bp [" ; ss << "bp_msg_schedule=" ; switch (WeightedBp::msgSchedule()) { - case MsgSchedule::SEQ_FIXED: ss << "seq_fixed"; break; - case MsgSchedule::SEQ_RANDOM: ss << "seq_random"; break; - case MsgSchedule::PARALLEL: ss << "parallel"; break; - case MsgSchedule::MAX_RESIDUAL: ss << "max_residual"; break; + case MsgSchedule::seqFixedSch: ss << "seq_fixed"; break; + case MsgSchedule::seqRandomSch: ss << "seq_random"; break; + case MsgSchedule::parallelSch: ss << "parallel"; break; + case MsgSchedule::maxResidualSch: ss << "max_residual"; break; } ss << ",bp_max_iter=" << WeightedBp::maxIterations(); ss << ",bp_accuracy=" << WeightedBp::accuracy(); @@ -79,7 +79,7 @@ CountingBp::solveQuery (VarIds queryVids) } if (idx == facNodes.size()) { res = GroundSolver::getJointByConditioning ( - GroundSolverType::CBP, fg, queryVids); + GroundSolverType::CbpSolver, fg, queryVids); } else { VarIds reprArgs; for (size_t i = 0; i < queryVids.size(); i++) { diff --git a/packages/CLPBN/horus/ElimGraph.cpp b/packages/CLPBN/horus/ElimGraph.cpp index dc916dcff..82326beda 100644 --- a/packages/CLPBN/horus/ElimGraph.cpp +++ b/packages/CLPBN/horus/ElimGraph.cpp @@ -6,7 +6,7 @@ namespace Horus { -ElimHeuristic ElimGraph::elimHeuristic_ = MIN_NEIGHBORS; +ElimHeuristic ElimGraph::elimHeuristic_ = minNeighborsEh; ElimGraph::ElimGraph (const std::vector& factors) @@ -137,7 +137,7 @@ ElimGraph::getEliminationOrder ( const Factors& factors, VarIds excludedVids) { - if (elimHeuristic_ == ElimHeuristic::SEQUENTIAL) { + if (elimHeuristic_ == ElimHeuristic::sequentialEh) { VarIds allVids; Factors::const_iterator first = factors.begin(); Factors::const_iterator end = factors.end(); @@ -181,7 +181,7 @@ ElimGraph::getLowestCostNode (void) const unsigned minCost = Util::maxUnsigned(); EGNeighs::const_iterator it; switch (elimHeuristic_) { - case MIN_NEIGHBORS: { + case minNeighborsEh: { for (it = unmarked_.begin(); it != unmarked_.end(); ++ it) { unsigned cost = getNeighborsCost (*it); if (cost < minCost) { @@ -190,7 +190,7 @@ ElimGraph::getLowestCostNode (void) const } }} break; - case MIN_WEIGHT: { + case minWeightEh: { for (it = unmarked_.begin(); it != unmarked_.end(); ++ it) { unsigned cost = getWeightCost (*it); if (cost < minCost) { @@ -199,7 +199,7 @@ ElimGraph::getLowestCostNode (void) const } }} break; - case MIN_FILL: { + case minFillEh: { for (it = unmarked_.begin(); it != unmarked_.end(); ++ it) { unsigned cost = getFillCost (*it); if (cost < minCost) { @@ -208,7 +208,7 @@ ElimGraph::getLowestCostNode (void) const } }} break; - case WEIGHTED_MIN_FILL: { + case weightedMinFillEh: { for (it = unmarked_.begin(); it != unmarked_.end(); ++ it) { unsigned cost = getWeightedFillCost (*it); if (cost < minCost) { diff --git a/packages/CLPBN/horus/ElimGraph.h b/packages/CLPBN/horus/ElimGraph.h index c5d6bf823..f62563da9 100644 --- a/packages/CLPBN/horus/ElimGraph.h +++ b/packages/CLPBN/horus/ElimGraph.h @@ -19,11 +19,11 @@ typedef TinySet EGNeighs; enum ElimHeuristic { - SEQUENTIAL, - MIN_NEIGHBORS, - MIN_WEIGHT, - MIN_FILL, - WEIGHTED_MIN_FILL + sequentialEh, + minNeighborsEh, + minWeightEh, + minFillEh, + weightedMinFillEh }; diff --git a/packages/CLPBN/horus/FactorGraph.h b/packages/CLPBN/horus/FactorGraph.h index 272a09834..085e98a97 100644 --- a/packages/CLPBN/horus/FactorGraph.h +++ b/packages/CLPBN/horus/FactorGraph.h @@ -19,7 +19,7 @@ class FacNode; class VarNode : public Var { public: VarNode (VarId varId, unsigned nrStates, - int evidence = Constants::NO_EVIDENCE) + int evidence = Constants::unobserved) : Var (varId, nrStates, evidence) { } VarNode (const Var* v) : Var (v) { } diff --git a/packages/CLPBN/horus/GroundSolver.cpp b/packages/CLPBN/horus/GroundSolver.cpp index 3fee77a3d..987278f96 100644 --- a/packages/CLPBN/horus/GroundSolver.cpp +++ b/packages/CLPBN/horus/GroundSolver.cpp @@ -31,7 +31,7 @@ GroundSolver::printAnswer (const VarIds& vids) Util::getStateLines (unobservedVars); for (size_t i = 0; i < res.size(); i++) { std::cout << "P(" << stateLines[i] << ") = " ; - std::cout << std::setprecision (Constants::PRECISION) << res[i]; + std::cout << std::setprecision (Constants::precision) << res[i]; std::cout << std::endl; } std::cout << std::endl; @@ -66,9 +66,9 @@ GroundSolver::getJointByConditioning ( GroundSolver* solver = 0; switch (solverType) { - case GroundSolverType::BP: solver = new BeliefProp (fg); break; - case GroundSolverType::CBP: solver = new CountingBp (fg); break; - case GroundSolverType::VE: solver = new VarElim (fg); break; + case GroundSolverType::bpSolver: solver = new BeliefProp (fg); break; + case GroundSolverType::CbpSolver: solver = new CountingBp (fg); break; + case GroundSolverType::veSolver: solver = new VarElim (fg); break; } Params prevBeliefs = solver->solveQuery ({jointVarIds[0]}); VarIds observedVids = {jointVars[0]->varId()}; @@ -89,9 +89,9 @@ GroundSolver::getJointByConditioning ( } delete solver; switch (solverType) { - case GroundSolverType::BP: solver = new BeliefProp (fg); break; - case GroundSolverType::CBP: solver = new CountingBp (fg); break; - case GroundSolverType::VE: solver = new VarElim (fg); break; + case GroundSolverType::bpSolver: solver = new BeliefProp (fg); break; + case GroundSolverType::CbpSolver: solver = new CountingBp (fg); break; + case GroundSolverType::veSolver: solver = new VarElim (fg); break; } Params beliefs = solver->solveQuery ({jointVarIds[i]}); for (size_t k = 0; k < beliefs.size(); k++) { diff --git a/packages/CLPBN/horus/Horus.h b/packages/CLPBN/horus/Horus.h index a889b8487..50e7339d3 100644 --- a/packages/CLPBN/horus/Horus.h +++ b/packages/CLPBN/horus/Horus.h @@ -35,16 +35,16 @@ typedef unsigned long long ullong; enum LiftedSolverType { - LVE, // generalized counting first-order variable elimination (GC-FOVE) - LBP, // lifted first-order belief propagation - LKC // lifted first-order knowledge compilation + lveSolver, // generalized counting first-order variable elimination (GC-FOveSolver) + lbpSolver, // lifted first-order belief propagation + lkcSolver // lifted first-order knowledge compilation }; enum GroundSolverType { - VE, // variable elimination - BP, // belief propagation - CBP // counting belief propagation + veSolver, // variable elimination + bpSolver, // belief propagation + CbpSolver // counting belief propagation }; @@ -64,12 +64,12 @@ extern GroundSolverType groundSolver; namespace Constants { // show message calculation for belief propagation -const bool SHOW_BP_CALCS = false; +const bool showBpCalcs = false; -const int NO_EVIDENCE = -1; +const int unobserved = -1; // number of digits to show when printing a parameter -const unsigned PRECISION = 6; +const unsigned precision = 6; } diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index c558d0e72..30ee90226 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -18,7 +18,7 @@ Horus::VarIds readQueryAndEvidence ( void runSolver (const Horus::FactorGraph&, const Horus::VarIds&); -const std::string USAGE = "usage: ./hcli [solver=hve|bp|cbp] \ +const std::string usage = "usage: ./hcli [solver=hve|bp|cbp] \ [