libDAI
hak.h
Go to the documentation of this file.
1 /* This file is part of libDAI - http://www.libdai.org/
2  *
3  * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4  *
5  * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6  */
7 
8 
15 
16 
17 #ifndef __defined_libdai_hak_h
18 #define __defined_libdai_hak_h
19 
20 
21 #include <string>
22 #include <dai/daialg.h>
23 #include <dai/regiongraph.h>
24 #include <dai/enum.h>
25 #include <dai/properties.h>
26 
27 
28 namespace dai {
29 
30 
32 class HAK : public DAIAlgRG {
33  private:
35  std::vector<Factor> _Qa;
37  std::vector<Factor> _Qb;
39  std::vector<std::vector<Factor> > _muab;
41  std::vector<std::vector<Factor> > _muba;
45  size_t _iters;
46 
47  public:
49  struct Properties {
51 
57  DAI_ENUM(ClustersType,MIN,BETHE,DELTA,LOOP);
58 
60  DAI_ENUM(InitType,UNIFORM,RANDOM);
61 
63  size_t verbose;
64 
66  size_t maxiter;
67 
69  double maxtime;
70 
73 
76 
78  ClustersType clusters;
79 
81  InitType init;
82 
84  bool doubleloop;
85 
87  size_t loopdepth;
88  } props;
89 
90  public:
92 
93 
94  HAK() : DAIAlgRG(), _Qa(), _Qb(), _muab(), _muba(), _maxdiff(0.0), _iters(0U), props() {}
95 
97 
100  HAK( const FactorGraph &fg, const PropertySet &opts );
101 
103  HAK( const RegionGraph &rg, const PropertySet &opts );
105 
106 
108 
109  virtual HAK* clone() const { return new HAK(*this); }
110  virtual HAK* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new HAK( fg, opts ); }
111  virtual std::string name() const { return "HAK"; }
112  virtual Factor belief( const VarSet &vs ) const;
113  virtual std::vector<Factor> beliefs() const;
114  virtual Real logZ() const;
115  virtual void init();
116  virtual void init( const VarSet &vs );
117  virtual Real run();
118  virtual Real maxDiff() const { return _maxdiff; }
119  virtual size_t Iterations() const { return _iters; }
120  virtual void setMaxIter( size_t maxiter ) { props.maxiter = maxiter; }
121  virtual void setProperties( const PropertySet &opts );
122  virtual PropertySet getProperties() const;
123  virtual std::string printProperties() const;
125 
126 
128 
129 
130  Factor & muab( size_t alpha, size_t _beta ) { return _muab[alpha][_beta]; }
132  Factor & muba( size_t alpha, size_t _beta ) { return _muba[alpha][_beta]; }
134  const Factor& Qa( size_t alpha ) const { return _Qa[alpha]; };
136  const Factor& Qb( size_t beta ) const { return _Qb[beta]; };
137 
139  Real doGBP();
141  Real doDoubleLoop();
143 
144  private:
146  void construct();
148 
156  void findLoopClusters( const FactorGraph &fg, std::set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars );
157 };
158 
159 
160 } // end of namespace dai
161 
162 
163 #endif