00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00014
00015
00016 #ifndef __defined_libdai_jtree_h
00017 #define __defined_libdai_jtree_h
00018
00019
00020 #include <vector>
00021 #include <string>
00022 #include <dai/daialg.h>
00023 #include <dai/varset.h>
00024 #include <dai/regiongraph.h>
00025 #include <dai/factorgraph.h>
00026 #include <dai/clustergraph.h>
00027 #include <dai/weightedgraph.h>
00028 #include <dai/enum.h>
00029 #include <dai/properties.h>
00030
00031
00032 namespace dai {
00033
00034
00036
00044 class JTree : public DAIAlgRG {
00045 private:
00047 std::vector<std::vector<Factor> > _mes;
00048
00050 Real _logZ;
00051
00052 public:
00054 RootedTree RTree;
00055
00057 std::vector<Factor> Qa;
00058
00060 std::vector<Factor> Qb;
00061
00063 struct Properties {
00065
00069 DAI_ENUM(UpdateType,HUGIN,SHSH);
00070
00072
00076 DAI_ENUM(InfType,SUMPROD,MAXPROD);
00077
00079
00088 DAI_ENUM(HeuristicType,MINNEIGHBORS,MINWEIGHT,MINFILL,WEIGHTEDMINFILL);
00089
00091 size_t verbose;
00092
00094 UpdateType updates;
00095
00097 InfType inference;
00098
00100 HeuristicType heuristic;
00101
00103 size_t maxmem;
00104 } props;
00105
00107 static const char *Name;
00108
00109 public:
00111
00112
00113 JTree() : DAIAlgRG(), _mes(), _logZ(), RTree(), Qa(), Qb(), props() {}
00114
00116
00120 JTree( const FactorGraph &fg, const PropertySet &opts, bool automatic=true );
00122
00123
00125
00126 virtual JTree* clone() const { return new JTree(*this); }
00127 virtual std::string identify() const;
00128 virtual Factor belief( const VarSet &vs ) const;
00129 virtual std::vector<Factor> beliefs() const;
00130 virtual Real logZ() const;
00133 std::vector<std::size_t> findMaximum() const;
00134 virtual void init() {}
00135 virtual void init( const VarSet & ) {}
00136 virtual Real run();
00137 virtual Real maxDiff() const { return 0.0; }
00138 virtual size_t Iterations() const { return 1UL; }
00139 virtual void setProperties( const PropertySet &opts );
00140 virtual PropertySet getProperties() const;
00141 virtual std::string printProperties() const;
00143
00144
00146
00147
00148
00161 void construct( const FactorGraph &fg, const std::vector<VarSet> &cl, bool verify=false );
00162
00164
00167 void GenerateJT( const FactorGraph &fg, const std::vector<VarSet> &cl );
00168
00170 const Factor & message( size_t alpha, size_t _beta ) const { return _mes[alpha][_beta]; }
00172 Factor & message( size_t alpha, size_t _beta ) { return _mes[alpha][_beta]; }
00173
00175
00177 void runHUGIN();
00178
00180
00182 void runShaferShenoy();
00183
00185
00192 size_t findEfficientTree( const VarSet& vs, RootedTree &Tree, size_t PreviousRoot=(size_t)-1 ) const;
00193
00195
00197 Factor calcMarginal( const VarSet& vs );
00199 };
00200
00201
00203
00210 std::pair<size_t,long double> boundTreewidth( const FactorGraph &fg, greedyVariableElimination::eliminationCostFunction fn, size_t maxStates=0 );
00211
00212
00213 }
00214
00215
00216 #endif