Significant improvement of documentation
[libdai.git] / include / dai / exactinf.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 ExactInf class
25
26
27 #ifndef __defined_libdai_exactinf_h
28 #define __defined_libdai_exactinf_h
29
30
31 #include <dai/daialg.h>
32 #include <dai/properties.h>
33 #include <dai/factorgraph.h>
34 #include <dai/enum.h>
35
36
37 namespace dai {
38
39
40 /// Exact inference algorithm using brute force enumeration (mainly useful for testing purposes)
41 class ExactInf : public DAIAlgFG {
42 public:
43 /// Parameters of this inference algorithm
44 struct Properties {
45 /// Verbosity
46 size_t verbose;
47 } props;
48
49 /// Name of this inference algorithm
50 static const char *Name;
51
52 private:
53 std::vector<Factor> _beliefsV;
54 std::vector<Factor> _beliefsF;
55 Real _logZ;
56
57 public:
58 /// Default constructor
59 ExactInf() : DAIAlgFG(), props(), _beliefsV(), _beliefsF(), _logZ(0) {}
60
61 /// Copy constructor
62 ExactInf( const ExactInf &x ) : DAIAlgFG(x), props(x.props), _beliefsV(x._beliefsV), _beliefsF(x._beliefsF), _logZ(x._logZ) {}
63
64 /// Assignment operator
65 ExactInf& operator=( const ExactInf &x ) {
66 if( this != &x ) {
67 DAIAlgFG::operator=( x );
68 props = x.props;
69 _beliefsV = x._beliefsV;
70 _beliefsF = x._beliefsF;
71 _logZ = x._logZ;
72 }
73 return *this;
74 }
75
76 /// Construct from FactorGraph fg and PropertySet opts
77 ExactInf( const FactorGraph &fg, const PropertySet &opts ) : DAIAlgFG(fg), props(), _beliefsV(), _beliefsF(), _logZ() {
78 setProperties( opts );
79 construct();
80 }
81
82
83 /// @name General InfAlg interface
84 //@{
85 virtual ExactInf* clone() const { return new ExactInf(*this); }
86 virtual ExactInf* create() const { return new ExactInf(); }
87 virtual std::string identify() const;
88 virtual Factor belief( const Var &n ) const { return beliefV( findVar( n ) ); }
89 virtual Factor belief( const VarSet &ns ) const;
90 virtual std::vector<Factor> beliefs() const;
91 virtual Real logZ() const { return _logZ; }
92 virtual void init();
93 virtual void init( const VarSet &/*ns*/ ) { DAI_THROW(NOT_IMPLEMENTED); }
94 virtual double run();
95 virtual double maxDiff() const { DAI_THROW(NOT_IMPLEMENTED); return 0.0; }
96 virtual size_t Iterations() const { DAI_THROW(NOT_IMPLEMENTED); return 0; }
97 //@}
98
99
100 /// @name Additional interface specific for ExactInf
101 //@{
102 Factor beliefV( size_t i ) const { return _beliefsV[i]; }
103 Factor beliefF( size_t I ) const { return _beliefsF[I]; }
104 //@}
105
106 private:
107 void construct();
108 void setProperties( const PropertySet &opts );
109 PropertySet getProperties() const;
110 std::string printProperties() const;
111 };
112
113
114 } // end of namespace dai
115
116
117 #endif