15 #ifndef __defined_libdai_treeep_h
16 #define __defined_libdai_treeep_h
20 #ifdef DAI_WITH_TREEEP
84 std::vector<Factor>
_Qa;
86 std::vector<Factor>
_Qb;
90 std::vector<size_t>
_a;
92 std::vector<size_t>
_b;
105 TreeEPSubTree() : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(NULL), _ns(), _nsrem(), _logZ(0.0) {}
109 TreeEPSubTree(
const TreeEPSubTree &x ) : _Qa(x._Qa), _Qb(x._Qb), _RTree(x._RTree), _a(x._a), _b(x._b), _I(x._I), _ns(x._ns), _nsrem(x._nsrem), _logZ(x._logZ) {}
141 Real logZ(
const std::vector<Factor> &
Qa,
const std::vector<Factor> &
Qb )
const;
148 std::map<size_t, TreeEPSubTree>
_Q;
155 TreeEP(
const TreeEP &x ) :
JTree(x), _maxdiff(x._maxdiff), _iters(x._iters), props(x.props), _Q(x._Q) {
156 for(
size_t I = 0; I < nrFactors(); I++ )
158 _Q[I].I() = &factor(I);
164 JTree::operator=( x );
169 for(
size_t I = 0; I < nrFactors(); I++ )
171 _Q[I].I() = &factor(I);
187 virtual std::string
name()
const {
return "TREEEP"; }
204 bool offtree(
size_t I )
const {
return (fac2OR(I) == -1U); }
virtual std::string name() const
Returns the name of the algorithm.
Definition: treeep.h:187
VarSet _nsrem
Variables in off-tree factor which are not in the root of this subtree.
Definition: treeep.h:98
virtual Real run()
Runs the approximate inference algorithm.
Definition: treeep.cpp:190
virtual void setProperties(const PropertySet &opts)
Set parameters of this inference algorithm.
Definition: treeep.cpp:27
virtual std::string printProperties() const
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1...
Definition: treeep.cpp:59
virtual Real maxDiff() const
Returns maximum difference between single variable beliefs in the last iteration. ...
Definition: treeep.h:192
Exact inference algorithm using junction tree.
Definition: jtree.h:45
Real logZ(const std::vector< Factor > &Qa, const std::vector< Factor > &Qb) const
Returns energy (?) of this subtree.
Definition: treeep.cpp:376
Approximate inference algorithm "Tree Expectation Propagation" [MiQ04].
Definition: treeep.h:40
size_t maxiter
Maximum number of iterations.
Definition: treeep.h:63
Defines some utility functions for (weighted) undirected graphs, trees and rooted trees...
Represents a factor graph.
Definition: factorgraph.h:65
Defines the VarSet class, which represents a set of random variables.
std::vector< Factor > Qa
Outer region beliefs.
Definition: jtree.h:58
virtual void init(const VarSet &)
Initializes all data structures corresponding to some set of variables.
Definition: treeep.h:190
FactorGraph & fg()
Returns reference to underlying FactorGraph.
Definition: daialg.h:221
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
TreeEPSubTree(const TreeEPSubTree &x)
Copy constructor.
Definition: treeep.h:109
void HUGIN_with_I(std::vector< Factor > &Qa, std::vector< Factor > &Qb)
Runs junction tree algorithm (including off-tree factor I) storing the results in the (super) junctio...
Definition: treeep.cpp:318
bool offtree(size_t I) const
Returns true if factor I is not part of the tree.
Definition: treeep.h:204
TreeEP(const TreeEP &x)
Copy constructor.
Definition: treeep.h:155
virtual TreeEP * construct(const FactorGraph &fg, const PropertySet &opts) const
Returns a pointer to a newly constructed inference algorithm.
Definition: treeep.h:186
Real _logZ
Used for calculating the free energy.
Definition: treeep.h:100
virtual void init()
Initializes all data structures of the approximate inference algorithm.
Definition: treeep.cpp:180
const Factor *& I()
Returns constant reference to the pointer to the off-tree factor.
Definition: treeep.h:144
DAI_ENUM(TypeType, ORG, ALT)
Enumeration of possible choices for the tree.
virtual size_t Iterations() const
Returns number of iterations done (one iteration passes over the complete factorgraph).
Definition: treeep.h:193
TreeEPSubTree & operator=(const TreeEPSubTree &x)
Assignment operator.
Definition: treeep.h:112
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
TreeEPSubTree()
Default constructor.
Definition: treeep.h:106
std::vector< Factor > _Qb
Inner region pseudomarginals (corresponding with the in [MiQ04])
Definition: treeep.h:86
Represents a set of variables.
Definition: varset.h:94
std::vector< Factor > _Qa
Outer region pseudomarginals (corresponding with the in [MiQ04])
Definition: treeep.h:84
std::vector< size_t > _b
Index conversion table for inner region indices (_Qb[beta] corresponds with Qb[_b[beta]] of the super...
Definition: treeep.h:92
virtual void setMaxIter(size_t maxiter)
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
Definition: treeep.h:194
Defines class JTree, which implements the junction tree algorithm.
RootedTree _RTree
The junction tree (stored as a rooted tree)
Definition: treeep.h:88
const Factor * _I
Pointer to off-tree factor.
Definition: treeep.h:94
VarSet _ns
Variables in off-tree factor.
Definition: treeep.h:96
std::vector< Factor > Qb
Inner region beliefs.
Definition: jtree.h:61
Defines class ClusterGraph, which is used by JTree, TreeEP and HAK.
Defines the Property and PropertySet classes, which are mainly used for managing parameters of infere...
Defines classes Region, FRegion and RegionGraph, which implement a particular subclass of region grap...
TypeType type
How to choose the tree.
Definition: treeep.h:72
std::map< size_t, TreeEPSubTree > _Q
Stores a TreeEPSubTree object for each off-tree factor.
Definition: treeep.h:148
Represents a rooted tree, implemented as a vector of directed edges.
Definition: weightedgraph.h:157
double maxtime
Maximum time (in seconds)
Definition: treeep.h:66
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
Parameters for TreeEP.
Definition: treeep.h:49
std::vector< size_t > _a
Index conversion table for outer region indices (_Qa[alpha] corresponds with Qa[_a[alpha]] of the sup...
Definition: treeep.h:90
void InvertAndMultiply(const std::vector< Factor > &Qa, const std::vector< Factor > &Qb)
Inverts this approximation and multiplies it by the (super) junction tree marginals Qa and Qb...
Definition: treeep.cpp:309
virtual Real logZ() const
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph)...
Definition: treeep.cpp:241
Namespace for libDAI.
Definition: alldai.cpp:16
Defines the FactorGraph class, which represents factor graphs (e.g., Bayesian networks or Markov rand...
Defines the general interface for inference methods in libDAI (classes InfAlg, DaiAlg<>, DaiAlgFG and DaiAlgRG).
Allows the user to specify which algorithms will be built into libDAI.
TreeEP & operator=(const TreeEP &x)
Assignment operator.
Definition: treeep.h:162
Real _maxdiff
Maximum difference encountered so far.
Definition: treeep.h:43
virtual PropertySet getProperties() const
Returns parameters of this inference algorithm converted into a PropertySet.
Definition: treeep.cpp:48
virtual TreeEP * clone() const
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) ...
Definition: treeep.h:185
Stores the data structures needed to efficiently update the approximation of an off-tree factor...
Definition: treeep.h:81
void init()
Initializes beliefs of this subtree.
Definition: treeep.cpp:301
Real tol
Tolerance for convergence test.
Definition: treeep.h:69
TreeEP()
Default constructor.
Definition: treeep.h:152
size_t _iters
Number of iterations needed.
Definition: treeep.h:45
size_t verbose
Verbosity (amount of output sent to stderr)
Definition: treeep.h:60