21 #ifndef __defined_libdai_hak_h
22 #define __defined_libdai_hak_h
39 std::vector<Factor>
_Qa;
41 std::vector<Factor>
_Qb;
43 std::vector<std::vector<Factor> >
_muab;
45 std::vector<std::vector<Factor> >
_muba;
61 DAI_ENUM(ClustersType,MIN,BETHE,DELTA,LOOP);
97 HAK() :
DAIAlgRG(), _Qa(), _Qb(), _muab(), _muba(), _maxdiff(0.0), _iters(0U), props() {}
115 virtual std::string
name()
const {
return "HAK"; }
117 virtual std::vector<Factor>
beliefs()
const;
133 Factor &
muab(
size_t alpha,
size_t _beta ) {
return _muab[alpha][_beta]; }
136 Factor &
muba(
size_t alpha,
size_t _beta ) {
return _muba[alpha][_beta]; }
138 const Factor&
Qa(
size_t alpha )
const {
return _Qa[alpha]; };
140 const Factor&
Qb(
size_t beta )
const {
return _Qb[beta]; };
size_t loopdepth
Depth of loops (only relevant for clusters == ClustersType::LOOP)
Definition: hak.h:91
A RegionGraph combines a bipartite graph consisting of outer regions (type FRegion) and inner regions...
Definition: regiongraph.h:91
virtual size_t Iterations() const
Returns number of iterations done (one iteration passes over the complete factorgraph).
Definition: hak.h:123
void findLoopClusters(const FactorGraph &fg, std::set< VarSet > &allcl, VarSet newcl, const Var &root, size_t length, VarSet vars)
Recursive procedure for finding clusters of variables containing loops of length at most length...
Definition: hak.cpp:155
Real _maxdiff
Maximum difference encountered so far.
Definition: hak.h:47
virtual Real logZ() const
Returns the logarithm of the (approximated) partition sum (normalizing constant of the factor graph)...
Definition: hak.cpp:605
virtual HAK * construct(const FactorGraph &fg, const PropertySet &opts) const
Returns a pointer to a newly constructed inference algorithm.
Definition: hak.h:114
Represents a factor graph.
Definition: factorgraph.h:65
ClustersType clusters
How to choose the outer regions.
Definition: hak.h:82
const Factor & Qb(size_t beta) const
Returns belief of inner region beta.
Definition: hak.h:140
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
HAK()
Default constructor.
Definition: hak.h:98
std::vector< Factor > _Qa
Outer region beliefs.
Definition: hak.h:39
virtual void init()
Initializes all data structures of the approximate inference algorithm.
Definition: hak.cpp:301
virtual Real run()
Runs the approximate inference algorithm.
Definition: hak.cpp:568
virtual HAK * clone() const
Returns a pointer to a new, cloned copy of *this (i.e., virtual copy constructor) ...
Definition: hak.h:113
Real damping
Damping constant (0.0 means no damping, 1.0 is maximum damping)
Definition: hak.h:79
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
size_t _iters
Number of iterations needed.
Definition: hak.h:49
Represents a set of variables.
Definition: varset.h:94
Factor & muab(size_t alpha, size_t _beta)
Returns reference to message from outer region alpha to its _beta 'th neighboring inner region...
Definition: hak.h:134
DAI_ENUM(ClustersType, MIN, BETHE, DELTA, LOOP)
Enumeration of possible cluster choices.
virtual std::string printProperties() const
Returns parameters of this inference algorithm formatted as a string in the format "[key1=val1...
Definition: hak.cpp:95
Real doDoubleLoop()
Runs double-loop algorithm (as described in section 4.2 of [HAK03]), which always convergences...
Definition: hak.cpp:464
virtual Factor belief(const VarSet &vs) const
Returns the (approximate) marginal probability distribution of a set of variables.
Definition: hak.cpp:576
virtual void setProperties(const PropertySet &opts)
Set parameters of this inference algorithm.
Definition: hak.cpp:44
InitType init
How to initialize the messages.
Definition: hak.h:85
std::vector< Factor > _Qb
Inner region beliefs.
Definition: hak.h:41
bool doubleloop
Use single-loop (GBP) or double-loop (HAK)
Definition: hak.h:88
virtual std::string name() const
Returns the name of the algorithm.
Definition: hak.h:115
const Factor & Qa(size_t alpha) const
Returns belief of outer region alpha.
Definition: hak.h:138
Parameters for HAK.
Definition: hak.h:53
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...
virtual std::vector< Factor > beliefs() const
Returns all beliefs (approximate marginal probability distributions) calculated by the algorithm...
Definition: hak.cpp:595
Approximate inference algorithm: implementation of single-loop ("Generalized Belief Propagation") and...
Definition: hak.h:36
Represents a set of properties, mapping keys (of type PropertyKey) to values (of type PropertyValue) ...
Definition: properties.h:73
Real doGBP()
Runs single-loop algorithm (algorithm 1 in [HAK03])
Definition: hak.cpp:331
size_t verbose
Verbosity (amount of output sent to stderr)
Definition: hak.h:67
void construct()
Helper function for constructors.
Definition: hak.cpp:111
virtual void setMaxIter(size_t maxiter)
Sets maximum number of iterations (one iteration passes over the complete factorgraph).
Definition: hak.h:124
double maxtime
Maximum time (in seconds)
Definition: hak.h:73
Real tol
Tolerance for convergence test.
Definition: hak.h:76
size_t maxiter
Maximum number of iterations.
Definition: hak.h:70
std::vector< std::vector< Factor > > _muab
Messages from outer to inner regions.
Definition: hak.h:43
Represents a discrete random variable.
Definition: var.h:37
Namespace for libDAI.
Definition: alldai.cpp:16
virtual Real maxDiff() const
Returns maximum difference between single variable beliefs in the last iteration. ...
Definition: hak.h:122
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.
Factor & muba(size_t alpha, size_t _beta)
Returns reference to message the _beta 'th neighboring inner region of outer region alpha to that out...
Definition: hak.h:136
Combines the abstract base class InfAlg with a graphical model (e.g., a FactorGraph or RegionGraph)...
Definition: daialg.h:207
virtual PropertySet getProperties() const
Returns parameters of this inference algorithm converted into a PropertySet.
Definition: hak.cpp:80
std::vector< std::vector< Factor > > _muba
Messages from inner to outer regions.
Definition: hak.h:45