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