From 7ec4887e77ef8b131d4f83b79e2d3f5005c7774e Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Tue, 15 May 2012 16:57:50 +0100 Subject: [PATCH] refactor printing of a parfactor --- packages/CLPBN/clpbn/bp/Parfactor.cpp | 77 +++++++++++++++++---------- packages/CLPBN/clpbn/bp/Parfactor.h | 4 ++ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/packages/CLPBN/clpbn/bp/Parfactor.cpp b/packages/CLPBN/clpbn/bp/Parfactor.cpp index c46072e96..7dca9e670 100644 --- a/packages/CLPBN/clpbn/bp/Parfactor.cpp +++ b/packages/CLPBN/clpbn/bp/Parfactor.cpp @@ -557,35 +557,56 @@ Parfactor::print (bool printParams) const copy.moveToTop (copy.logVarSet().elements()); cout << "Tuples: " << copy.tupleSet() << endl; if (printParams) { - vector jointStrings; - StatesIndexer indexer (ranges_); - while (indexer.valid()) { - stringstream ss; - for (unsigned i = 0; i < args_.size(); i++) { - if (i != 0) ss << ", " ; - if (args_[i].isCounting()) { - unsigned N = constr_->getConditionalCount ( - args_[i].countedLogVar()); - HistogramSet hs (N, args_[i].range()); - unsigned c = 0; - while (c < indexer[i]) { - hs.nextHistogram(); - c ++; - } - ss << hs; - } else { - ss << indexer[i]; - } - } - jointStrings.push_back (ss.str()); - ++ indexer; - } - for (unsigned i = 0; i < params_.size(); i++) { - cout << "f(" << jointStrings[i] << ")" ; - cout << " = " << params_[i] << endl; - } + printParameters(); + } +} + + + +void +Parfactor::printParameters (void) const +{ + vector jointStrings; + StatesIndexer indexer (ranges_); + while (indexer.valid()) { + stringstream ss; + for (unsigned i = 0; i < args_.size(); i++) { + if (i != 0) ss << ", " ; + if (args_[i].isCounting()) { + unsigned N = constr_->getConditionalCount ( + args_[i].countedLogVar()); + HistogramSet hs (N, args_[i].range()); + unsigned c = 0; + while (c < indexer[i]) { + hs.nextHistogram(); + c ++; + } + ss << hs; + } else { + ss << indexer[i]; + } + } + jointStrings.push_back (ss.str()); + ++ indexer; + } + for (unsigned i = 0; i < params_.size(); i++) { + cout << "f(" << jointStrings[i] << ")" ; + cout << " = " << params_[i] << endl; + } +} + + + +void +Parfactor::printProjections (void) const +{ + ConstraintTree copy (*constr_); + + LogVarSet Xs = copy.logVarSet(); + for (unsigned i = 0; i < Xs.size(); i++) { + cout << "-> projection of " << Xs[i] << ": " ; + cout << copy.tupleSet ({Xs[i]}) << endl; } - cout << endl; } diff --git a/packages/CLPBN/clpbn/bp/Parfactor.h b/packages/CLPBN/clpbn/bp/Parfactor.h index 4c206e209..f2bd5257d 100644 --- a/packages/CLPBN/clpbn/bp/Parfactor.h +++ b/packages/CLPBN/clpbn/bp/Parfactor.h @@ -80,6 +80,10 @@ class Parfactor : public TFactor void print (bool = false) const; + void printParameters (void) const; + + void printProjections (void) const; + string getLabel (void) const; private: