OpenGM  2.3.x
Discrete Graphical Model Library
tree_reweighted_bp.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_LIBDAI_TRBP_HXX
2 #define OPENGM_LIBDAI_TRBP_HXX
3 
5 
6 namespace opengm{
7 namespace external{
8 namespace libdai{
9 
22 template<class GM,class ACC>
23 class TreeReweightedBp : public LibDaiInference<GM,ACC,TreeReweightedBp<GM,ACC> >
24  , public opengm::Inference<GM,ACC>{
25  public:
26  typedef ACC AccumulationType;
27  typedef GM GraphicalModelType;
32  enum UpdateRule{
37  };
38  std::string name() const {
39  return "libDAI-Tree-Reweighted-Bp";
40  }
41  struct Parameter{
42  Parameter
43  (
44  const size_t maxIterations=100,
45  const double damping=0.0,
46  const double tolerance=0.000001,
47  const size_t ntrees=0,
48  UpdateRule updateRule= PARALL,
49  const size_t verbose=0
50  ) :maxIterations_(maxIterations),
51  damping_(damping),
52  tolerance_(tolerance),
53  ntrees_(ntrees),
54  updateRule_(updateRule),
55  verbose_(verbose),
56  logDomain_(0) {
57 
58  }
59  std::string toString( )const{
60  std::string ur;
61  std::stringstream ss;
62  if(updateRule_==PARALL)ur="PARALL";
63  else if(updateRule_==SEQFIX)ur = "SEQFIX";
64  else if(updateRule_==SEQMAX)ur = "SEQMAX";
65  else if(updateRule_==SEQRND)ur = "SEQRND";
66  ss <<"TRWBP["
67  <<"updates="<<ur<<","
68  <<"damping="<<damping_<<","
69  <<"maxiter="<<maxIterations_<<","
70  <<"tol="<<tolerance_<<","
71  <<"ntrees="<<ntrees_<<","
72  <<"logdomain="<<logDomain_<<","
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  }
78  double damping_;
79  double tolerance_;
81  size_t ntrees_;
82  size_t verbose_;
83  size_t logDomain_;
84 
85  };
86  TreeReweightedBp(const GM & gm,const Parameter param=Parameter())
87  :LibDaiInference<GM,ACC,TreeReweightedBp<GM,ACC> >(gm,param.toString()) {
88 
89  }
90 
91  virtual const GraphicalModelType& graphicalModel() const{
92  return this->graphicalModel_impl();
93  }
94 
95  virtual void reset(){
96  return this->reset_impl();
97  }
98 
100  return this->infer_impl();
101  }
102 
103  template<class VISITOR>
104  InferenceTermination infer(VISITOR& visitor ){
105  visitor.begin(*this);
106  InferenceTermination infTerm = this->infer_impl();
107  visitor.end(*this);
108  return infTerm;
109  }
110 
111  virtual InferenceTermination arg(std::vector<LabelType>& v, const size_t argnr=1)const{
112  return this->arg_impl(v,argnr);
113  }
114  virtual InferenceTermination marginal(const size_t v, IndependentFactorType& m) const{
115  return this->marginal_impl(v,m);
116  }
117  virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType& m) const{
118  return this->factorMarginal_impl(f,m);
119  }
120 };
121 
122 } // end namespace libdai
123 } // end namespace external
124 } //end namespace opengm
125 
126 #endif // OPENGM_LIBDAI_TRBP_HXX
opengm::visitors::EmptyVisitor< TreeReweightedBp< GM, ACC > > EmptyVisitorType
The OpenGM namespace.
Definition: config.hxx:43
TreeReweightedBp(const GM &gm, const Parameter param=Parameter())
opengm::visitors::TimingVisitor< TreeReweightedBp< GM, ACC > > TimingVisitorType
InferenceTermination infer(VISITOR &visitor)
virtual InferenceTermination marginal(const size_t v, IndependentFactorType &m) const
output a solution for a marginal for a specific variable
Parameter(const size_t maxIterations=100, const double damping=0.0, const double tolerance=0.000001, const size_t ntrees=0, UpdateRule updateRule=PARALL, const size_t verbose=0)
virtual InferenceTermination arg(std::vector< LabelType > &v, const size_t argnr=1) const
output a solution
Inference algorithm interface.
Definition: inference.hxx:34
tree reweighted belief propagation : [?]
virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType &m) const
output a solution for a marginal for all variables connected to a factor
opengm::visitors::VerboseVisitor< TreeReweightedBp< GM, ACC > > VerboseVisitorType
virtual const GraphicalModelType & graphicalModel() const
InferenceTermination
Definition: inference.hxx:24
GraphicalModelType::IndependentFactorType IndependentFactorType
Definition: inference.hxx:44