OpenGM  2.3.x
Discrete Graphical Model Library
junction_tree.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_LIBDAI_JUNCTION_TREE_HXX
2 #define OPENGM_LIBDAI_JUNCTION_TREE_HXX
3 
5 
7 
8 namespace opengm{
9 namespace external{
10 namespace libdai{
11 
25 template<class GM,class ACC>
26 class JunctionTree : public LibDaiInference<GM,ACC,JunctionTree<GM,ACC> > , public opengm::Inference<GM,ACC>{
27  public:
28  typedef ACC AccumulationType;
29  typedef GM GraphicalModelType;
31  typedef opengm::visitors::VerboseVisitor< JunctionTree<GM,ACC> > VerboseVisitorType;
34 
35  enum UpdateRule{
36  HUGIN,
37  SHSH
38  };
39  enum Heuristic{
40  MINFILL,
41  WEIGHTEDMINFILL,
42  MINWEIGHT,
43  MINNEIGHBORS
44  };
45  std::string name() const {
46  return "libDAI-Junction-Tree";
47  }
48  struct Parameter{
49  Parameter
50  (
51  UpdateRule updateRule= HUGIN,
52  Heuristic heuristic=MINWEIGHT,
53  size_t verbose=0
54  ) :updateRule_(updateRule),
55  heuristic_(heuristic),
56  verbose_(verbose) {
57  }
58  std::string toString()const{
59  std::stringstream ss;
60  std::string ur,hr;
61 
62  if(updateRule_==HUGIN)ur = "HUGIN";
63  else if(updateRule_==SHSH)ur = "SHSH";
64 
65  if(heuristic_==MINFILL)hr="MINFILL";
66  else if(heuristic_==WEIGHTEDMINFILL)hr = "WEIGHTEDMINFILL";
67  else if(heuristic_==MINWEIGHT)hr = "MINWEIGHT";
68  else if(heuristic_==MINNEIGHBORS)hr = "MINNEIGHBORS";
69 
70  ss <<"JTREE["
71  <<"updates="<<ur<<","
72  <<"heuristic="<<hr<<","
73  <<"inference="<< std::string(::opengm::meta::Compare<ACC,::opengm::Integrator>::value==true ? std::string("SUMPROD") : std::string("MAXPROD") ) <<","
74  <<"verbose="<<verbose_<<"]";
75  return ss.str();
76  }
77  UpdateRule updateRule_;
78  Heuristic heuristic_;
79  size_t verbose_;
80  };
81  JunctionTree(const GM & gm,const Parameter param=Parameter())
82  :LibDaiInference<GM,ACC,JunctionTree<GM,ACC> >(gm,param.toString()) {
83 
84  }
85 
86  virtual const GraphicalModelType& graphicalModel() const{
87  return this->graphicalModel_impl();
88  }
89 
90  virtual void reset(){
91  return this->reset_impl();
92  }
93 
94  virtual InferenceTermination infer(){
95  return this->infer_impl();
96  }
97 
98  template<class VISITOR>
99  InferenceTermination infer(VISITOR& visitor ){
100  visitor.begin(*this);
101  InferenceTermination infTerm = this->infer_impl();
102  visitor.end(*this);
103  return infTerm;
104  }
105 
106  virtual InferenceTermination arg(std::vector<LabelType>& v, const size_t argnr=1)const{
107  return this->arg_impl(v,argnr);
108  }
109  virtual InferenceTermination marginal(const size_t v, IndependentFactorType& m) const{
110  return this->marginal_impl(v,m);
111  }
112  virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType& m) const{
113  return this->factorMarginal_impl(f,m);
114  }
115 
116 };
117 
118 } // end namespace libdai
119 } // end namespace external
120 } //end namespace opengm
121 
123 
124 #endif // OPENGM_LIBDAI_JUNCTION_TREE_HXX
The OpenGM namespace.
Definition: config.hxx:43
Inference algorithm interface.
Definition: inference.hxx:34
#define OPENGM_GM_TYPE_TYPEDEFS
Definition: inference.hxx:13
InferenceTermination
Definition: inference.hxx:24