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