1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
13 /// \brief Defines class MF
14 /// \todo Improve documentation
17 #ifndef __defined_libdai_mf_h
18 #define __defined_libdai_mf_h
22 #include <dai/daialg.h>
23 #include <dai/factorgraph.h>
24 #include <dai/properties.h>
30 /// Approximate inference algorithm "Mean Field"
31 class MF
: public DAIAlgFG
{
33 std::vector
<Factor
> _beliefs
;
34 /// Maximum difference encountered so far
36 /// Number of iterations needed
40 /// Parameters of this inference algorithm
45 /// Maximum number of iterations
55 /// Name of this inference algorithm
56 static const char *Name
;
59 /// Default constructor
60 MF() : DAIAlgFG(), _beliefs(), _maxdiff(0.0), _iters(0U), props() {}
62 /// Construct from FactorGraph fg and PropertySet opts
63 MF( const FactorGraph
&fg
, const PropertySet
&opts
) : DAIAlgFG(fg
), _beliefs(), _maxdiff(0.0), _iters(0U), props() {
64 setProperties( opts
);
69 /// @name General InfAlg interface
71 virtual MF
* clone() const { return new MF(*this); }
72 virtual std::string
identify() const;
73 virtual Factor
belief( const Var
&n
) const;
74 virtual Factor
belief( const VarSet
&ns
) const;
75 virtual std::vector
<Factor
> beliefs() const;
76 virtual Real
logZ() const;
78 virtual void init( const VarSet
&ns
);
80 virtual Real
maxDiff() const { return _maxdiff
; }
81 virtual size_t Iterations() const { return _iters
; }
85 /// @name Additional interface specific for MF
87 Factor
beliefV( size_t i
) const;
92 void setProperties( const PropertySet
&opts
);
93 PropertySet
getProperties() const;
94 std::string
printProperties() const;
98 } // end of namespace dai