00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018
00019
00020 #ifndef __defined_libdai_hak_h
00021 #define __defined_libdai_hak_h
00022
00023
00024 #include <string>
00025 #include <dai/daialg.h>
00026 #include <dai/regiongraph.h>
00027 #include <dai/enum.h>
00028 #include <dai/properties.h>
00029
00030
00031 namespace dai {
00032
00033
00035 class HAK : public DAIAlgRG {
00036 private:
00038 std::vector<Factor> _Qa;
00040 std::vector<Factor> _Qb;
00042 std::vector<std::vector<Factor> > _muab;
00044 std::vector<std::vector<Factor> > _muba;
00046 Real _maxdiff;
00048 size_t _iters;
00049
00050 public:
00052 struct Properties {
00054
00060 DAI_ENUM(ClustersType,MIN,BETHE,DELTA,LOOP);
00061
00063 DAI_ENUM(InitType,UNIFORM,RANDOM);
00064
00066 size_t verbose;
00067
00069 size_t maxiter;
00070
00072 double maxtime;
00073
00075 Real tol;
00076
00078 Real damping;
00079
00081 ClustersType clusters;
00082
00084 InitType init;
00085
00087 bool doubleloop;
00088
00090 size_t loopdepth;
00091 } props;
00092
00094 static const char *Name;
00095
00096 public:
00098
00099
00100 HAK() : DAIAlgRG(), _Qa(), _Qb(), _muab(), _muba(), _maxdiff(0.0), _iters(0U), props() {}
00101
00103
00106 HAK( const FactorGraph &fg, const PropertySet &opts );
00107
00109 HAK( const RegionGraph &rg, const PropertySet &opts );
00111
00112
00114
00115 virtual HAK* clone() const { return new HAK(*this); }
00116 virtual std::string identify() const;
00117 virtual Factor belief( const VarSet &vs ) const;
00118 virtual std::vector<Factor> beliefs() const;
00119 virtual Real logZ() const;
00120 virtual void init();
00121 virtual void init( const VarSet &vs );
00122 virtual Real run();
00123 virtual Real maxDiff() const { return _maxdiff; }
00124 virtual size_t Iterations() const { return _iters; }
00125 virtual void setMaxIter( size_t maxiter ) { props.maxiter = maxiter; }
00126 virtual void setProperties( const PropertySet &opts );
00127 virtual PropertySet getProperties() const;
00128 virtual std::string printProperties() const;
00130
00131
00133
00134
00135 Factor & muab( size_t alpha, size_t _beta ) { return _muab[alpha][_beta]; }
00137 Factor & muba( size_t alpha, size_t _beta ) { return _muba[alpha][_beta]; }
00139 const Factor& Qa( size_t alpha ) const { return _Qa[alpha]; };
00141 const Factor& Qb( size_t beta ) const { return _Qb[beta]; };
00142
00144 Real doGBP();
00146 Real doDoubleLoop();
00148
00149 private:
00151 void construct();
00153
00161 void findLoopClusters( const FactorGraph &fg, std::set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars );
00162 };
00163
00164
00165 }
00166
00167
00168 #endif