libDAI
jtree.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 
11 
12 
13 #ifndef __defined_libdai_jtree_h
14 #define __defined_libdai_jtree_h
15 
16 
17 #include <vector>
18 #include <string>
19 #include <dai/daialg.h>
20 #include <dai/varset.h>
21 #include <dai/regiongraph.h>
22 #include <dai/factorgraph.h>
23 #include <dai/clustergraph.h>
24 #include <dai/weightedgraph.h>
25 #include <dai/enum.h>
26 #include <dai/properties.h>
27 
28 
29 namespace dai {
30 
31 
33 
41 class JTree : public DAIAlgRG {
42  private:
44  std::vector<std::vector<Factor> > _mes;
45 
48 
49  public:
52 
54  std::vector<Factor> Qa;
55 
57  std::vector<Factor> Qb;
58 
60  struct Properties {
62 
66  DAI_ENUM(UpdateType,HUGIN,SHSH);
67 
69 
73  DAI_ENUM(InfType,SUMPROD,MAXPROD);
74 
76 
85  DAI_ENUM(HeuristicType,MINNEIGHBORS,MINWEIGHT,MINFILL,WEIGHTEDMINFILL);
86 
88  size_t verbose;
89 
91  UpdateType updates;
92 
94  InfType inference;
95 
97  HeuristicType heuristic;
98 
100  size_t maxmem;
101  } props;
102 
103  public:
105 
106 
107  JTree() : DAIAlgRG(), _mes(), _logZ(), RTree(), Qa(), Qb(), props() {}
108 
110 
114  JTree( const FactorGraph &fg, const PropertySet &opts, bool automatic=true );
116 
117 
119 
120  virtual JTree* clone() const { return new JTree(*this); }
121  virtual JTree* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new JTree( fg, opts ); }
122  virtual std::string name() const { return "JTREE"; }
123  virtual Factor belief( const VarSet &vs ) const;
124  virtual std::vector<Factor> beliefs() const;
125  virtual Real logZ() const;
128  std::vector<std::size_t> findMaximum() const;
129  virtual void init() {}
130  virtual void init( const VarSet &/*ns*/ ) {}
131  virtual Real run();
132  virtual Real maxDiff() const { return 0.0; }
133  virtual size_t Iterations() const { return 1UL; }
134  virtual void setProperties( const PropertySet &opts );
135  virtual PropertySet getProperties() const;
136  virtual std::string printProperties() const;
138 
139 
141 
142 
143 
156  void construct( const FactorGraph &fg, const std::vector<VarSet> &cl, bool verify=false );
157 
159 
162  void GenerateJT( const FactorGraph &fg, const std::vector<VarSet> &cl );
163 
165  const Factor & message( size_t alpha, size_t _beta ) const { return _mes[alpha][_beta]; }
167  Factor & message( size_t alpha, size_t _beta ) { return _mes[alpha][_beta]; }
168 
170 
172  void runHUGIN();
173 
175 
177  void runShaferShenoy();
178 
180 
187  size_t findEfficientTree( const VarSet& vs, RootedTree &Tree, size_t PreviousRoot=(size_t)-1 ) const;
188 
190 
192  Factor calcMarginal( const VarSet& vs );
194 };
195 
196 
198 
205 std::pair<size_t,BigInt> boundTreewidth( const FactorGraph &fg, greedyVariableElimination::eliminationCostFunction fn, size_t maxStates=0 );
206 
207 
208 } // end of namespace dai
209 
210 
211 #endif