1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
5 This file is part of libDAI.
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 /// \brief Defines class MF
25 /// \todo Improve documentation
28 #ifndef __defined_libdai_mf_h
29 #define __defined_libdai_mf_h
33 #include <dai/daialg.h>
34 #include <dai/factorgraph.h>
35 #include <dai/properties.h>
41 /// Approximate inference algorithm "Mean Field"
42 class MF
: public DAIAlgFG
{
44 std::vector
<Factor
> _beliefs
;
45 /// Maximum difference encountered so far
47 /// Number of iterations needed
51 /// Parameters of this inference algorithm
56 /// Maximum number of iterations
66 /// Name of this inference algorithm
67 static const char *Name
;
70 /// Default constructor
71 MF() : DAIAlgFG(), _beliefs(), _maxdiff(0.0), _iters(0U), props() {}
73 /// Construct from FactorGraph fg and PropertySet opts
74 MF( const FactorGraph
&fg
, const PropertySet
&opts
) : DAIAlgFG(fg
), _beliefs(), _maxdiff(0.0), _iters(0U), props() {
75 setProperties( opts
);
80 /// @name General InfAlg interface
82 virtual MF
* clone() const { return new MF(*this); }
83 virtual MF
* create() const { return new MF(); }
84 virtual std::string
identify() const;
85 virtual Factor
belief( const Var
&n
) const;
86 virtual Factor
belief( const VarSet
&ns
) const;
87 virtual std::vector
<Factor
> beliefs() const;
88 virtual Real
logZ() const;
90 virtual void init( const VarSet
&ns
);
92 virtual double maxDiff() const { return _maxdiff
; }
93 virtual size_t Iterations() const { return _iters
; }
97 /// @name Additional interface specific for MF
99 Factor
beliefV( size_t i
) const;
104 void setProperties( const PropertySet
&opts
);
105 PropertySet
getProperties() const;
106 std::string
printProperties() const;
110 } // end of namespace dai