libDAI
|
00001 /* This file is part of libDAI - http://www.libdai.org/ 00002 * 00003 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved. 00004 * 00005 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 00006 */ 00007 00008 00015 00016 00017 #ifndef __defined_libdai_hak_h 00018 #define __defined_libdai_hak_h 00019 00020 00021 #include <string> 00022 #include <dai/daialg.h> 00023 #include <dai/regiongraph.h> 00024 #include <dai/enum.h> 00025 #include <dai/properties.h> 00026 00027 00028 namespace dai { 00029 00030 00032 class HAK : public DAIAlgRG { 00033 private: 00035 std::vector<Factor> _Qa; 00037 std::vector<Factor> _Qb; 00039 std::vector<std::vector<Factor> > _muab; 00041 std::vector<std::vector<Factor> > _muba; 00043 Real _maxdiff; 00045 size_t _iters; 00046 00047 public: 00049 struct Properties { 00051 00057 DAI_ENUM(ClustersType,MIN,BETHE,DELTA,LOOP); 00058 00060 DAI_ENUM(InitType,UNIFORM,RANDOM); 00061 00063 size_t verbose; 00064 00066 size_t maxiter; 00067 00069 double maxtime; 00070 00072 Real tol; 00073 00075 Real damping; 00076 00078 ClustersType clusters; 00079 00081 InitType init; 00082 00084 bool doubleloop; 00085 00087 size_t loopdepth; 00088 } props; 00089 00090 public: 00092 00093 00094 HAK() : DAIAlgRG(), _Qa(), _Qb(), _muab(), _muba(), _maxdiff(0.0), _iters(0U), props() {} 00095 00097 00100 HAK( const FactorGraph &fg, const PropertySet &opts ); 00101 00103 HAK( const RegionGraph &rg, const PropertySet &opts ); 00105 00106 00108 00109 virtual HAK* clone() const { return new HAK(*this); } 00110 virtual HAK* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new HAK( fg, opts ); } 00111 virtual std::string name() const { return "HAK"; } 00112 virtual Factor belief( const VarSet &vs ) const; 00113 virtual std::vector<Factor> beliefs() const; 00114 virtual Real logZ() const; 00115 virtual void init(); 00116 virtual void init( const VarSet &vs ); 00117 virtual Real run(); 00118 virtual Real maxDiff() const { return _maxdiff; } 00119 virtual size_t Iterations() const { return _iters; } 00120 virtual void setMaxIter( size_t maxiter ) { props.maxiter = maxiter; } 00121 virtual void setProperties( const PropertySet &opts ); 00122 virtual PropertySet getProperties() const; 00123 virtual std::string printProperties() const; 00125 00126 00128 00129 00130 Factor & muab( size_t alpha, size_t _beta ) { return _muab[alpha][_beta]; } 00132 Factor & muba( size_t alpha, size_t _beta ) { return _muba[alpha][_beta]; } 00134 const Factor& Qa( size_t alpha ) const { return _Qa[alpha]; }; 00136 const Factor& Qb( size_t beta ) const { return _Qb[beta]; }; 00137 00139 Real doGBP(); 00141 Real doDoubleLoop(); 00143 00144 private: 00146 void construct(); 00148 00156 void findLoopClusters( const FactorGraph &fg, std::set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars ); 00157 }; 00158 00159 00160 } // end of namespace dai 00161 00162 00163 #endif