Declared class Diffs as obsolete
[libdai.git] / include / dai / mf.h
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
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.
6 *
7 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
9 */
10
11
12 /// \file
13 /// \brief Defines class MF
14 /// \todo Improve documentation
15
16
17 #ifndef __defined_libdai_mf_h
18 #define __defined_libdai_mf_h
19
20
21 #include <string>
22 #include <dai/daialg.h>
23 #include <dai/factorgraph.h>
24 #include <dai/properties.h>
25
26
27 namespace dai {
28
29
30 /// Approximate inference algorithm "Mean Field"
31 class MF : public DAIAlgFG {
32 private:
33 std::vector<Factor> _beliefs;
34 /// Maximum difference encountered so far
35 Real _maxdiff;
36 /// Number of iterations needed
37 size_t _iters;
38
39 public:
40 /// Parameters of this inference algorithm
41 struct Properties {
42 /// Verbosity
43 size_t verbose;
44
45 /// Maximum number of iterations
46 size_t maxiter;
47
48 /// Tolerance
49 Real tol;
50
51 /// Damping constant
52 Real damping;
53 } props;
54
55 /// Name of this inference algorithm
56 static const char *Name;
57
58 public:
59 /// Default constructor
60 MF() : DAIAlgFG(), _beliefs(), _maxdiff(0.0), _iters(0U), props() {}
61
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 );
65 construct();
66 }
67
68
69 /// @name General InfAlg interface
70 //@{
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 Factor beliefV( size_t i ) const;
76 virtual std::vector<Factor> beliefs() const;
77 virtual Real logZ() const;
78 virtual void init();
79 virtual void init( const VarSet &ns );
80 virtual Real run();
81 virtual Real maxDiff() const { return _maxdiff; }
82 virtual size_t Iterations() const { return _iters; }
83 //@}
84
85
86 /// @name Additional interface specific for MF
87 //@{
88 Factor calcNewBelief( size_t i );
89 //@}
90
91 private:
92 void construct();
93 void setProperties( const PropertySet &opts );
94 PropertySet getProperties() const;
95 std::string printProperties() const;
96 };
97
98
99 } // end of namespace dai
100
101
102 #endif