[Frederik Eaton] Removed unnecessary copy constructors and assignment operators
[libdai.git] / include / dai / mf.h
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
4
5 This file is part of libDAI.
6
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.
11
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.
16
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
20 */
21
22
23 /// \file
24 /// \brief Defines class MF
25 /// \todo Improve documentation
26
27
28 #ifndef __defined_libdai_mf_h
29 #define __defined_libdai_mf_h
30
31
32 #include <string>
33 #include <dai/daialg.h>
34 #include <dai/factorgraph.h>
35 #include <dai/properties.h>
36
37
38 namespace dai {
39
40
41 /// Approximate inference algorithm "Mean Field"
42 class MF : public DAIAlgFG {
43 private:
44 std::vector<Factor> _beliefs;
45 /// Maximum difference encountered so far
46 double _maxdiff;
47 /// Number of iterations needed
48 size_t _iters;
49
50 public:
51 /// Parameters of this inference algorithm
52 struct Properties {
53 /// Verbosity
54 size_t verbose;
55
56 /// Maximum number of iterations
57 size_t maxiter;
58
59 /// Tolerance
60 double tol;
61
62 /// Damping constant
63 double damping;
64 } props;
65
66 /// Name of this inference algorithm
67 static const char *Name;
68
69 public:
70 /// Default constructor
71 MF() : DAIAlgFG(), _beliefs(), _maxdiff(0.0), _iters(0U), props() {}
72
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 );
76 construct();
77 }
78
79
80 /// @name General InfAlg interface
81 //@{
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;
89 virtual void init();
90 virtual void init( const VarSet &ns );
91 virtual double run();
92 virtual double maxDiff() const { return _maxdiff; }
93 virtual size_t Iterations() const { return _iters; }
94 //@}
95
96
97 /// @name Additional interface specific for MF
98 //@{
99 Factor beliefV( size_t i ) const;
100 //@}
101
102 private:
103 void construct();
104 void setProperties( const PropertySet &opts );
105 PropertySet getProperties() const;
106 std::string printProperties() const;
107 };
108
109
110 } // end of namespace dai
111
112
113 #endif