From 5124098b6c140be266bcf72d5f0b851566317756 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 24 May 2012 16:21:41 +0100 Subject: [PATCH] delete unused code --- packages/CLPBN/horus/BpSolver.cpp | 12 -- packages/CLPBN/horus/CbpSolver.cpp | 19 --- packages/CLPBN/horus/Horus.h | 2 - packages/CLPBN/horus/Util.cpp | 183 ----------------------------- packages/CLPBN/horus/Util.h | 62 ---------- 5 files changed, 278 deletions(-) diff --git a/packages/CLPBN/horus/BpSolver.cpp b/packages/CLPBN/horus/BpSolver.cpp index 2494e1a5e..f86610e8e 100644 --- a/packages/CLPBN/horus/BpSolver.cpp +++ b/packages/CLPBN/horus/BpSolver.cpp @@ -145,10 +145,6 @@ BpSolver::getJointDistributionOf (const VarIds& jointVarIds) void BpSolver::runSolver (void) { - clock_t start; - if (Constants::COLLECT_STATS) { - start = clock(); - } initializeSolver(); nIters_ = 0; while (!converged() && nIters_ < BpOptions::maxIter) { @@ -188,14 +184,6 @@ BpSolver::runSolver (void) } cout << endl; } - unsigned size = fg_->varNodes().size(); - if (Constants::COLLECT_STATS) { - unsigned nIters = 0; - bool loopy = fg_->isTree() == false; - if (loopy) nIters = nIters_; - double time = (double (clock() - start)) / CLOCKS_PER_SEC; - Statistics::updateStatistics (size, loopy, nIters, time); - } runned_ = true; } diff --git a/packages/CLPBN/horus/CbpSolver.cpp b/packages/CLPBN/horus/CbpSolver.cpp index f72d9485b..14b1a849d 100644 --- a/packages/CLPBN/horus/CbpSolver.cpp +++ b/packages/CLPBN/horus/CbpSolver.cpp @@ -3,27 +3,8 @@ CbpSolver::CbpSolver (const FactorGraph& fg) : BpSolver (fg) { - unsigned nrGroundVars, nrGroundFacs, nrNeighborless; - if (Constants::COLLECT_STATS) { - nrGroundVars = fg_->varNodes().size(); - nrGroundFacs = fg_->facNodes().size(); - const VarNodes& vars = fg_->varNodes(); - nrNeighborless = 0; - for (unsigned i = 0; i < vars.size(); i++) { - const FacNodes& factors = vars[i]->neighbors(); - if (factors.size() == 1 && factors[0]->neighbors().size() == 1) { - nrNeighborless ++; - } - } - } cfg_ = new CFactorGraph (fg); fg_ = cfg_->getGroundFactorGraph(); - if (Constants::COLLECT_STATS) { - unsigned nrClusterVars = fg_->varNodes().size(); - unsigned nrClusterFacs = fg_->facNodes().size(); - Statistics::updateCompressingStatistics (nrGroundVars, - nrGroundFacs, nrClusterVars, nrClusterFacs, nrNeighborless); - } } diff --git a/packages/CLPBN/horus/Horus.h b/packages/CLPBN/horus/Horus.h index 90f346bfd..7f06f41af 100644 --- a/packages/CLPBN/horus/Horus.h +++ b/packages/CLPBN/horus/Horus.h @@ -59,8 +59,6 @@ const int NO_EVIDENCE = -1; // number of digits to show when printing a parameter const unsigned PRECISION = 6; -const bool COLLECT_STATS = false; - }; diff --git a/packages/CLPBN/horus/Util.cpp b/packages/CLPBN/horus/Util.cpp index 36b0c6f25..a90a9e73d 100644 --- a/packages/CLPBN/horus/Util.cpp +++ b/packages/CLPBN/horus/Util.cpp @@ -30,11 +30,6 @@ unsigned maxIter = 1000; -vector Statistics::netInfo_; -vector Statistics::compressInfo_; -unsigned Statistics::primaryNetCount_; - - namespace Util { @@ -426,181 +421,3 @@ pow (Params& v, double exp) } - - -unsigned -Statistics::getSolvedNetworksCounting (void) -{ - return netInfo_.size(); -} - - - -void -Statistics::incrementPrimaryNetworksCounting (void) -{ - primaryNetCount_ ++; -} - - - -unsigned -Statistics::getPrimaryNetworksCounting (void) -{ - return primaryNetCount_; -} - - - -void -Statistics::updateStatistics ( - unsigned size, - bool loopy, - unsigned nIters, - double time) -{ - netInfo_.push_back (NetInfo (size, loopy, nIters, time)); -} - - - -void -Statistics::printStatistics (void) -{ - cout << getStatisticString(); -} - - - -void -Statistics::writeStatistics (const char* fileName) -{ - ofstream out (fileName); - if (!out.is_open()) { - cerr << "error: cannot open file to write at " ; - cerr << "Statistics::writeStats()" << endl; - abort(); - } - out << getStatisticString(); - out.close(); -} - - - -void -Statistics::updateCompressingStatistics ( - unsigned nrGroundVars, - unsigned nrGroundFactors, - unsigned nrClusterVars, - unsigned nrClusterFactors, - unsigned nrNeighborless) -{ - compressInfo_.push_back (CompressInfo (nrGroundVars, nrGroundFactors, - nrClusterVars, nrClusterFactors, nrNeighborless)); -} - - - -string -Statistics::getStatisticString (void) -{ - stringstream ss2, ss3, ss4, ss1; - ss1 << "running mode: " ; - switch (Globals::infAlgorithm) { - case InfAlgorithms::VE: ss1 << "ve" << endl; break; - case InfAlgorithms::BP: ss1 << "bp" << endl; break; - case InfAlgorithms::CBP: ss1 << "cbp" << endl; break; - } - ss1 << "message schedule: " ; - switch (BpOptions::schedule) { - case BpOptions::Schedule::SEQ_FIXED: - ss1 << "sequential fixed" << endl; - break; - case BpOptions::Schedule::SEQ_RANDOM: - ss1 << "sequential random" << endl; - break; - case BpOptions::Schedule::PARALLEL: - ss1 << "parallel" << endl; - break; - case BpOptions::Schedule::MAX_RESIDUAL: - ss1 << "max residual" << endl; - break; - } - ss1 << "max iterations: " << BpOptions::maxIter << endl; - ss1 << "accuracy " << BpOptions::accuracy << endl; - ss1 << endl << endl; - Util::printSubHeader ("Network information", ss2); - ss2 << left; - ss2 << setw (15) << "Network Size" ; - ss2 << setw (9) << "Loopy" ; - ss2 << setw (15) << "Iterations" ; - ss2 << setw (15) << "Solving Time" ; - ss2 << endl; - unsigned nLoopyNets = 0; - unsigned nUnconvergedRuns = 0; - double totalSolvingTime = 0.0; - for (unsigned i = 0; i < netInfo_.size(); i++) { - ss2 << setw (15) << netInfo_[i].size; - if (netInfo_[i].loopy) { - ss2 << setw (9) << "yes"; - nLoopyNets ++; - } else { - ss2 << setw (9) << "no"; - } - if (netInfo_[i].nIters == 0) { - ss2 << setw (15) << "n/a" ; - } else { - ss2 << setw (15) << netInfo_[i].nIters; - if (netInfo_[i].nIters > BpOptions::maxIter) { - nUnconvergedRuns ++; - } - } - ss2 << setw (15) << netInfo_[i].time; - totalSolvingTime += netInfo_[i].time; - ss2 << endl; - } - ss2 << endl << endl; - - unsigned c1 = 0, c2 = 0, c3 = 0, c4 = 0; - if (compressInfo_.size() > 0) { - Util::printSubHeader ("Compress information", ss3); - ss3 << left; - ss3 << "Ground Cluster Ground Cluster Neighborless" << endl; - ss3 << "Vars Vars Factors Factors Vars" << endl; - for (unsigned i = 0; i < compressInfo_.size(); i++) { - ss3 << setw (9) << compressInfo_[i].nrGroundVars; - ss3 << setw (10) << compressInfo_[i].nrClusterVars; - ss3 << setw (10) << compressInfo_[i].nrGroundFactors; - ss3 << setw (10) << compressInfo_[i].nrClusterFactors; - ss3 << setw (10) << compressInfo_[i].nrNeighborless; - ss3 << endl; - c1 += compressInfo_[i].nrGroundVars - compressInfo_[i].nrNeighborless; - c2 += compressInfo_[i].nrClusterVars; - c3 += compressInfo_[i].nrGroundFactors - compressInfo_[i].nrNeighborless; - c4 += compressInfo_[i].nrClusterFactors; - if (compressInfo_[i].nrNeighborless != 0) { - c2 --; - c4 --; - } - } - ss3 << endl << endl; - } - - ss4 << "primary networks: " << primaryNetCount_ << endl; - ss4 << "solved networks: " << netInfo_.size() << endl; - ss4 << "loopy networks: " << nLoopyNets << endl; - ss4 << "unconverged runs: " << nUnconvergedRuns << endl; - ss4 << "total solving time: " << totalSolvingTime << endl; - if (compressInfo_.size() > 0) { - double pc1 = (1.0 - (c2 / (double)c1)) * 100.0; - double pc2 = (1.0 - (c4 / (double)c3)) * 100.0; - ss4 << setprecision (5); - ss4 << "variable compression: " << pc1 << "%" << endl; - ss4 << "factor compression: " << pc2 << "%" << endl; - } - ss4 << endl << endl; - - ss1 << ss4.str() << ss2.str() << ss3.str(); - return ss1.str(); -} - diff --git a/packages/CLPBN/horus/Util.h b/packages/CLPBN/horus/Util.h index 6f1fae322..72962e1d1 100644 --- a/packages/CLPBN/horus/Util.h +++ b/packages/CLPBN/horus/Util.h @@ -383,67 +383,5 @@ void pow (Params&, double); }; - - -struct NetInfo -{ - NetInfo (unsigned size, bool loopy, unsigned nIters, double time) - { - this->size = size; - this->loopy = loopy; - this->nIters = nIters; - this->time = time; - } - unsigned size; - bool loopy; - unsigned nIters; - double time; -}; - - -struct CompressInfo -{ - CompressInfo (unsigned a, unsigned b, unsigned c, unsigned d, unsigned e) - { - nrGroundVars = a; - nrGroundFactors = b; - nrClusterVars = c; - nrClusterFactors = d; - nrNeighborless = e; - } - unsigned nrGroundVars; - unsigned nrGroundFactors; - unsigned nrClusterVars; - unsigned nrClusterFactors; - unsigned nrNeighborless; -}; - - -class Statistics -{ - public: - static unsigned getSolvedNetworksCounting (void); - - static void incrementPrimaryNetworksCounting (void); - - static unsigned getPrimaryNetworksCounting (void); - - static void updateStatistics (unsigned, bool, unsigned, double); - - static void printStatistics (void); - - static void writeStatistics (const char*); - - static void updateCompressingStatistics ( - unsigned, unsigned, unsigned, unsigned, unsigned); - - private: - static string getStatisticString (void); - - static vector netInfo_; - static vector compressInfo_; - static unsigned primaryNetCount_; -}; - #endif // HORUS_UTIL_H