OpenGM  2.3.x
Discrete Graphical Model Library
tree_expectation_propagation.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_LIBDAI_TREEEP_HXX
2 #define OPENGM_LIBDAI_TREEEP_HXX
3 
5 
6 namespace opengm{
7 namespace external{
8 namespace libdai{
9 
21 template<class GM,class ACC>
22 class TreeExpectationPropagation : public LibDaiInference<GM,ACC,TreeExpectationPropagation<GM,ACC> > , public opengm::Inference<GM,ACC>{
23  public:
24  typedef ACC AccumulationType;
25  typedef GM GraphicalModelType;
30 
31  enum TreeEpType{
32  ORG,
34  };
35  std::string name() const{
36  return "libDAI-Tree-Expectation-Propagation";
37  }
38  struct Parameter{
39  Parameter
40  (
41  TreeEpType treeEpTyp=ORG,
42  const size_t maxiter=10000,
43  const double maxtime=120,
44  const double tolerance=1e-9,
45  size_t verbose=0
46  ) :treeEpType_(treeEpTyp),
47  maxiter_(maxiter),
48  maxtime_(maxtime),
49  tolerance_(tolerance),
50  verbose_(verbose) {
51  }
52  std::string toString()const{
53  std::stringstream ss;
54  std::string treeept,hr;
55 
56  if(treeEpType_==ORG)treeept = "ORG";
57  else if(treeEpType_==ALT)treeept = "ALT";
58 
59  ss <<"TREEEP["
60  <<"type="<<treeept<<","
61  <<"tol="<<tolerance_<<","
62  <<"maxiter="<<maxiter_<<","
63  //<<"maxtime="<<maxtime_<<","
64  <<"verbose="<<verbose_<<"]";
65  return ss.str();
66  }
68  size_t maxiter_;
69  double maxtime_; // in seconds
70  double tolerance_;
71  size_t verbose_;
72  };
73  TreeExpectationPropagation(const GM & gm,const Parameter param=Parameter())
74  :LibDaiInference<GM,ACC,TreeExpectationPropagation<GM,ACC> >(gm,param.toString()) {
75 
76  }
77 
78  virtual const GraphicalModelType& graphicalModel() const{
79  return this->graphicalModel_impl();
80  }
81 
82  virtual void reset(){
83  return this->reset_impl();
84  }
85 
87  return this->infer_impl();
88  }
89 
90  template<class VISITOR>
91  InferenceTermination infer(VISITOR& visitor ){
92  visitor.begin(*this);
93  InferenceTermination infTerm = this->infer_impl();
94  visitor.end(*this);
95  return infTerm;
96  }
97 
98  virtual InferenceTermination arg(std::vector<LabelType>& v, const size_t argnr=1)const{
99  return this->arg_impl(v,argnr);
100  }
101  virtual InferenceTermination marginal(const size_t v, IndependentFactorType& m) const{
102  return this->marginal_impl(v,m);
103  }
104  virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType& m) const{
105  return this->factorMarginal_impl(f,m);
106  }
107 
108 };
109 
110 } // end namespace libdai
111 } // end namespace external
112 } //end namespace opengm
113 
114 #endif // OPENGM_LIBDAI_TREEEP_HXX
The OpenGM namespace.
Definition: config.hxx:43
Parameter(TreeEpType treeEpTyp=ORG, const size_t maxiter=10000, const double maxtime=120, const double tolerance=1e-9, size_t verbose=0)
virtual const GraphicalModelType & graphicalModel() const
TreeExpectationPropagation(const GM &gm, const Parameter param=Parameter())
virtual InferenceTermination factorMarginal(const size_t f, IndependentFactorType &m) const
output a solution for a marginal for all variables connected to a factor
virtual InferenceTermination marginal(const size_t v, IndependentFactorType &m) const
output a solution for a marginal for a specific variable
opengm::visitors::VerboseVisitor< TreeExpectationPropagation< GM, ACC > > VerboseVisitorType
virtual InferenceTermination arg(std::vector< LabelType > &v, const size_t argnr=1) const
output a solution
opengm::visitors::EmptyVisitor< TreeExpectationPropagation< GM, ACC > > EmptyVisitorType
Inference algorithm interface.
Definition: inference.hxx:34
opengm::visitors::TimingVisitor< TreeExpectationPropagation< GM, ACC > > TimingVisitorType
InferenceTermination
Definition: inference.hxx:24
GraphicalModelType::IndependentFactorType IndependentFactorType
Definition: inference.hxx:44