diff --git a/fastlib/trunk/contrib/tqlong/GraphicalModel/factor_template.h b/fastlib/trunk/contrib/tqlong/GraphicalModel/factor_template.h index d059d6d452..e5f9f38299 100644 --- a/fastlib/trunk/contrib/tqlong/GraphicalModel/factor_template.h +++ b/fastlib/trunk/contrib/tqlong/GraphicalModel/factor_template.h @@ -8,6 +8,10 @@ BEGIN_GRAPHICAL_MODEL_NAMESPACE; /** A domain is a list of variables, e.g. x0, x1, ... xn, * which could be the arguments of a function or factor + * Usage: + * Domain dom; + * dom << var1 << var2; + * TableF factor(Domain() << var1 << var2), factor2(dom); */ typedef Vector Domain; @@ -132,14 +136,6 @@ void TableF<_V>::restricted(const Assignment& a) it++; } assignments_.remove_if(RemoveCondition(a)); - // for (typename List::iterator it = assignments_.begin(); it != assignments_.end();) - // { - // const Assignment& b = (*it); - // if (!b.agree(a)) - // assignments_.erase(it++); - // else - // it++; - // } } template diff --git a/fastlib/trunk/contrib/tqlong/GraphicalModel/gm_test.cpp b/fastlib/trunk/contrib/tqlong/GraphicalModel/gm_test.cpp index 4f4c65f1f6..68d5011702 100644 --- a/fastlib/trunk/contrib/tqlong/GraphicalModel/gm_test.cpp +++ b/fastlib/trunk/contrib/tqlong/GraphicalModel/gm_test.cpp @@ -3,13 +3,13 @@ #include "gm.h" using namespace std; -void testNaiveInference(); +void testInference(fx_module*); int main(int argc, char** argv) { -// fx_module* root = fx_init(argc, argv, NULL); - testNaiveInference(); -// fx_done(root); + fx_module* root = fx_init(argc, argv, NULL); + testInference(root); + fx_done(root); } template @@ -37,7 +37,7 @@ void printBelief(const typename Inference::vertex_type& u, // cout << "less = " << (b.size() < 2 ? 0 : b[0] < b[1]) << endl; } -void testNaiveInference() +void testInference(fx_module* module) { typedef gm::ConvergenceMeasure Cvm; typedef gm::FiniteVar Variable; @@ -47,7 +47,7 @@ void testNaiveInference() typedef gm::Logarithm Logarithm; typedef gm::TableF Factor; typedef gm::FactorGraph Graph; - typedef gm::MessagePendingInference Inference; + typedef gm::NaiveInference Inference; typedef Inference::belief_type belief_type; typedef Inference::belief_map_type belief_map_type; // void printBelief(belief_type blf); @@ -109,13 +109,35 @@ void testNaiveInference() // Inference::_Base::_Base bp(fg); // NaiveInference // Inference::_Base bp(fg); // SumProductInference cvm = Cvm(Cvm::Iter) // Inference bp(fg, Cvm(Cvm::Iter|Cvm::Change)); // MessagePriorityInference - gm::NaiveInference bp(fg); -// gm::MessagePendingInference bp(fg, Cvm(Cvm::Iter|Cvm::Change)); -// gm::MessagePriorityInference bp(fg, Cvm(Cvm::Iter|Cvm::Change)); - bp.run(); + const char* method = fx_param_str(module, "method", "naive"); + + belief_map_type beliefs; + if (strcmp(method, "naive") == 0) + { + gm::NaiveInference bp(fg); + bp.run(); + beliefs = bp.beliefs(); + } + else if (strcmp(method, "sum_product") == 0) + { + gm::SumProductInference bp(fg); + bp.run(); + beliefs = bp.beliefs(); + } + else if (strcmp(method, "msg_priority") == 0) + { + gm::MessagePriorityInference bp(fg, Cvm(Cvm::Iter | Cvm::Change)); + bp.run(); + beliefs = bp.beliefs(); + } + else if (strcmp(method, "msg_pending") == 0) + { + gm::MessagePendingInference bp(fg, Cvm(Cvm::Iter | Cvm::Change)); + bp.run(); + beliefs = bp.beliefs(); + } cout << "---------------------- Inference result ----------------------" << endl; - belief_map_type beliefs = bp.beliefs(); BOOST_FOREACH (const belief_map_type::value_type& p, beliefs) { printBelief(p.first, p.second);