OpenGM  2.3.x
Discrete Graphical Model Library
double_loop_generalized_bp.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_LIBDAI_DOUBLE_LOOP_GENERALIZED_BP_HXX
2 #define OPENGM_LIBDAI_DOUBLE_LOOP_GENERALIZED_BP_HXX
3 
5 
7 
8 namespace opengm{
9 namespace external{
10 namespace libdai{
11 
12 template<class GM,class ACC>
13 class DoubleLoopGeneralizedBP : public LibDaiInference<GM,ACC,DoubleLoopGeneralizedBP<GM,ACC> >, public opengm::Inference<GM,ACC>{
14  public:
15  typedef ACC AccumulationType;
16  typedef GM GraphicalModelType;
21 
22  enum Clusters{
23  MIN,
24  BETHE,
25  DELTA,
26  LOOP
27  };
28 
29  enum Init{
30  UNIFORM,
31  RANDOM
32  };
33 
34  std::string name()const {
35  return "Double-Loop-Generalized-BP";
36  }
37 
38  struct Parameter{
39  Parameter
40  (
41  const bool doubleloop=1,
42  const Clusters clusters=BETHE,
43  const size_t loopdepth = 3,
44  const Init init=UNIFORM,
45  const size_t maxiter=10000,
46  const double tolerance=1e-9,
47  const size_t verbose=0
48  ) :
49  doubleloop_(doubleloop),
50  loopdepth_(loopdepth),
51  clusters_(clusters),
52  init_(init),
53  maxiter_(maxiter),
54  tolerance_(tolerance),
55  verbose_(verbose) {
56  }
57  std::string toString()const{
58  std::stringstream ss;
59  std::string init,cluster;
60 
61  if(init_==UNIFORM)init="UNIFORM";
62  else if(init_==RANDOM)init = "RANDOM";
63 
64  if(clusters_==MIN)cluster="MIN";
65  else if(clusters_==BETHE)cluster = "BETHE";
66  else if(clusters_==DELTA)cluster = "DELTA";
67  else if(clusters_==LOOP)cluster = "LOOP";
68 
69  if(clusters_==LOOP) {
70  ss <<"HAK["
71  <<"doubleloop="<<doubleloop_<<","
72  <<"clusters="<<"LOOP"<<","
73  <<"init="<<init<<","
74  <<"tol="<<tolerance_<<","
75  <<"loopdepth="<<loopdepth_<<","
76  <<"maxiter="<<maxiter_<<","
77  <<"verbose="<<verbose_<<"]";
78  return ss.str();
79  }
80  else{
81  ss <<"HAK["
82  <<"doubleloop="<<doubleloop_<<","
83  <<"clusters="<<cluster<<","
84  <<"init="<<init<<","
85  <<"tol="<<tolerance_<<","
86  <<"maxiter="<<maxiter_<<","
87  <<"verbose="<<verbose_<<"]";
88  return ss.str();
89  }
90  }
91  bool doubleloop_;
92  size_t loopdepth_;
93  Clusters clusters_;
94  Init init_;
95  size_t maxiter_;
96  double tolerance_;
97  size_t verbose_;
98 
99  };
100  DoubleLoopGeneralizedBP(const GM & gm,const Parameter param=Parameter())
101  :LibDaiInference<GM,ACC,DoubleLoopGeneralizedBP<GM,ACC> >(gm,param.toString()) {
102 
103  }
104 
105  virtual const GraphicalModelType& graphicalModel() const{
106  return this->graphicalModel_impl();
107  }
108 
109  virtual void reset(){
110  return this->reset_impl();
111  }
112 
113  virtual InferenceTermination infer(){
114  return this->infer_impl();
115  }
116 
117  template<class VISITOR>
118  InferenceTermination infer(VISITOR& visitor ){
119  visitor.begin(*this);
120  InferenceTermination infTerm = this->infer_impl();
121  visitor.end(*this);
122  return infTerm;
123  }
124 
125  virtual InferenceTermination arg(std::vector<LabelType>& v, const size_t argnr=1)const{
126  return this->arg_impl(v,argnr);
127  }
128  virtual InferenceTermination marginal(const size_t v, IndependentFactorType& m) const{
129  return this->marginal_impl(v,m);
130  }
131  virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType& m) const{
132  return this->factorMarginal_impl(f,m);
133  }
134 
135 };
136 
137 } // end namespace libdai
138 } // end namespace external
139 } //end namespace opengm
140 
142 
143 #endif // OPENGM_LIBDAI_DOUBLE_LOOP_GENERALIZED_BP_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