ae4aef7ceb958341bfe2c4ca2ded9512f3c0898d
1 /* This file is part of libDAI - http://www.libdai.org/
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.
7 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
13 /// \brief Defines ExactInf class
14 /// \todo Improve documentation
17 #ifndef __defined_libdai_exactinf_h
18 #define __defined_libdai_exactinf_h
21 #include <dai/daialg.h>
22 #include <dai/properties.h>
23 #include <dai/factorgraph.h>
30 /// Exact inference algorithm using brute force enumeration (mainly useful for testing purposes)
31 class ExactInf
: public DAIAlgFG
{
33 /// Parameters of this inference algorithm
39 /// Name of this inference algorithm
40 static const char *Name
;
43 std::vector
<Factor
> _beliefsV
;
44 std::vector
<Factor
> _beliefsF
;
48 /// Default constructor
49 ExactInf() : DAIAlgFG(), props(), _beliefsV(), _beliefsF(), _logZ(0) {}
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
);
58 /// @name General InfAlg interface
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
; }
67 virtual void init( const VarSet
&/*ns*/ ) { DAI_THROW(NOT_IMPLEMENTED
); }
69 virtual double maxDiff() const { DAI_THROW(NOT_IMPLEMENTED
); return 0.0; }
70 virtual size_t Iterations() const { DAI_THROW(NOT_IMPLEMENTED
); return 0; }
74 /// @name Additional interface specific for ExactInf
76 Factor
beliefV( size_t i
) const { return _beliefsV
[i
]; }
77 Factor
beliefF( size_t I
) const { return _beliefsF
[I
]; }
82 void setProperties( const PropertySet
&opts
);
83 PropertySet
getProperties() const;
84 std::string
printProperties() const;
88 } // end of namespace dai